From: Michal Privoznik Date: Wed, 18 Feb 2015 17:04:16 +0000 (+0100) Subject: cpu: Format properly X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0e69d97648e02bf3aa15adab6c555ceaa24da5b0;p=people%2Fliuw%2Flibxenctrl-split%2Flibvirt.git cpu: Format properly Well, not that we are not formatting invalid XML, rather than not as beautiful as we can: If there are no children, let's use the singleton element. Signed-off-by: Michal Privoznik --- diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 2bce525d5..cd3882df2 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -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, "%s\n", + virBufferAsprintf(&childrenBuf, "%s\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, "\n"); + if (virBufferUse(&childrenBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &childrenBuf); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } ret = 0; cleanup: + virBufferFreeAndReset(&childrenBuf); return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml index 89153a53a..89542788c 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml @@ -8,8 +8,7 @@ hvm - - +