]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainNetIPInfoParseXML: Don't force callers to set proper 'ctxt->node'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Sep 2022 16:04:12 +0000 (18:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Oct 2022 12:43:17 +0000 (14:43 +0200)
In certain cases it's inconvenient to move the XPath's context current
node in the caller. Add a 'node' argument and override it inside the
function. VIR_XPATH_NODE_AUTORESTORE handles the cleanup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index ffc55508efbf667b83906696ef85bf00ecd99a7b..9b327e9ab7aecab74f0542c24c628f788a41c04c 100644 (file)
@@ -6213,15 +6213,20 @@ virDomainNetIPParseXML(xmlNodePtr node)
  */
 static int
 virDomainNetIPInfoParseXML(const char *source,
+                           xmlNodePtr node,
                            xmlXPathContextPtr ctxt,
                            virNetDevIPInfo *def)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
     size_t i;
     g_autofree xmlNodePtr *ipNodes = NULL;
     int nipNodes;
     g_autofree xmlNodePtr *routeNodes = NULL;
     int nrouteNodes;
 
+    if (node)
+        ctxt->node = node;
+
     if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0 ||
         (nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0)
         return -1;
@@ -6368,7 +6373,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED,
                            _("Missing <interface> element in hostdev net device"));
             return -1;
         }
-        if (virDomainNetIPInfoParseXML(_("Domain hostdev device"),
+        if (virDomainNetIPInfoParseXML(_("Domain hostdev device"), NULL,
                                        ctxt, &def->source.caps.u.net.ip) < 0)
             return -1;
         break;
@@ -9010,12 +9015,8 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
         return NULL;
 
     if ((source_node = virXPathNode("./source", ctxt))) {
-        xmlNodePtr tmpnode = ctxt->node;
-
-        ctxt->node = source_node;
-        if (virDomainNetIPInfoParseXML(_("interface host IP"), ctxt, &def->hostIP) < 0)
+        if (virDomainNetIPInfoParseXML(_("interface host IP"), source_node, ctxt, &def->hostIP) < 0)
             return NULL;
-        ctxt->node = tmpnode;
 
         if (def->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
             network = virXMLPropString(source_node, "network");
@@ -9463,7 +9464,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
         break;
     }
 
-    if (virDomainNetIPInfoParseXML(_("guest interface"),
+    if (virDomainNetIPInfoParseXML(_("guest interface"), node,
                                    ctxt, &def->guestIP) < 0)
         return NULL;