[PATCH 05/37] virDomainNetDefParseXML: Separate and localize parsing of 'backend/@vhost'

Peter Krempa posted 37 patches 3 years, 4 months ago
[PATCH 05/37] virDomainNetDefParseXML: Separate and localize parsing of 'backend/@vhost'
Posted by Peter Krempa 3 years, 4 months ago
Move it into an independent block and move temporary variables locally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 390263d806..0e25d585c8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8869,9 +8869,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree char *vhostuser_mode = NULL;
     g_autofree char *vhostuser_path = NULL;
     g_autofree char *vhostuser_type = NULL;
-    g_autofree char *vhost_path = NULL;
     g_autofree char *tap = NULL;
-    g_autofree char *vhost = NULL;
     g_autofree char *switchid = NULL;
     g_autofree char *connectionid = NULL;
     const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL;
@@ -9039,9 +9037,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
     if ((tap = virXPathString("string(./backend/@tap)", ctxt)))
         def->backend.tap = virFileSanitizePath(tap);

-    if ((vhost = virXPathString("string(./backend/@vhost)", ctxt)))
-        vhost_path = virFileSanitizePath(vhost);
-
     mac_node = virXPathNode("./mac", ctxt);

     if ((macaddr = virXMLPropString(mac_node, "address"))) {
@@ -9484,7 +9479,14 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
                                          &def->driver.virtio.guest.ufo) < 0)
                 return NULL;
         }
-        def->backend.vhost = g_steal_pointer(&vhost_path);
+    }
+
+    if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+        virDomainNetIsVirtioModel(def)) {
+        g_autofree  char *vhost = virXPathString("string(./backend/@vhost)", ctxt);
+
+        if (vhost)
+            def->backend.vhost = virFileSanitizePath(vhost);
     }

     def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
-- 
2.37.1
Re: [PATCH 05/37] virDomainNetDefParseXML: Separate and localize parsing of 'backend/@vhost'
Posted by Ján Tomko 3 years, 4 months ago
On a Monday in 2022, Peter Krempa wrote:
>Move it into an independent block and move temporary variables locally.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
>@@ -9484,7 +9479,14 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
>                                          &def->driver.virtio.guest.ufo) < 0)
>                 return NULL;
>         }
>-        def->backend.vhost = g_steal_pointer(&vhost_path);
>+    }
>+
>+    if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
>+        virDomainNetIsVirtioModel(def)) {
>+        g_autofree  char *vhost = virXPathString("string(./backend/@vhost)", ctxt);
>+

Double space -------^

>+        if (vhost)
>+            def->backend.vhost = virFileSanitizePath(vhost);
>     }
>
>     def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
>-- 
>2.37.1
>
Re: [PATCH 05/37] virDomainNetDefParseXML: Separate and localize parsing of 'backend/@vhost'
Posted by Ján Tomko 3 years, 4 months ago
On a Monday in 2022, Peter Krempa wrote:
>Move it into an independent block and move temporary variables locally.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano