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); - } + xml = virXMLParse(NULL, xmlStr, _("(domain_backup)"), + "domainbackup", &ctxt, "domainbackup.rng", validate); + xmlKeepBlanksDefault(keepBlanksDefault); - return ret; -} - - -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; - } - - 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 858d14af6a..4c14fc2aef 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;