mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
parent
b487bb810e
commit
e4d7ddfdd2
@ -435,13 +435,14 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
bool updateCPU)
|
bool updateCPU)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
|
||||||
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
|
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
|
||||||
int indent = virBufferGetIndent(buf, false);
|
int indent = virBufferGetIndent(buf, false);
|
||||||
|
|
||||||
if (!def)
|
if (!def)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virBufferAddLit(buf, "<cpu");
|
/* Format attributes */
|
||||||
if (def->type == VIR_CPU_TYPE_GUEST) {
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
|
|
||||||
@ -451,7 +452,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
_("Unexpected CPU mode %d"), def->mode);
|
_("Unexpected CPU mode %d"), def->mode);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virBufferAsprintf(buf, " mode='%s'", tmp);
|
virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->model &&
|
if (def->model &&
|
||||||
@ -463,10 +464,11 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
def->match);
|
def->match);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virBufferAsprintf(buf, " match='%s'", tmp);
|
virBufferAsprintf(&attributeBuf, " match='%s'", tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Format children */
|
||||||
virBufferAdjustIndent(&childrenBuf, indent + 2);
|
virBufferAdjustIndent(&childrenBuf, indent + 2);
|
||||||
if (def->arch)
|
if (def->arch)
|
||||||
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
|
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
|
||||||
@ -477,16 +479,25 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
|
if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virBufferUse(&childrenBuf)) {
|
/* Put it all together */
|
||||||
virBufferAddLit(buf, ">\n");
|
if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) {
|
||||||
virBufferAddBuffer(buf, &childrenBuf);
|
virBufferAddLit(buf, "<cpu");
|
||||||
virBufferAddLit(buf, "</cpu>\n");
|
|
||||||
} else {
|
if (virBufferUse(&attributeBuf))
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddBuffer(buf, &attributeBuf);
|
||||||
|
|
||||||
|
if (virBufferUse(&childrenBuf)) {
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAddBuffer(buf, &childrenBuf);
|
||||||
|
virBufferAddLit(buf, "</cpu>\n");
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virBufferFreeAndReset(&attributeBuf);
|
||||||
virBufferFreeAndReset(&childrenBuf);
|
virBufferFreeAndReset(&childrenBuf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
23
tests/qemuxml2argvdata/qemuxml2argv-cpu-empty.xml
Normal file
23
tests/qemuxml2argvdata/qemuxml2argv-cpu-empty.xml
Normal 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>
|
21
tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-empty.xml
Normal file
21
tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-empty.xml
Normal 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>
|
@ -361,6 +361,7 @@ mymain(void)
|
|||||||
|
|
||||||
DO_TEST("clock-utc");
|
DO_TEST("clock-utc");
|
||||||
DO_TEST("clock-localtime");
|
DO_TEST("clock-localtime");
|
||||||
|
DO_TEST_DIFFERENT("cpu-empty");
|
||||||
DO_TEST("cpu-kvmclock");
|
DO_TEST("cpu-kvmclock");
|
||||||
DO_TEST("cpu-host-kvmclock");
|
DO_TEST("cpu-host-kvmclock");
|
||||||
DO_TEST("cpu-host-passthrough-features");
|
DO_TEST("cpu-host-passthrough-features");
|
||||||
|
Loading…
Reference in New Issue
Block a user