All the devices we have format their address as its last sub-element, so
let's change memballoon to follow suit. Also adjust RNG to allow any
order of them so 'virsh edit' doesn't shout at us.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
docs/schemas/domaincommon.rng | 28 ++++++++++----------
src/conf/domain_conf.c | 30 ++++++++++------------
.../qemuxml2xmlout-balloon-device-period.xml | 30 ++++++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
4 files changed, 60 insertions(+), 29 deletions(-)
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b1d883f..b9d430a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3438,19 +3438,21 @@
<value>none</value>
</choice>
</attribute>
- <optional>
- <ref name="alias"/>
- </optional>
- <optional>
- <ref name="address"/>
- </optional>
- <optional>
- <element name="stats">
- <attribute name="period">
- <ref name="positiveInteger"/>
- </attribute>
- </element>
- </optional>
+ <interleave>
+ <optional>
+ <ref name="alias"/>
+ </optional>
+ <optional>
+ <ref name="address"/>
+ </optional>
+ <optional>
+ <element name="stats">
+ <attribute name="period">
+ <ref name='positiveInteger'/>
+ </attribute>
+ </element>
+ </optional>
+ </interleave>
</element>
</define>
<define name="parallel">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ae8688e..e010040 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18810,7 +18810,8 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
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,
@@ -18819,27 +18820,24 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
}
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;
}
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml
new file mode 100644
index 0000000..79e465a
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml
@@ -0,0 +1,30 @@
+<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>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 8e12e84..9e4b3a2 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -354,6 +354,7 @@ mymain(void)
/* 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");
--
2.3.2