[libvirt] [PATCH] conf: fix formatting of udp chardev attributes

Ján Tomko posted 1 patch 6 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/fcd5c61cd4ea3d1a0a14260e2b3443b0292b19cb.1506426025.git.jtomko@redhat.com
src/conf/domain_conf.c                              | 12 ++++--------
tests/genericxml2xmloutdata/generic-chardev-udp.xml |  2 +-
2 files changed, 5 insertions(+), 9 deletions(-)
[libvirt] [PATCH] conf: fix formatting of udp chardev attributes
Posted by Ján Tomko 6 years, 6 months ago
It is possible (although possibly not very useful) to leave out
the service attribute when using <source mode='bind'/>

Fix the formatter bug introduced by commit 4a0da34 and format
the host when its present (checked for non-NULL inside
virBufferEscapeString) instead of basing it on the presence
of the service attribute.

https://bugzilla.redhat.com/show_bug.cgi?id=1455825
---
 src/conf/domain_conf.c                              | 12 ++++--------
 tests/genericxml2xmloutdata/generic-chardev-udp.xml |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 44cfb52b4..3c3db7291 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23307,19 +23307,15 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
     case VIR_DOMAIN_CHR_TYPE_UDP:
         if (def->data.udp.bindService || def->data.udp.bindHost) {
             virBufferAddLit(buf, "<source mode='bind'");
-            if (def->data.udp.bindService)
-                virBufferEscapeString(buf, " host='%s'", def->data.udp.bindHost);
-            if (def->data.udp.bindService)
-                virBufferEscapeString(buf, " service='%s'", def->data.udp.bindService);
+            virBufferEscapeString(buf, " host='%s'", def->data.udp.bindHost);
+            virBufferEscapeString(buf, " service='%s'", def->data.udp.bindService);
             virBufferAddLit(buf, "/>\n");
         }
 
         if (def->data.udp.connectService || def->data.udp.connectHost) {
             virBufferAddLit(buf, "<source mode='connect'");
-            if (def->data.udp.connectService)
-                virBufferEscapeString(buf, " host='%s'", def->data.udp.connectHost);
-            if (def->data.udp.connectService)
-                virBufferEscapeString(buf, " service='%s'", def->data.udp.connectService);
+            virBufferEscapeString(buf, " host='%s'", def->data.udp.connectHost);
+            virBufferEscapeString(buf, " service='%s'", def->data.udp.connectService);
             virBufferAddLit(buf, "/>\n");
         }
         break;
diff --git a/tests/genericxml2xmloutdata/generic-chardev-udp.xml b/tests/genericxml2xmloutdata/generic-chardev-udp.xml
index c4a719f2f..c9b3e5550 100644
--- a/tests/genericxml2xmloutdata/generic-chardev-udp.xml
+++ b/tests/genericxml2xmloutdata/generic-chardev-udp.xml
@@ -29,7 +29,7 @@
       <target type='virtio' name='test3'/>
     </channel>
     <channel type='udp'>
-      <source mode='bind'/>
+      <source mode='bind' host='localhost'/>
       <source mode='connect' service='5678'/>
       <target type='virtio' name='test4'/>
     </channel>
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: fix formatting of udp chardev attributes
Posted by Erik Skultety 6 years, 6 months ago
On Tue, Sep 26, 2017 at 01:40:30PM +0200, Ján Tomko wrote:
> It is possible (although possibly not very useful) to leave out
> the service attribute when using <source mode='bind'/>
>
> Fix the formatter bug introduced by commit 4a0da34 and format
> the host when its present (checked for non-NULL inside
> virBufferEscapeString) instead of basing it on the presence
> of the service attribute.
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1455825

ACK

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list