[PATCH 23/43] conf: backup: Remove virDomainBackupDefParseNode

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

 



Rename virDomainBackupDefParse to virDomainBackupDefParseXML and use
it in place of virDomainBackupDefParseNode. This is possible as
virXMLParse can be used to replace XPath context allocation and root
node checking.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/backup_conf.c   | 41 ++++++++++------------------------------
 src/conf/backup_conf.h   | 10 +++++-----
 src/libvirt_private.syms |  2 +-
 src/qemu/qemu_domain.c   |  9 ++++++---
 4 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c
index 7dfc8ee635..ad5633388d 100644
--- a/src/conf/backup_conf.c
+++ b/src/conf/backup_conf.c
@@ -190,10 +190,10 @@ virDomainBackupDefParsePrivate(virDomainBackupDef *def,
 }


-static virDomainBackupDef *
-virDomainBackupDefParse(xmlXPathContextPtr ctxt,
-                        virDomainXMLOption *xmlopt,
-                        unsigned int flags)
+virDomainBackupDef *
+virDomainBackupDefParseXML(xmlXPathContextPtr ctxt,
+                           virDomainXMLOption *xmlopt,
+                           unsigned int flags)
 {
     g_autoptr(virDomainBackupDef) def = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
@@ -274,41 +274,20 @@ virDomainBackupDefParseString(const char *xmlStr,
                               virDomainXMLOption *xmlopt,
                               unsigned int flags)
 {
-    virDomainBackupDef *ret = NULL;
     g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int keepBlanksDefault = xmlKeepBlanksDefault(0);
     bool validate = !(flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL);

-    if ((xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"),
-                           NULL, NULL, "domainbackup.rng", validate))) {
-        xmlKeepBlanksDefault(keepBlanksDefault);
-        ret = virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml),
-                                          xmlopt, flags);
-    }
-    xmlKeepBlanksDefault(keepBlanksDefault);
-
-    return ret;
-}
-
+    xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"),
+                      "domainbackup", &ctxt, "domainbackup.rng", validate);

-virDomainBackupDef *
-virDomainBackupDefParseNode(xmlDocPtr xml,
-                            xmlNodePtr root,
-                            virDomainXMLOption *xmlopt,
-                            unsigned int flags)
-{
-    g_autoptr(xmlXPathContext) ctxt = NULL;
-
-    if (!virXMLNodeNameEqual(root, "domainbackup")) {
-        virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup"));
-        return NULL;
-    }
+    xmlKeepBlanksDefault(keepBlanksDefault);

-    if (!(ctxt = virXMLXPathContextNew(xml)))
+    if (!xml)
         return NULL;

-    ctxt->node = root;
-    return virDomainBackupDefParse(ctxt, xmlopt, flags);
+    return virDomainBackupDefParseXML(ctxt, xmlopt, flags);
 }


diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h
index dc66b75892..9c3532a546 100644
--- a/src/conf/backup_conf.h
+++ b/src/conf/backup_conf.h
@@ -105,16 +105,16 @@ typedef enum {
     VIR_DOMAIN_BACKUP_PARSE_INTERNAL = 1 << 0,
 } virDomainBackupParseFlags;

+virDomainBackupDef *
+virDomainBackupDefParseXML(xmlXPathContextPtr ctxt,
+                           virDomainXMLOption *xmlopt,
+                           unsigned int flags);
+
 virDomainBackupDef *
 virDomainBackupDefParseString(const char *xmlStr,
                               virDomainXMLOption *xmlopt,
                               unsigned int flags);

-virDomainBackupDef *
-virDomainBackupDefParseNode(xmlDocPtr xml,
-                            xmlNodePtr root,
-                            virDomainXMLOption *xmlopt,
-                            unsigned int flags);
 void
 virDomainBackupDefFree(virDomainBackupDef *def);

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6334cbb448..0adcf20f0c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -46,8 +46,8 @@ virAccessPermStorageVolTypeToString;
 virDomainBackupAlignDisks;
 virDomainBackupDefFormat;
 virDomainBackupDefFree;
-virDomainBackupDefParseNode;
 virDomainBackupDefParseString;
+virDomainBackupDefParseXML;


 # conf/capabilities.h
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ee024d17cd..ee35ef586f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2860,6 +2860,7 @@ static int
 qemuDomainObjPrivateXMLParseBackups(qemuDomainObjPrivate *priv,
                                     xmlXPathContextPtr ctxt)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree xmlNodePtr *nodes = NULL;
     ssize_t nnodes = 0;

@@ -2875,9 +2876,11 @@ qemuDomainObjPrivateXMLParseBackups(qemuDomainObjPrivate *priv,
     if (nnodes == 0)
         return 0;

-    if (!(priv->backup = virDomainBackupDefParseNode(ctxt->doc, nodes[0],
-                                                     priv->driver->xmlopt,
-                                                     VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))
+    ctxt->node = nodes[0];
+
+    if (!(priv->backup = virDomainBackupDefParseXML(ctxt,
+                                                    priv->driver->xmlopt,
+                                                    VIR_DOMAIN_BACKUP_PARSE_INTERNAL)))
         return -1;

     return 0;
-- 
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