conf: Don't output <cpu> tag if it contains no information.

The tag is already marked as optional in the schema, so no changes
are needed there.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1202606
This commit is contained in:
Andrea Bolognani 2015-04-10 15:09:59 +02:00 committed by Erik Skultety
parent b487bb810e
commit e4d7ddfdd2
4 changed files with 65 additions and 9 deletions

View File

@ -435,13 +435,14 @@ virCPUDefFormatBufFull(virBufferPtr buf,
bool updateCPU)
{
int ret = -1;
virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
int indent = virBufferGetIndent(buf, false);
if (!def)
return 0;
virBufferAddLit(buf, "<cpu");
/* Format attributes */
if (def->type == VIR_CPU_TYPE_GUEST) {
const char *tmp;
@ -451,7 +452,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
_("Unexpected CPU mode %d"), def->mode);
goto cleanup;
}
virBufferAsprintf(buf, " mode='%s'", tmp);
virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
}
if (def->model &&
@ -463,10 +464,11 @@ virCPUDefFormatBufFull(virBufferPtr buf,
def->match);
goto cleanup;
}
virBufferAsprintf(buf, " match='%s'", tmp);
virBufferAsprintf(&attributeBuf, " match='%s'", tmp);
}
}
/* Format children */
virBufferAdjustIndent(&childrenBuf, indent + 2);
if (def->arch)
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
@ -477,16 +479,25 @@ virCPUDefFormatBufFull(virBufferPtr buf,
if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
goto cleanup;
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childrenBuf);
virBufferAddLit(buf, "</cpu>\n");
} else {
virBufferAddLit(buf, "/>\n");
/* Put it all together */
if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "<cpu");
if (virBufferUse(&attributeBuf))
virBufferAddBuffer(buf, &attributeBuf);
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childrenBuf);
virBufferAddLit(buf, "</cpu>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
}
ret = 0;
cleanup:
virBufferFreeAndReset(&attributeBuf);
virBufferFreeAndReset(&childrenBuf);
return ret;
}

View File

@ -0,0 +1,23 @@
<domain type='kvm'>
<name>cpu-empty</name>
<uuid>1aed4c39-ad6e-4a78-9264-4ce996290d17</uuid>
<memory unit='KiB'>4000768</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<cpu>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
<controller type='usb' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<memballoon model='virtio'/>
</devices>
</domain>

View File

@ -0,0 +1,21 @@
<domain type='kvm'>
<name>cpu-empty</name>
<uuid>1aed4c39-ad6e-4a78-9264-4ce996290d17</uuid>
<memory unit='KiB'>4000768</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' 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-kvm</emulator>
<controller type='usb' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<memballoon model='virtio'/>
</devices>
</domain>

View File

@ -361,6 +361,7 @@ mymain(void)
DO_TEST("clock-utc");
DO_TEST("clock-localtime");
DO_TEST_DIFFERENT("cpu-empty");
DO_TEST("cpu-kvmclock");
DO_TEST("cpu-host-kvmclock");
DO_TEST("cpu-host-passthrough-features");