]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix openvz crash when setting vcpus & initialize mutex (Anton Protopopov)
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 17 Dec 2008 21:13:19 +0000 (21:13 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 17 Dec 2008 21:13:19 +0000 (21:13 +0000)
ChangeLog
src/openvz_conf.c
src/openvz_driver.c

index d3e7bf31732d6bf86a0c71cb1f9f961924ca0a45..87235f53b9206ada1dd532bb5aeed4a29e49b172 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,18 +1,26 @@
+Wed Dec 17 21:10:39 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       Mutex / crash fixes to openvz driver (Anton Protopopov)
+       * src/openvz_driver.c: Fix crash with setting CPU value
+       during define
+       * src/openvz_conf.c: Initialize the domain mutex when
+       loading config files
+
 Wed Dec 17 20:53:39 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
 
-       * domain_conf.c, node_device_conf.c, node_device_conf.h,
-       storage_conf.c, storage_conf.h: Remove trailing semi-colon
+       * src/domain_conf.c, src/node_device_conf.c, src/node_device_conf.h,
+       src/storage_conf.c, src/storage_conf.h: Remove trailing semi-colon
        causing empty statement compile warnings on solaris (John
        Levon).
 
 Wed Dec 17 18:10:39 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
 
        Anonymous union fixes for non-GCC compilers (John Levon)
-       * domain_conf.c, qemu_conf.c, qemu_driver.c: Remove use
+       * src/domain_conf.c, src/qemu_conf.c, src/qemu_driver.c: Remove use
        of anonymous union
-       * domain_conf.h: Give a name to the anonymous union for
+       * src/domain_conf.h: Give a name to the anonymous union for
        host devices. Add 'dummy' field to avoid empty struct
-       * remote_internal.c: Remove gcc-ism in empty "x ? : y"
+       * src/remote_internal.c: Remove gcc-ism in empty "x ? : y"
 
 Wed Dec 17 19:06:53 +0100 2008 Jim Meyering <meyering@redhat.com>
 
index 1361c53e82d9c6bb56ad384f1eeb2b2f53ae1ef8..44a243bfe1d26a8fb99722fef7d0b7ccb940fe32 100644 (file)
@@ -393,6 +393,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
             VIR_ALLOC(dom->def) < 0)
             goto no_memory;
 
+        pthread_mutex_init(&dom->lock, NULL);
+
         if (STREQ(status, "stopped"))
             dom->state = VIR_DOMAIN_SHUTOFF;
         else
index 95ac7dcb689402717603df7728530fb2b43a0aa7..290ef850614f1d7030ea7f35f44e8eebea07de11 100644 (file)
@@ -66,6 +66,7 @@ static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
 static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type);
 static int openvzDomainGetMaxVcpus(virDomainPtr dom);
 static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus);
+static int openvzDomainSetVcpusInternal(virConnectPtr conn, virDomainObjPtr vm, unsigned int nvcpus);
 
 static void openvzDriverLock(struct openvz_driver *driver)
 {
@@ -695,7 +696,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
         goto cleanup;
 
     if (vm->def->vcpus > 0) {
-        if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
+        if (openvzDomainSetVcpusInternal(conn, vm, vm->def->vcpus) < 0) {
             openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                      "%s", _("Could not set number of virtual cpu"));
              goto cleanup;
@@ -780,9 +781,9 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
     vm->state = VIR_DOMAIN_RUNNING;
 
     if (vm->def->vcpus > 0) {
-        if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
+        if (openvzDomainSetVcpusInternal(conn, vm, vm->def->vcpus) < 0) {
             openvzError(conn, VIR_ERR_INTERNAL_ERROR,
-                        "%s", _("Could not set number of virtual cpu"));
+                    "%s", _("Could not set number of virtual cpu"));
             goto cleanup;
         }
     }
@@ -961,14 +962,36 @@ static int openvzDomainGetMaxVcpus(virDomainPtr dom) {
     return openvzGetMaxVCPUs(dom->conn, "openvz");
 }
 
-static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
-    struct openvz_driver *driver = dom->conn->privateData;
-    virDomainObjPtr vm;
-    char   str_vcpus[32];
+static int openvzDomainSetVcpusInternal(virConnectPtr conn, virDomainObjPtr vm,
+    unsigned int nvcpus)
+{
+    char        str_vcpus[32];
     const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
                            "--cpus", str_vcpus, "--save", NULL };
     unsigned int pcpus;
-    int ret = -1;
+    pcpus = openvzGetNodeCPUs();
+    if (pcpus > 0 && pcpus < nvcpus)
+        nvcpus = pcpus;
+
+    snprintf(str_vcpus, 31, "%d", nvcpus);
+    str_vcpus[31] = '\0';
+
+    openvzSetProgramSentinal(prog, vm->def->name);
+    if (virRun(conn, prog, NULL) < 0) {
+        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+                _("Could not exec %s"), VZCTL);
+        return -1;
+    }
+
+    vm->def->vcpus = nvcpus;
+    return 0;
+}
+
+static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
+{
+    virDomainObjPtr         vm;
+    struct openvz_driver   *driver = dom->conn->privateData;
+    int                     ret = -1;
 
     openvzDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -986,21 +1009,7 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
         goto cleanup;
     }
 
-    pcpus = openvzGetNodeCPUs();
-    if (pcpus > 0 && pcpus < nvcpus)
-        nvcpus = pcpus;
-
-    snprintf(str_vcpus, 31, "%d", nvcpus);
-    str_vcpus[31] = '\0';
-
-    openvzSetProgramSentinal(prog, vm->def->name);
-    if (virRun(dom->conn, prog, NULL) < 0) {
-        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
-                    _("Could not exec %s"), VZCTL);
-        goto cleanup;
-    }
-
-    vm->def->vcpus = nvcpus;
+    openvzDomainSetVcpusInternal(dom->conn, vm, nvcpus);
     ret = 0;
 
 cleanup: