[libvirt] [PATCH 2/4] conf: domain: Invoke post-parse callbacks after parsing private XML parts

Peter Krempa pkrempa at redhat.com
Mon May 28 09:36:45 UTC 2018


When parsing status XML the post-parse callbacks can't access any
private data present in the status XML as the private bits were parsed
after invoking post-parse callbacks.

Move the invocation so that everything is parsed first.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/domain_conf.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index eead28f5fb..43ae5ad96a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18746,7 +18746,6 @@ virDomainDefParseXML(xmlDocPtr xml,
                      xmlXPathContextPtr ctxt,
                      virCapsPtr caps,
                      virDomainXMLOptionPtr xmlopt,
-                     void *parseOpaque,
                      unsigned int flags)
 {
     xmlNodePtr *nodes = NULL, node = NULL;
@@ -20489,14 +20488,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         }
     }

-    /* callback to fill driver specific domain aspects */
-    if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0)
-        goto error;
-
-    /* valdiate configuration */
-    if (virDomainDefValidate(def, caps, flags, xmlopt) < 0)
-        goto error;
-
     virHashFree(bootHash);

     return def;
@@ -20539,7 +20530,7 @@ virDomainObjParseXML(xmlDocPtr xml,

     oldnode = ctxt->node;
     ctxt->node = config;
-    obj->def = virDomainDefParseXML(xml, config, ctxt, caps, xmlopt, NULL, flags);
+    obj->def = virDomainDefParseXML(xml, config, ctxt, caps, xmlopt, flags);
     ctxt->node = oldnode;
     if (!obj->def)
         goto error;
@@ -20598,6 +20589,14 @@ virDomainObjParseXML(xmlDocPtr xml,
         xmlopt->privateData.parse(ctxt, obj, &xmlopt->config) < 0)
         goto error;

+    /* callback to fill driver specific domain aspects */
+    if (virDomainDefPostParse(obj->def, caps, flags, xmlopt, NULL) < 0)
+        goto error;
+
+    /* valdiate configuration */
+    if (virDomainDefValidate(obj->def, caps, flags, xmlopt) < 0)
+        goto error;
+
     return obj;

  error:
@@ -20660,6 +20659,7 @@ virDomainDefParseNode(xmlDocPtr xml,
 {
     xmlXPathContextPtr ctxt = NULL;
     virDomainDefPtr def = NULL;
+    virDomainDefPtr ret = NULL;

     if (!virXMLNodeNameEqual(root, "domain")) {
         virReportError(VIR_ERR_XML_ERROR,
@@ -20676,11 +20676,24 @@ virDomainDefParseNode(xmlDocPtr xml,
     }

     ctxt->node = root;
-    def = virDomainDefParseXML(xml, root, ctxt, caps, xmlopt, parseOpaque, flags);
+
+    if (!(def = virDomainDefParseXML(xml, root, ctxt, caps, xmlopt, flags)))
+        goto cleanup;
+
+    /* callback to fill driver specific domain aspects */
+    if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0)
+        goto cleanup;
+
+    /* valdiate configuration */
+    if (virDomainDefValidate(def, caps, flags, xmlopt) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, def);

  cleanup:
+    virDomainDefFree(def);
     xmlXPathFreeContext(ctxt);
-    return def;
+    return ret;
 }


-- 
2.16.2




More information about the libvir-list mailing list