[PATCH 22/23] conf: Move XPath context node in descendants of virSysinfoParseXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than moving the XPath root node in the caller and then still
passing it down, make sure that the callees move the node themselves.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 45 ++++++++++++++++++------------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ea4fbf2280..bbeb1c1a8d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14606,9 +14606,12 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
                        xmlXPathContextPtr ctxt,
                        virSysinfoBIOSDefPtr *bios)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoBIOSDefPtr def;

+    ctxt->node = node;
+
     if (!virXMLNodeNameEqual(node, "bios")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'bios' element"));
@@ -14666,10 +14669,13 @@ virSysinfoSystemParseXML(xmlNodePtr node,
                          unsigned char *domUUID,
                          bool uuid_generated)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoSystemDefPtr def;
     VIR_AUTOFREE(char *) tmpUUID = NULL;

+    ctxt->node = node;
+
     if (!virXMLNodeNameEqual(node, "system")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'system' element"));
@@ -14786,15 +14792,19 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt,


 static int
-virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt,
+virSysinfoOEMStringsParseXML(xmlNodePtr node,
+                             xmlXPathContextPtr ctxt,
                              virSysinfoOEMStringsDefPtr *oem)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoOEMStringsDefPtr def;
     int nstrings;
     size_t i;
     VIR_AUTOFREE(xmlNodePtr *) strings = NULL;

+    ctxt->node = node;
+
     nstrings = virXPathNodeSet("./entry", ctxt, &strings);
     if (nstrings < 0)
         return -1;
@@ -14824,9 +14834,12 @@ virSysinfoChassisParseXML(xmlNodePtr node,
                          xmlXPathContextPtr ctxt,
                          virSysinfoChassisDefPtr *chassisdef)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoChassisDefPtr def;

+    ctxt->node = node;
+
     if (!xmlStrEqual(node->name, BAD_CAST "chassis")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'chassis' element"));
@@ -14868,7 +14881,7 @@ virSysinfoParseXML(xmlNodePtr node,
                   bool uuid_generated)
 {
     virSysinfoDefPtr def;
-    xmlNodePtr oldnode, tmpnode;
+    xmlNodePtr tmpnode;
     VIR_AUTOFREE(char *) type = NULL;

     if (!virXMLNodeNameEqual(node, "sysinfo")) {
@@ -14894,25 +14907,15 @@ virSysinfoParseXML(xmlNodePtr node,

     /* Extract BIOS related metadata */
     if ((tmpnode = virXPathNode("./bios[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }

     /* Extract system related metadata */
     if ((tmpnode = virXPathNode("./system[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
         if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system,
-                                     domUUID, uuid_generated) < 0) {
-            ctxt->node = oldnode;
+                                     domUUID, uuid_generated) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }

     /* Extract system base board metadata */
@@ -14921,24 +14924,14 @@ virSysinfoParseXML(xmlNodePtr node,

     /* Extract chassis related metadata */
     if ((tmpnode = virXPathNode("./chassis[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }

     /* Extract system related metadata */
     if ((tmpnode = virXPathNode("./oemStrings[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoOEMStringsParseXML(ctxt, &def->oemStrings) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }

  cleanup:
-- 
2.20.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux