[libvirt] [PATCH 3/4] cpu: Format <cpu/> properly
Martin Kletzander
mkletzan at redhat.com
Tue Feb 24 10:52:47 UTC 2015
On Thu, Feb 19, 2015 at 02:13:44PM +0100, Michal Privoznik wrote:
>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.
>
Is there any purpose behind this or is this just for the sake of
looking good?
ACK anyway (after the requisite 1/4 is fixed).
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/conf/cpu_conf.c | 19 +++++++++++++------
> .../qemuxml2argv-cpu-host-kvmclock.xml | 3 +--
> 2 files changed, 14 insertions(+), 8 deletions(-)
>
>diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
>index 9a430ef..1a35185 100644
>--- a/src/conf/cpu_conf.c
>+++ b/src/conf/cpu_conf.c
>@@ -556,6 +556,8 @@ virCPUDefFormatBufFull(virBufferPtr buf,
> bool updateCPU)
> {
> int ret = -1;
>+ virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
>+ int indent = virBufferGetIndent(buf, false);
>
> if (!def)
> return 0;
>@@ -585,20 +587,25 @@ 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;
>- 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;
> }
>
>diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml
>index 89153a5..8954278 100644
>--- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml
>+++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-kvmclock.xml
>@@ -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>
>--
>2.0.5
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150224/8703d141/attachment-0001.sig>
More information about the libvir-list
mailing list