[PATCH 34/43] virDomainDefParseNode: Pass only the XPath context as argument

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

 



Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/checkpoint_conf.c       |  6 ++++--
 src/conf/domain_conf.c           | 11 ++---------
 src/conf/domain_conf.h           |  3 +--
 src/conf/snapshot_conf.c         | 16 ++++++++++------
 src/qemu/qemu_migration_cookie.c | 10 ++++++----
 src/test/test_driver.c           |  8 ++++----
 tests/qemuxml2argvtest.c         |  3 +--
 7 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index ea20bfdd14..6656089457 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -153,11 +153,13 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
         def->parent.parent_name = virXPathString("string(./parent/name)", ctxt);

         if ((domainNode = virXPathNode("./domain", ctxt))) {
+            VIR_XPATH_NODE_AUTORESTORE(ctxt)
             unsigned int domainParseFlags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
                                             VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;

-            def->parent.dom = virDomainDefParseNode(ctxt->node->doc, domainNode,
-                                                    xmlopt, parseOpaque,
+            ctxt->node = domainNode;
+
+            def->parent.dom = virDomainDefParseNode(ctxt, xmlopt, parseOpaque,
                                                     domainParseFlags);
             if (!def->parent.dom)
                 return NULL;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bd882039e7..bf165d0a64 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19092,7 +19092,7 @@ virDomainDefParse(const char *xmlStr,
     if (!xml)
         return NULL;

-    return virDomainDefParseNode(xml, ctxt->node, xmlopt, parseOpaque, flags);
+    return virDomainDefParseNode(ctxt, xmlopt, parseOpaque, flags);
 }

 virDomainDef *
@@ -19115,20 +19115,13 @@ virDomainDefParseFile(const char *filename,


 virDomainDef *
-virDomainDefParseNode(xmlDocPtr xml,
-                      xmlNodePtr root,
+virDomainDefParseNode(xmlXPathContext *ctxt,
                       virDomainXMLOption *xmlopt,
                       void *parseOpaque,
                       unsigned int flags)
 {
-    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virDomainDef) def = NULL;

-    if (!(ctxt = virXMLXPathContextNew(xml)))
-        return NULL;
-
-    ctxt->node = root;
-
     if (!(def = virDomainDefParseXML(ctxt, xmlopt, flags)))
         return NULL;

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6eab1056c1..8f8a54bc41 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3612,8 +3612,7 @@ virDomainDef *virDomainDefParseFile(const char *filename,
                                     virDomainXMLOption *xmlopt,
                                     void *parseOpaque,
                                     unsigned int flags);
-virDomainDef *virDomainDefParseNode(xmlDocPtr doc,
-                                    xmlNodePtr root,
+virDomainDef *virDomainDefParseNode(xmlXPathContext *ctxt,
                                     virDomainXMLOption *xmlopt,
                                     void *parseOpaque,
                                     unsigned int flags);
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index afdc11876d..4b5b908d66 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -266,15 +266,15 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
          * clients will have to decide between best effort
          * initialization or outright failure.  */
         if ((domtype = virXPathString("string(./domain/@type)", ctxt))) {
-            xmlNodePtr domainNode = virXPathNode("./domain", ctxt);
+            VIR_XPATH_NODE_AUTORESTORE(ctxt)

-            if (!domainNode) {
+            if (!(ctxt->node = virXPathNode("./domain", ctxt))) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("missing domain in snapshot"));
                 return NULL;
             }
-            def->parent.dom = virDomainDefParseNode(ctxt->node->doc, domainNode,
-                                                    xmlopt, parseOpaque,
+
+            def->parent.dom = virDomainDefParseNode(ctxt, xmlopt, parseOpaque,
                                                     domainflags);
             if (!def->parent.dom)
                 return NULL;
@@ -286,8 +286,12 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
          * VM. In case of absent, leave parent.inactiveDom NULL and use
          * parent.dom for config and live XML. */
         if ((inactiveDomNode = virXPathNode("./inactiveDomain", ctxt))) {
-            def->parent.inactiveDom = virDomainDefParseNode(ctxt->node->doc, inactiveDomNode,
-                                                            xmlopt, NULL, domainflags);
+            VIR_XPATH_NODE_AUTORESTORE(ctxt)
+
+            ctxt->node = inactiveDomNode;
+
+            def->parent.inactiveDom = virDomainDefParseNode(ctxt, xmlopt, NULL,
+                                                            domainflags);
             if (!def->parent.inactiveDom)
                 return NULL;
         }
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index a4e018e204..95e803b3e1 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -1261,7 +1261,6 @@ static int
 qemuMigrationCookieXMLParse(qemuMigrationCookie *mig,
                             virQEMUDriver *driver,
                             virQEMUCaps *qemuCaps,
-                            xmlDocPtr doc,
                             xmlXPathContextPtr ctxt,
                             unsigned int flags)
 {
@@ -1356,6 +1355,7 @@ qemuMigrationCookieXMLParse(qemuMigrationCookie *mig,

     if ((flags & QEMU_MIGRATION_COOKIE_PERSISTENT) &&
         virXPathBoolean("count(./domain) > 0", ctxt)) {
+        VIR_XPATH_NODE_AUTORESTORE(ctxt)
         g_autofree xmlNodePtr *nodes = NULL;

         if ((virXPathNodeSet("./domain", ctxt, &nodes)) != 1) {
@@ -1363,8 +1363,10 @@ qemuMigrationCookieXMLParse(qemuMigrationCookie *mig,
                            _("Too many domain elements in migration cookie"));
             return -1;
         }
-        mig->persistent = virDomainDefParseNode(doc, nodes[0],
-                                                driver->xmlopt, qemuCaps,
+
+        ctxt->node = nodes[0];
+
+        mig->persistent = virDomainDefParseNode(ctxt, driver->xmlopt, qemuCaps,
                                                 VIR_DOMAIN_DEF_PARSE_INACTIVE |
                                                 VIR_DOMAIN_DEF_PARSE_ABI_UPDATE_MIGRATION |
                                                 VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
@@ -1420,7 +1422,7 @@ qemuMigrationCookieXMLParseStr(qemuMigrationCookie *mig,
     if (!(doc = virXMLParseStringCtxt(xml, _("(qemu_migration_cookie)"), &ctxt)))
         return -1;

-    return qemuMigrationCookieXMLParse(mig, driver, qemuCaps, doc, ctxt, flags);
+    return qemuMigrationCookieXMLParse(mig, driver, qemuCaps, ctxt, flags);
 }


diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 9f0517e89e..373e5f7846 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1019,14 +1019,14 @@ testParseDomains(testDriver *privconn,
         return -1;

     for (i = 0; i < num; i++) {
+        VIR_XPATH_NODE_AUTORESTORE(ctxt)
         g_autoptr(virDomainDef) def = NULL;
         testDomainNamespaceDef *nsdata;
-        xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file);
-        if (!node)
+
+        if (!(ctxt->node = testParseXMLDocFromFile(nodes[i], file)))
             goto error;

-        def = virDomainDefParseNode(ctxt->doc, node,
-                                    privconn->xmlopt, NULL,
+        def = virDomainDefParseNode(ctxt, privconn->xmlopt, NULL,
                                     VIR_DOMAIN_DEF_PARSE_INACTIVE);
         if (!def)
             goto error;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 8785c96ce1..cad4c1abd5 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -709,8 +709,7 @@ testCompareXMLToArgv(const void *data)

     parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE;

-    if (!(vm->def = virDomainDefParseNode(xml, ctxt->node, driver.xmlopt, NULL,
-                                          parseFlags))) {
+    if (!(vm->def = virDomainDefParseNode(ctxt, driver.xmlopt, NULL, parseFlags))) {
         err = virGetLastError();
         if (!err) {
             VIR_TEST_DEBUG("no error was reported for expected parse error");
-- 
2.37.3




[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