~serge-hallyn/ubuntu/raring/libvirt/libvirt-hugepages

« back to all changes in this revision

Viewing changes to src/libxl/libxl_driver.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-13 15:44:12 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120513154412-fgmn5sxqdzgnzlx3
Tags: 0.9.12-0ubuntu1
* New upstream version:
  * Synchronize with debian packaging:
    - debian/control: Update build depends.
    - debian/libvirt-bin.postrm: Cleanup /var/log/libvirt
      on purge.
    - Bump standards verson (no changes).
    - debian/patches/Don-t-fail-if-we-can-t-setup-avahi.patch: Added
  * Dropped patches:
    - debian/patches/Debianize-libvirt-guests.patch
    - debian/patches/rewrite-lxc-controller-eof-handling-yet-again
    - debian/patches/ubuntu/libnl13.patch
    - debian/patches/ubuntu/fix-lxc-startup-error.patch
    - debian/patches/ubuntu/fix-bridge-fd.patch
    - debian/patches/ubuntu/skip-labelling-network-disks.patch
    - debian/patches/ubuntu/xen-xend-shutdown-detection.patch
    - debian/patches/ubuntu/xen-config-no-vfb-for-hvm.patch
    - debian/patches/debian/Disable-daemon-start-test.patch
    - debian/patches/debian/Disable-gnulib-s-test-nonplocking-pipe.sh.patch
    - debian/patches/ubuntu/9006-default-config-test-case.patch
    - debian/patches/fix-block-migration.patch
    - debian/patches/ubuntu/9022-qemu-unescape-HMP-commands-before-converting-them-to.patch
    - debian/patches/ubuntu/9023-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/9024-qemu-allow-snapshotting-of-sheepdog-and-rbd-disks.patch
    - debian/patches/9025-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/arm-gcc-workaround.patch
  * Rediffed:
    - debian/patches/Allow-libvirt-group-to-access-the-socket.patch
    - debian/patches/Disable-failing-virnetsockettest.patch
    - debian/patches/dnsmasq-as-priv-user
    - debian/patches/9002-better_default_uri_virsh.patch
  * debian/control: Add libnl-route-3-dev ass a build depends.
  * debian/patches/libnl3-build-fix.patch: Fix build with libnl3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*---------------------------------------------------------------------------*/
2
 
/*  Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
 
2
/*  Copyright (C) 2006-2012 Red Hat, Inc.
 
3
 *  Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
3
4
 *  Copyright (C) 2011 Univention GmbH.
4
 
 *  Copyright (C) 2006-2011 Red Hat, Inc.
5
5
 *
6
6
 * This library is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU Lesser General Public
43
43
#include "libxl_driver.h"
44
44
#include "libxl_conf.h"
45
45
#include "xen_xm.h"
46
 
 
 
46
#include "virtypedparam.h"
 
47
#include "viruri.h"
47
48
 
48
49
#define VIR_FROM_THIS VIR_FROM_LIBXL
49
50
 
111
112
    VIR_FREE(priv);
112
113
}
113
114
 
114
 
static void
115
 
libxlDomainEventDispatchFunc(virConnectPtr conn, virDomainEventPtr event,
116
 
                             virConnectDomainEventGenericCallback cb,
117
 
                             void *cbopaque, void *opaque)
118
 
{
119
 
    libxlDriverPrivatePtr driver = opaque;
120
 
 
121
 
    /* Drop the lock whle dispatching, for sake of re-entrancy */
122
 
    libxlDriverUnlock(driver);
123
 
    virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
124
 
    libxlDriverLock(driver);
125
 
}
126
 
 
127
 
static void
128
 
libxlDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
129
 
{
130
 
    libxlDriverPrivatePtr driver = opaque;
131
 
 
132
 
    libxlDriverLock(driver);
133
 
    virDomainEventStateFlush(driver->domainEventState,
134
 
                             libxlDomainEventDispatchFunc,
135
 
                             driver);
136
 
    libxlDriverUnlock(driver);
137
 
}
138
115
 
139
116
/* driver must be locked before calling */
140
117
static void
240
217
    libxlSavefileHeader hdr;
241
218
    char *xml = NULL;
242
219
 
243
 
    if ((fd = virFileOpenAs(from, O_RDONLY, 0, getuid(), getgid(), 0)) < 0) {
 
220
    if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) {
244
221
        libxlError(VIR_ERR_OPERATION_FAILED,
245
222
                   "%s", _("cannot read domain image"));
246
223
        goto error;
856
833
    char *log_file = NULL;
857
834
    virCommandPtr cmd;
858
835
    int status, ret = 0;
 
836
    char ebuf[1024];
859
837
 
860
838
    /* Disable libxl driver if non-root */
861
839
    if (!privileged) {
916
894
        goto out_of_memory;
917
895
 
918
896
    if (virFileMakePath(libxl_driver->logDir) < 0) {
919
 
        char ebuf[1024];
920
897
        VIR_ERROR(_("Failed to create log dir '%s': %s"),
921
 
                  libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
 
898
                  libxl_driver->logDir, virStrerror(errno, ebuf, sizeof(ebuf)));
922
899
        goto error;
923
900
    }
924
901
    if (virFileMakePath(libxl_driver->stateDir) < 0) {
925
 
        char ebuf[1024];
926
902
        VIR_ERROR(_("Failed to create state dir '%s': %s"),
927
 
                  libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
 
903
                  libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof(ebuf)));
928
904
        goto error;
929
905
    }
930
906
    if (virFileMakePath(libxl_driver->libDir) < 0) {
931
 
        char ebuf[1024];
932
907
        VIR_ERROR(_("Failed to create lib dir '%s': %s"),
933
 
                  libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
 
908
                  libxl_driver->libDir, virStrerror(errno, ebuf, sizeof(ebuf)));
934
909
        goto error;
935
910
    }
936
911
    if (virFileMakePath(libxl_driver->saveDir) < 0) {
937
 
        char ebuf[1024];
938
912
        VIR_ERROR(_("Failed to create save dir '%s': %s"),
939
 
                  libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
 
913
                  libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof(ebuf)));
940
914
        goto error;
941
915
    }
942
916
 
952
926
    }
953
927
    VIR_FREE(log_file);
954
928
 
955
 
    libxl_driver->domainEventState = virDomainEventStateNew(
956
 
                                                        libxlDomainEventFlush,
957
 
                                                        libxl_driver,
958
 
                                                        NULL,
959
 
                                                        false);
 
929
    libxl_driver->domainEventState = virDomainEventStateNew();
960
930
    if (!libxl_driver->domainEventState)
961
931
        goto error;
962
932
 
1071
1041
        if (libxl_driver == NULL)
1072
1042
            return VIR_DRV_OPEN_DECLINED;
1073
1043
 
1074
 
        conn->uri = xmlParseURI("xen:///");
1075
 
        if (!conn->uri) {
1076
 
            virReportOOMError();
 
1044
        if (!(conn->uri = virURIParse("xen:///")))
1077
1045
            return VIR_DRV_OPEN_ERROR;
1078
 
        }
1079
1046
    } else {
1080
1047
        /* Only xen scheme */
1081
1048
        if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen"))
1115
1082
    libxlDriverPrivatePtr driver = conn->privateData;
1116
1083
 
1117
1084
    libxlDriverLock(driver);
1118
 
    virDomainEventCallbackListRemoveConn(conn,
1119
 
                                         driver->domainEventState->callbacks);
 
1085
    virDomainEventStateDeregisterConn(conn,
 
1086
                                      driver->domainEventState);
1120
1087
    libxlDriverUnlock(driver);
1121
1088
    conn->privateData = NULL;
1122
1089
    return 0;
1440
1407
}
1441
1408
 
1442
1409
static int
1443
 
libxlDomainShutdown(virDomainPtr dom)
 
1410
libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
1444
1411
{
1445
1412
    libxlDriverPrivatePtr driver = dom->conn->privateData;
1446
1413
    virDomainObjPtr vm;
1447
1414
    int ret = -1;
1448
1415
    libxlDomainObjPrivatePtr priv;
1449
1416
 
 
1417
    virCheckFlags(0, -1);
 
1418
 
1450
1419
    libxlDriverLock(driver);
1451
1420
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
1452
1421
    if (!vm) {
1484
1453
}
1485
1454
 
1486
1455
static int
 
1456
libxlDomainShutdown(virDomainPtr dom)
 
1457
{
 
1458
    return libxlDomainShutdownFlags(dom, 0);
 
1459
}
 
1460
 
 
1461
 
 
1462
static int
1487
1463
libxlDomainReboot(virDomainPtr dom, unsigned int flags)
1488
1464
{
1489
1465
    libxlDriverPrivatePtr driver = dom->conn->privateData;
1610
1586
    return type;
1611
1587
}
1612
1588
 
1613
 
static unsigned long
 
1589
static unsigned long long
1614
1590
libxlDomainGetMaxMemory(virDomainPtr dom)
1615
1591
{
1616
1592
    libxlDriverPrivatePtr driver = dom->conn->privateData;
1617
1593
    virDomainObjPtr vm;
1618
 
    unsigned long ret = 0;
 
1594
    unsigned long long ret = 0;
1619
1595
 
1620
1596
    libxlDriverLock(driver);
1621
1597
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
1855
1831
    }
1856
1832
 
1857
1833
    if ((fd = virFileOpenAs(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR,
1858
 
                            getuid(), getgid(), 0)) < 0) {
 
1834
                            -1, -1, 0)) < 0) {
1859
1835
        virReportSystemError(-fd,
1860
1836
                             _("Failed to create domain save file '%s'"), to);
1861
1837
        goto cleanup;
3107
3083
static int
3108
3084
libxlDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
3109
3085
{
3110
 
    virDomainDiskDefPtr disk;
 
3086
    virDomainDiskDefPtr disk, detach;
3111
3087
    int ret = -1;
3112
3088
 
3113
3089
    switch (dev->type) {
3114
3090
        case VIR_DOMAIN_DEVICE_DISK:
3115
3091
            disk = dev->data.disk;
3116
 
            if (virDomainDiskRemoveByName(vmdef, disk->dst)) {
 
3092
            if (!(detach = virDomainDiskRemoveByName(vmdef, disk->dst))) {
3117
3093
                libxlError(VIR_ERR_INVALID_ARG,
3118
3094
                            _("no target device %s"), disk->dst);
3119
3095
                break;
3120
3096
            }
 
3097
            virDomainDiskDefFree(detach);
3121
3098
            ret = 0;
3122
3099
            break;
3123
3100
        default:
3261
3238
         goto cleanup;
3262
3239
    }
3263
3240
 
3264
 
    if (!(dev = virDomainDeviceDefParse(driver->caps, vm->def, xml,
3265
 
                                  VIR_DOMAIN_XML_INACTIVE)))
3266
 
        goto cleanup;
3267
 
 
3268
3241
    priv = vm->privateData;
3269
3242
 
3270
3243
    if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
3404
3377
    int ret;
3405
3378
 
3406
3379
    libxlDriverLock(driver);
3407
 
    ret = virDomainEventCallbackListAdd(conn,
3408
 
                                        driver->domainEventState->callbacks,
3409
 
                                        callback, opaque, freecb);
 
3380
    ret = virDomainEventStateRegister(conn,
 
3381
                                      driver->domainEventState,
 
3382
                                      callback, opaque, freecb);
3410
3383
    libxlDriverUnlock(driver);
3411
3384
 
3412
3385
    return ret;
3638
3611
        goto cleanup;
3639
3612
    }
3640
3613
 
3641
 
    params[0].value.ui = sc_info.weight;
3642
 
    params[0].type = VIR_TYPED_PARAM_UINT;
3643
 
    if (virStrcpyStatic(params[0].field,
3644
 
                        VIR_DOMAIN_SCHEDULER_WEIGHT) == NULL) {
3645
 
        libxlError(VIR_ERR_INTERNAL_ERROR,
3646
 
                   _("Field name '%s' too long"),
3647
 
                   VIR_DOMAIN_SCHEDULER_WEIGHT);
 
3614
    if (virTypedParameterAssign(&params[0], VIR_DOMAIN_SCHEDULER_WEIGHT,
 
3615
                                VIR_TYPED_PARAM_UINT, sc_info.weight) < 0)
3648
3616
        goto cleanup;
3649
 
    }
3650
3617
 
3651
3618
    if (*nparams > 1) {
3652
 
        params[1].value.ui = sc_info.cap;
3653
 
        params[1].type = VIR_TYPED_PARAM_UINT;
3654
 
        if (virStrcpyStatic(params[1].field,
3655
 
                            VIR_DOMAIN_SCHEDULER_CAP) == NULL) {
3656
 
            libxlError(VIR_ERR_INTERNAL_ERROR,
3657
 
                       _("Field name '%s' too long"),
3658
 
                       VIR_DOMAIN_SCHEDULER_CAP);
 
3619
        if (virTypedParameterAssign(&params[0], VIR_DOMAIN_SCHEDULER_CAP,
 
3620
                                    VIR_TYPED_PARAM_UINT, sc_info.cap) < 0)
3659
3621
            goto cleanup;
3660
 
        }
3661
3622
    }
3662
3623
 
3663
3624
    if (*nparams > XEN_SCHED_CREDIT_NPARAM)
3692
3653
    int ret = -1;
3693
3654
 
3694
3655
    virCheckFlags(0, -1);
 
3656
    if (virTypedParameterArrayValidate(params, nparams,
 
3657
                                       VIR_DOMAIN_SCHEDULER_WEIGHT,
 
3658
                                       VIR_TYPED_PARAM_UINT,
 
3659
                                       VIR_DOMAIN_SCHEDULER_CAP,
 
3660
                                       VIR_TYPED_PARAM_UINT,
 
3661
                                       NULL) < 0)
 
3662
        return -1;
3695
3663
 
3696
3664
    libxlDriverLock(driver);
3697
3665
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
3733
3701
        virTypedParameterPtr param = &params[i];
3734
3702
 
3735
3703
        if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
3736
 
            if (param->type != VIR_TYPED_PARAM_UINT) {
3737
 
                libxlError(VIR_ERR_INVALID_ARG, "%s",
3738
 
                           _("invalid type for weight tunable, expected a 'uint'"));
3739
 
                goto cleanup;
3740
 
            }
3741
3704
            sc_info.weight = params[i].value.ui;
3742
 
 
3743
3705
        } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CAP)) {
3744
 
            if (param->type != VIR_TYPED_PARAM_UINT) {
3745
 
                libxlError(VIR_ERR_INVALID_ARG, "%s",
3746
 
                           _("invalid type for cap tunable, expected a 'uint'"));
3747
 
                goto cleanup;
3748
 
            }
3749
3706
            sc_info.cap = params[i].value.ui;
3750
 
        } else {
3751
 
            libxlError(VIR_ERR_INVALID_ARG,
3752
 
                       _("Invalid parameter '%s'"), param->field);
3753
 
            goto cleanup;
3754
3707
        }
3755
3708
    }
3756
3709
 
3851
3804
    int ret;
3852
3805
 
3853
3806
    libxlDriverLock(driver);
3854
 
    ret = virDomainEventCallbackListAddID(conn,
3855
 
                                          driver->domainEventState->callbacks,
3856
 
                                          dom, eventID, callback, opaque,
3857
 
                                          freecb);
 
3807
    if (virDomainEventStateRegisterID(conn,
 
3808
                                      driver->domainEventState,
 
3809
                                      dom, eventID, callback, opaque,
 
3810
                                      freecb, &ret) < 0)
 
3811
        ret = -1;
3858
3812
    libxlDriverUnlock(driver);
3859
3813
 
3860
3814
    return ret;
3868
3822
    int ret;
3869
3823
 
3870
3824
    libxlDriverLock(driver);
3871
 
    ret = virDomainEventStateDeregisterAny(conn,
3872
 
                                           driver->domainEventState,
3873
 
                                           callbackID);
 
3825
    ret = virDomainEventStateDeregisterID(conn,
 
3826
                                          driver->domainEventState,
 
3827
                                          callbackID);
3874
3828
    libxlDriverUnlock(driver);
3875
3829
 
3876
3830
    return ret;
3904
3858
    .domainSuspend = libxlDomainSuspend, /* 0.9.0 */
3905
3859
    .domainResume = libxlDomainResume, /* 0.9.0 */
3906
3860
    .domainShutdown = libxlDomainShutdown, /* 0.9.0 */
 
3861
    .domainShutdownFlags = libxlDomainShutdownFlags, /* 0.9.10 */
3907
3862
    .domainReboot = libxlDomainReboot, /* 0.9.0 */
3908
3863
    .domainDestroy = libxlDomainDestroy, /* 0.9.0 */
3909
3864
    .domainDestroyFlags = libxlDomainDestroyFlags, /* 0.9.4 */