[libvirt] [PATCH 03/18] conf: only format <controller> as a pair tag when needed

Ján Tomko posted 18 patches 7 years, 11 months ago
[libvirt] [PATCH 03/18] conf: only format <controller> as a pair tag when needed
Posted by Ján Tomko 7 years, 11 months ago
Make the decision based on the usage of childBuf buffer.

This fixes the oddity in the test case introduced by commit c1c4d0d
where we would format an empty pair tag.
---
 src/conf/domain_conf.c                                          | 4 +++-
 tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fe0eaf2..57f52be 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21464,7 +21464,6 @@ virDomainControllerDefFormat(virBufferPtr buf,
         def->queues || def->cmd_per_lun || def->max_sectors || def->ioeventfd ||
         def->iothread ||
         virDomainDeviceInfoNeedsFormat(&def->info, flags) || pcihole64) {
-        virBufferAddLit(buf, ">\n");
 
         if (pciModel) {
             modelName = virDomainControllerPCIModelNameTypeToString(def->opts.pciopts.modelName);
@@ -21513,7 +21512,10 @@ virDomainControllerDefFormat(virBufferPtr buf,
             virBufferAsprintf(&childBuf, "<pcihole64 unit='KiB'>%lu</"
                               "pcihole64>\n", def->opts.pciopts.pcihole64size);
         }
+    }
 
+    if (virBufferUse(&childBuf)) {
+        virBufferAddLit(buf, ">\n");
         virBufferAddBuffer(buf, &childBuf);
         virBufferAddLit(buf, "</controller>\n");
     } else {
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
index 882d005..7eb1a76 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
@@ -14,8 +14,7 @@
   <on_crash>destroy</on_crash>
   <devices>
     <emulator>/usr/bin/qemu-system-s390x</emulator>
-    <controller type='virtio-serial' index='0'>
-    </controller>
+    <controller type='virtio-serial' index='0'/>
     <console type='pty'>
       <target type='virtio' port='0'/>
     </console>
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/18] conf: only format <controller> as a pair tag when needed
Posted by Pavel Hrdina 7 years, 11 months ago
On Tue, May 30, 2017 at 02:50:26PM +0200, Ján Tomko wrote:
> Make the decision based on the usage of childBuf buffer.
> 
> This fixes the oddity in the test case introduced by commit c1c4d0d
> where we would format an empty pair tag.
> ---
>  src/conf/domain_conf.c                                          | 4 +++-
>  tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml | 3 +--
>  2 files changed, 4 insertions(+), 3 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list