]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu: Format <cpu/> properly
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Feb 2015 17:04:16 +0000 (18:04 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 25 Feb 2015 08:26:04 +0000 (09:26 +0100)
Well, not that we are not formatting invalid XML, rather than not as
beautiful as we can:

  <cpu mode='host-passthrough'>
  </cpu>

If there are no children, let's use the singleton element.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/cpu_conf.c
tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml

index 2bce525d5113dd541ddf2a2c52a5e493059dc695..cd3882df2cc6fa6f6b4f0f284b59366c2bef243d 100644 (file)
@@ -435,6 +435,8 @@ virCPUDefFormatBufFull(virBufferPtr buf,
                        bool updateCPU)
 {
     int ret = -1;
+    virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
+    int indent = virBufferGetIndent(buf, false);
 
     if (!def)
         return 0;
@@ -464,23 +466,28 @@ virCPUDefFormatBufFull(virBufferPtr buf,
             virBufferAsprintf(buf, " match='%s'", tmp);
         }
     }
-    virBufferAddLit(buf, ">\n");
-    virBufferAdjustIndent(buf, 2);
 
+    virBufferAdjustIndent(&childrenBuf, indent + 2);
     if (def->arch)
-        virBufferAsprintf(buf, "<arch>%s</arch>\n",
+        virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
                           virArchToString(def->arch));
-    if (virCPUDefFormatBuf(buf, def, updateCPU) < 0)
+    if (virCPUDefFormatBuf(&childrenBuf, def, updateCPU) < 0)
         goto cleanup;
 
-    if (virDomainNumaDefCPUFormat(buf, numa) < 0)
+    if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
         goto cleanup;
 
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</cpu>\n");
+    if (virBufferUse(&childrenBuf)) {
+        virBufferAddLit(buf, ">\n");
+        virBufferAddBuffer(buf, &childrenBuf);
+        virBufferAddLit(buf, "</cpu>\n");
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
 
     ret = 0;
  cleanup:
+    virBufferFreeAndReset(&childrenBuf);
     return ret;
 }
 
index 89153a53afa0ba151e9b135d235d1c6befe8e395..89542788ccff401537a5d605fd15c0de7d7bd1ab 100644 (file)
@@ -8,8 +8,7 @@
     <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='network'/>
   </os>
-  <cpu mode='host-passthrough'>
-  </cpu>
+  <cpu mode='host-passthrough'/>
   <clock offset='utc'>
     <timer name='kvmclock' present='no'/>
   </clock>