]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
numatune: setting --mode does not work well
authorErik Skultety <eskultet@redhat.com>
Fri, 22 Aug 2014 14:05:37 +0000 (16:05 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 22 Aug 2014 14:34:23 +0000 (16:34 +0200)
When trying to set numatune mode directly using virsh numatune command,
correct error is raised, however numatune structure was not deallocated,
thus resulting in creating an empty numatune element in the guest XML,
if none was present before. Running the same command aftewards results
in a successful change with broken XML structure. Patch fixes the
deallocation problem as well as checking for invalid attribute
combination VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO + a nonempty nodeset.

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1129998

src/conf/numatune_conf.c
tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index 48d1d04fe68dced383d9e0c7ab0b08613870f028..ff0f3eb34e8190f1383429ceae7ce47dfd3e21c4 100644 (file)
@@ -437,14 +437,27 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
                      int mode,
                      virBitmapPtr nodeset)
 {
-    bool create = !*numatunePtr;  /* Whether we are creating new struct */
+    bool created = false;
     int ret = -1;
-    virDomainNumatunePtr numatune = NULL;
+    virDomainNumatunePtr numatune;
 
     /* No need to do anything in this case */
     if (mode == -1 && placement == -1 && !nodeset)
         return 0;
 
+    if (!(*numatunePtr)) {
+        if (VIR_ALLOC(*numatunePtr) < 0)
+            goto cleanup;
+
+        created = true;
+        if (mode == -1)
+            mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
+        if (placement == -1)
+            placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT;
+    }
+
+    numatune = *numatunePtr;
+
     /* Range checks */
     if (mode != -1 &&
         (mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) {
@@ -453,6 +466,7 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
                        mode);
         goto cleanup;
     }
+
     if (placement != -1 &&
         (placement < 0 || placement >= VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -461,21 +475,9 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
         goto cleanup;
     }
 
-    if (create && VIR_ALLOC(*numatunePtr) < 0)
-        goto cleanup;
-    numatune = *numatunePtr;
-
-    if (create) {
-        /* Defaults for new struct */
-        if (mode == -1)
-            mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
-
-        if (placement == -1)
-            placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT;
-    }
-
     if (mode != -1)
         numatune->memory.mode = mode;
+
     if (nodeset) {
         virBitmapFree(numatune->memory.nodeset);
         numatune->memory.nodeset = virBitmapNewCopy(nodeset);
@@ -500,13 +502,26 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
         goto cleanup;
     }
 
+    /* setting nodeset when placement auto is invalid */
+    if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO &&
+        numatune->memory.nodeset) {
+        virBitmapFree(numatune->memory.nodeset);
+        numatune->memory.nodeset = NULL;
+    }
+
     if (placement != -1)
         numatune->memory.placement = placement;
 
     numatune->memory.specified = true;
 
     ret = 0;
+
  cleanup:
+    if (ret < 0 && created) {
+        virDomainNumatuneFree(*numatunePtr);
+        *numatunePtr = NULL;
+    }
+
     return ret;
 }
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml b/tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml
new file mode 100644 (file)
index 0000000..b3cb5c5
--- /dev/null
@@ -0,0 +1,31 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='auto'>2</vcpu>
+  <numatune>
+    <memory mode='interleave' placement='static'/>
+  </numatune>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <cpu>
+    <topology sockets='2' cores='1' threads='1'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index 65dc9c708f1ba0a8a5486d9dd64560698f8fd79b..b289d0e8436c941ac3668bfa9400b3ff2f73905a 100644 (file)
@@ -1223,6 +1223,7 @@ mymain(void)
     DO_TEST_PARSE_ERROR("numatune-memnodes-problematic", NONE);
     DO_TEST("numad", NONE);
     DO_TEST("numad-auto-vcpu-static-numatune", NONE);
+    DO_TEST_PARSE_ERROR("numad-auto-vcpu-static-numatune-no-nodeset", NONE);
     DO_TEST("numad-auto-memory-vcpu-cpuset", NONE);
     DO_TEST("numad-auto-memory-vcpu-no-cpuset-and-placement", NONE);
     DO_TEST("numad-static-memory-auto-vcpu", NONE);