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;
_("Unexpected CPU mode %d"), def->mode);
goto cleanup;
}
- virBufferAsprintf(buf, " mode='%s'", tmp);
+ virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
}
if (def->model &&
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",
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;
}
--- /dev/null
+<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>
--- /dev/null
+<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>