]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Don't format cputune element when not needed
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 17 Dec 2012 15:03:01 +0000 (16:03 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 30 Jan 2013 08:37:03 +0000 (09:37 +0100)
Commit 60b176c3d0f0d5037acfa5e27c7753f657833a0b introduced a bug that
when editing an XML with cputune similar to this:

...
  <vcpu placement='static' current='1'>2</vcpu>
  <cputune>
    <vcpupin vcpu="1" cpuset="0"/>
  </cputune>
...

results in formatted XML that looks like this:

...
  <vcpu placement='static' current='1'>2</vcpu>
  <cputune>
  </cputune>
...

That is caused by a condition depending on def->cputune.vcpupin being
set rather than checking def->cputune.nvcpupin.  Notice that nvcpupin
can be 0 and vcpupin can still be allocated since it's a pointer to an
array, so no harm done there.

I also changed it on other places in the code where it depended on the
wrong variable.

src/conf/domain_conf.c

index 8dbfb9622d22256bc252b71713ca65d9232db2d4..ac4b2c2b6f95952f824bc4d7763c1bc87fa22df6 100644 (file)
@@ -13955,10 +13955,10 @@ virDomainIsAllVcpupinInherited(virDomainDefPtr def)
     int i;
 
     if (!def->cpumask) {
-        if (!def->cputune.vcpupin)
-            return true;
-        else
+        if (def->cputune.nvcpupin)
             return false;
+        else
+            return true;
     } else {
         for (i = 0; i < def->cputune.nvcpupin; i++) {
             if (!virBitmapEqual(def->cputune.vcpupin[i]->cpumask,
@@ -14143,7 +14143,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
 
     if (def->cputune.shares ||
-        (def->cputune.vcpupin && !virDomainIsAllVcpupinInherited(def)) ||
+        (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) ||
         def->cputune.period || def->cputune.quota ||
         def->cputune.emulatorpin ||
         def->cputune.emulator_period || def->cputune.emulator_quota)
@@ -14209,7 +14209,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         VIR_FREE(cpumask);
     }
     if (def->cputune.shares ||
-        (def->cputune.vcpupin && !virDomainIsAllVcpupinInherited(def)) ||
+        (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) ||
         def->cputune.period || def->cputune.quota ||
         def->cputune.emulatorpin ||
         def->cputune.emulator_period || def->cputune.emulator_quota)