]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Reorder elements inside memballoon
authorMartin Kletzander <mkletzan@redhat.com>
Fri, 13 Mar 2015 15:16:57 +0000 (16:16 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 17 Mar 2015 11:03:33 +0000 (12:03 +0100)
All the devices we have format their address as its last sub-element, so
let's change memballoon to follow suit.  Also adjust RNG to allow any
order of them so 'virsh edit' doesn't shout at us.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index e98e9052aa919430bcc710382a904cdefbea724c..ebd9299371b68255d5a6cf9cbcdb3ae4dfd7dd9e 100644 (file)
           <value>none</value>
         </choice>
       </attribute>
-      <optional>
-        <ref name="alias"/>
-      </optional>
-      <optional>
-        <ref name="address"/>
-      </optional>
-      <optional>
-        <element name="stats">
-          <attribute name="period">
-            <ref name="positiveInteger"/>
-          </attribute>
-        </element>
-      </optional>
+      <interleave>
+        <optional>
+          <ref name="alias"/>
+        </optional>
+        <optional>
+          <ref name="address"/>
+        </optional>
+        <optional>
+          <element name="stats">
+            <attribute name="period">
+              <ref name='positiveInteger'/>
+            </attribute>
+          </element>
+        </optional>
+      </interleave>
     </element>
   </define>
   <define name="parallel">
index e8cda6ca28a89aea280c72b08374cfacf9fb8b5b..3865854a5ca843ea891882d92cec5c4bf4f3bf31 100644 (file)
@@ -18826,7 +18826,8 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
                              unsigned int flags)
 {
     const char *model = virDomainMemballoonModelTypeToString(def->model);
-    bool noopts = true;
+    virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
+    int indent = virBufferGetIndent(buf, false);
 
     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -18835,27 +18836,24 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
     }
 
     virBufferAsprintf(buf, "<memballoon model='%s'", model);
-    virBufferAdjustIndent(buf, 2);
+    virBufferAdjustIndent(&childrenBuf, indent + 2);
 
-    if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
-        virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
-            return -1;
-        noopts = false;
-    }
+    if (def->period)
+        virBufferAsprintf(&childrenBuf, "<stats period='%u'/>\n", def->period);
 
-    if (def->period) {
-        if (noopts)
-            virBufferAddLit(buf, ">\n");
-        virBufferAsprintf(buf, "<stats period='%u'/>\n", def->period);
-        noopts = false;
+    if (virDomainDeviceInfoNeedsFormat(&def->info, flags) &&
+        virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) {
+        virBufferFreeAndReset(&childrenBuf);
+        return -1;
     }
 
-    virBufferAdjustIndent(buf, -2);
-    if (noopts)
+    if (!virBufferUse(&childrenBuf)) {
         virBufferAddLit(buf, "/>\n");
-    else
+    } else {
+        virBufferAddLit(buf, ">\n");
+        virBufferAddBuffer(buf, &childrenBuf);
         virBufferAddLit(buf, "</memballoon>\n");
+    }
 
     return 0;
 }
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml
new file mode 100644 (file)
index 0000000..79e465a
--- /dev/null
@@ -0,0 +1,30 @@
+<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='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <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='usb' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <controller type='ide' index='0'/>
+    <memballoon model='virtio'>
+      <stats period='10'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
index 6ffe36b700e50f41f41b40aa5932f6367b6d6a25..7755ea3675c684b1c4a6d9bb41f0a64ca7e02b4f 100644 (file)
@@ -354,6 +354,7 @@ mymain(void)
 
     /* These tests generate different XML */
     DO_TEST_DIFFERENT("balloon-device-auto");
+    DO_TEST_DIFFERENT("balloon-device-period");
     DO_TEST_DIFFERENT("channel-virtio-auto");
     DO_TEST_DIFFERENT("console-compat-auto");
     DO_TEST_DIFFERENT("disk-scsi-device-auto");