[PATCH 16/43] conf: storage: Remove virStorageVolDefParseNode

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

 



Proper use of virXMLParse replaces everything the function provides.
Callers can use virStorageVolDefParseXML instead.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/storage_conf.c  | 37 ++++++-------------------------------
 src/conf/storage_conf.h  |  7 +++----
 src/libvirt_private.syms |  2 +-
 src/test/test_driver.c   |  6 +++---
 4 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 0c095c73e0..703149241a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1234,7 +1234,7 @@ virStorageCheckCompat(const char *compat)
 }


-static virStorageVolDef *
+virStorageVolDef *
 virStorageVolDefParseXML(virStoragePoolDef *pool,
                          xmlXPathContextPtr ctxt,
                          unsigned int flags)
@@ -1401,45 +1401,20 @@ virStorageVolDefParseXML(virStoragePoolDef *pool,
 }


-virStorageVolDef *
-virStorageVolDefParseNode(virStoragePoolDef *pool,
-                          xmlDocPtr xml,
-                          xmlNodePtr root,
-                          unsigned int flags)
-{
-    g_autoptr(xmlXPathContext) ctxt = NULL;
-
-    if (!virXMLNodeNameEqual(root, "volume")) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("unexpected root element <%s>, "
-                         "expecting <volume>"),
-                       root->name);
-        return NULL;
-    }
-
-    if (!(ctxt = virXMLXPathContextNew(xml)))
-        return NULL;
-
-    ctxt->node = root;
-    return virStorageVolDefParseXML(pool, ctxt, flags);
-}
-
-
 static virStorageVolDef *
 virStorageVolDefParse(virStoragePoolDef *pool,
                       const char *xmlStr,
                       const char *filename,
                       unsigned int flags)
 {
-    virStorageVolDef *ret = NULL;
     g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;

-    if ((xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"),
-                           NULL, NULL, NULL, false))) {
-        ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml), flags);
-    }
+    if (!(xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"),
+                            "volume", &ctxt, NULL, false)))
+        return NULL;

-    return ret;
+    return virStorageVolDefParseXML(pool, ctxt, flags);
 }


diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index ead54ca7c6..14167af761 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -297,10 +297,9 @@ virStorageVolDefParseFile(virStoragePoolDef *pool,
                           unsigned int flags);

 virStorageVolDef *
-virStorageVolDefParseNode(virStoragePoolDef *pool,
-                          xmlDocPtr xml,
-                          xmlNodePtr root,
-                          unsigned int flags);
+virStorageVolDefParseXML(virStoragePoolDef *pool,
+                         xmlXPathContextPtr ctxt,
+                         unsigned int flags);

 char *
 virStorageVolDefFormat(virStoragePoolDef *pool,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8fec8d9027..3191c9d5f7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1079,8 +1079,8 @@ virStorageVolDefFindByPath;
 virStorageVolDefFormat;
 virStorageVolDefFree;
 virStorageVolDefParseFile;
-virStorageVolDefParseNode;
 virStorageVolDefParseString;
+virStorageVolDefParseXML;
 virStorageVolDefRefreshAllocationTypeFromString;
 virStorageVolDefRefreshAllocationTypeToString;
 virStorageVolTypeFromString;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4245b32c15..943c0834cd 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1147,6 +1147,7 @@ testOpenVolumesForPool(const char *file,
                        xmlXPathContextPtr ctxt,
                        virStoragePoolObj *obj)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
     virStoragePoolDef *def = virStoragePoolObjGetDef(obj);
     size_t i;
     int num;
@@ -1158,11 +1159,10 @@ testOpenVolumesForPool(const char *file,
         return -1;

     for (i = 0; i < num; i++) {
-        xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file);
-        if (!node)
+        if (!(ctxt->node = testParseXMLDocFromFile(nodes[i], file)))
             return -1;

-        if (!(volDef = virStorageVolDefParseNode(def, ctxt->doc, node, 0)))
+        if (!(volDef = virStorageVolDefParseXML(def, ctxt, 0)))
             return -1;

         if (!volDef->target.path) {
-- 
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