unsigned int flags)
{
const char *model = virDomainMemballoonModelTypeToString(def->model);
- bool noopts = true;
+ virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
+ int indent = virBufferGetIndent(buf, false);
if (!model) {
virReportError(VIR_ERR_INTERNAL_ERROR,
}
virBufferAsprintf(buf, "<memballoon model='%s'", model);
- virBufferAdjustIndent(buf, 2);
+ virBufferAdjustIndent(&childrenBuf, indent + 2);
- if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
- virBufferAddLit(buf, ">\n");
- if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
- return -1;
- noopts = false;
- }
+ if (def->period)
+ virBufferAsprintf(&childrenBuf, "<stats period='%u'/>\n", def->period);
- if (def->period) {
- if (noopts)
- virBufferAddLit(buf, ">\n");
- virBufferAsprintf(buf, "<stats period='%u'/>\n", def->period);
- noopts = false;
+ if (virDomainDeviceInfoNeedsFormat(&def->info, flags) &&
+ virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) {
+ virBufferFreeAndReset(&childrenBuf);
+ return -1;
}
- virBufferAdjustIndent(buf, -2);
- if (noopts)
+ if (!virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "/>\n");
- else
+ } else {
+ virBufferAddLit(buf, ">\n");
+ virBufferAddBuffer(buf, &childrenBuf);
virBufferAddLit(buf, "</memballoon>\n");
+ }
return 0;
}
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' 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</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'>
+ <stats period='10'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
/* These tests generate different XML */
DO_TEST_DIFFERENT("balloon-device-auto");
+ DO_TEST_DIFFERENT("balloon-device-period");
DO_TEST_DIFFERENT("channel-virtio-auto");
DO_TEST_DIFFERENT("console-compat-auto");
DO_TEST_DIFFERENT("disk-scsi-device-auto");