From 02ce97bca6ff460c02abb76a6ef22e340e37ce8f Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Fri, 13 Mar 2015 16:16:57 +0100 Subject: [PATCH] conf: Reorder elements inside memballoon 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 --- docs/schemas/domaincommon.rng | 28 ++++++++-------- src/conf/domain_conf.c | 32 +++++++++---------- .../qemuxml2xmlout-balloon-device-period.xml | 30 +++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 4 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index e98e9052aa..ebd9299371 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3440,19 +3440,21 @@ none - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e8cda6ca28..3865854a5c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18826,7 +18826,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, @@ -18835,27 +18836,24 @@ virDomainMemballoonDefFormat(virBufferPtr buf, } virBufferAsprintf(buf, "info, flags)) { - virBufferAddLit(buf, ">\n"); - if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) - return -1; - noopts = false; + if (def->period) + virBufferAsprintf(&childrenBuf, "\n", def->period); + + if (virDomainDeviceInfoNeedsFormat(&def->info, flags) && + virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) { + virBufferFreeAndReset(&childrenBuf); + return -1; } - if (def->period) { - if (noopts) - virBufferAddLit(buf, ">\n"); - virBufferAsprintf(buf, "\n", def->period); - noopts = false; - } - - virBufferAdjustIndent(buf, -2); - if (noopts) + if (!virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "/>\n"); - else + } else { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &childrenBuf); virBufferAddLit(buf, "\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 0000000000..79e465a801 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-balloon-device-period.xml @@ -0,0 +1,30 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 6ffe36b700..7755ea3675 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");