]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: snapshot: Remove virDomainSnapshotDefParseNode
authorPeter Krempa <pkrempa@redhat.com>
Thu, 22 Sep 2022 15:33:56 +0000 (17:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 6 Oct 2022 08:54:24 +0000 (10:54 +0200)
Check the root XML node name and fetch XPath context by properly
configuring virXMLParse. Callers can use virDomainSnapshotDefParse
instead.

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

index a5974053f49c298a5260b354f8db0a531d0fd925..afdc11876ddde6a541472118be5c30a91a1f72c6 100644 (file)
@@ -197,7 +197,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
  * If flags does not include
  * VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL, then current is ignored.
  */
-static virDomainSnapshotDef *
+virDomainSnapshotDef *
 virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
                           virDomainXMLOption *xmlopt,
                           void *parseOpaque,
@@ -389,27 +389,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
     return g_steal_pointer(&def);
 }
 
-virDomainSnapshotDef *
-virDomainSnapshotDefParseNode(xmlDocPtr xml,
-                              xmlNodePtr root,
-                              virDomainXMLOption *xmlopt,
-                              void *parseOpaque,
-                              bool *current,
-                              unsigned int flags)
-{
-    g_autoptr(xmlXPathContext) ctxt = NULL;
-
-    if (!virXMLNodeNameEqual(root, "domainsnapshot")) {
-        virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
-        return NULL;
-    }
-
-    if (!(ctxt = virXMLXPathContextNew(xml)))
-        return NULL;
-
-    ctxt->node = root;
-    return virDomainSnapshotDefParse(ctxt, xmlopt, parseOpaque, current, flags);
-}
 
 virDomainSnapshotDef *
 virDomainSnapshotDefParseString(const char *xmlStr,
@@ -418,21 +397,20 @@ virDomainSnapshotDefParseString(const char *xmlStr,
                                 bool *current,
                                 unsigned int flags)
 {
-    virDomainSnapshotDef *ret = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(xmlDoc) xml = NULL;
     int keepBlanksDefault = xmlKeepBlanksDefault(0);
     bool validate = flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE;
 
-    if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"),
-                           NULL, NULL, "domainsnapshot.rng", validate))) {
-        xmlKeepBlanksDefault(keepBlanksDefault);
-        ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml),
-                                            xmlopt, parseOpaque,
-                                            current, flags);
-    }
+    xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"),
+                      "domainsnapshot", &ctxt, "domainsnapshot.rng", validate);
+
     xmlKeepBlanksDefault(keepBlanksDefault);
 
-    return ret;
+    if (!xml)
+        return NULL;
+
+    return virDomainSnapshotDefParse(ctxt, xmlopt, parseOpaque, current, flags);
 }
 
 
index 1f787f1a94203d8a7eacf5945d68f5f5e2b3ca28..fec4a5a912e42a3380dce267ad4ffa0d3823fd96 100644 (file)
@@ -102,12 +102,13 @@ virDomainSnapshotDef *virDomainSnapshotDefParseString(const char *xmlStr,
                                                       void *parseOpaque,
                                                       bool *current,
                                                       unsigned int flags);
-virDomainSnapshotDef *virDomainSnapshotDefParseNode(xmlDocPtr xml,
-                                                    xmlNodePtr root,
-                                                    virDomainXMLOption *xmlopt,
-                                                    void *parseOpaque,
-                                                    bool *current,
-                                                    unsigned int flags);
+virDomainSnapshotDef *
+virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
+                          virDomainXMLOption *xmlopt,
+                          void *parseOpaque,
+                          bool *current,
+                          unsigned int flags);
+
 virDomainSnapshotDef *virDomainSnapshotDefNew(void);
 char *virDomainSnapshotDefFormat(const char *uuidstr,
                                  virDomainSnapshotDef *def,
index 5a4e240d35a35fe2d868b262ef55ab76b4b211b3..50c8a7e2bef2f6a15fee248a6f1f365391210368 100644 (file)
@@ -961,25 +961,23 @@ testParseDomainSnapshots(testDriver *privconn,
                          const char *file,
                          xmlXPathContextPtr ctxt)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
     size_t i;
     testDomainNamespaceDef *nsdata = domobj->def->namespaceData;
     xmlNodePtr *nodes = nsdata->snap_nodes;
-    bool cur;
 
     for (i = 0; i < nsdata->num_snap_nodes; i++) {
         virDomainMomentObj *snap;
         g_autoptr(virDomainSnapshotDef) def = NULL;
-        xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file);
-        if (!node)
+        unsigned int parseFlags = VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL |
+                                  VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
+        bool cur;
+
+        if (!(ctxt->node = testParseXMLDocFromFile(nodes[i], file)))
             return -1;
 
-        def = virDomainSnapshotDefParseNode(ctxt->doc, node,
-                                            privconn->xmlopt,
-                                            NULL,
-                                            &cur,
-                                            VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL |
-                                            VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE);
-        if (!def)
+        if (!(def = virDomainSnapshotDefParse(ctxt, privconn->xmlopt, NULL,
+                                              &cur, parseFlags)))
             return -1;
 
         if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, &def)))