[libvirt] [PATCH v1 21/51] util: conf: separate virDomainDefParseLeaseInfo from virDomainDefParseXML

xinhua.Cao caoxinhua at huawei.com
Thu Feb 8 06:46:19 UTC 2018


separate virDomainDefParseLeaseInfo from virDomainDefParseXML,
move virDomainDefParseLeaseInfo into virDomainDefParseDeviceInfo
---
 src/conf/domain_conf.c | 54 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 903dfec..6a27294 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19911,6 +19911,40 @@ virDomainDefParseDisksInfo(virDomainParseTotalParamPtr param)
 
 
 static int
+virDomainDefParseLeaseInfo(virDomainParseTotalParamPtr param)
+{
+    virDomainDefPtr def = param->def;
+    xmlXPathContextPtr ctxt = param->ctxt;
+
+    int ret = -1;
+    int n = 0;
+    size_t i;
+    xmlNodePtr *nodes = NULL;
+
+    /* analysis of the resource leases */
+    if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("cannot extract device leases"));
+        goto cleanup;
+    }
+    if (n && VIR_ALLOC_N(def->leases, n) < 0)
+        goto cleanup;
+    for (i = 0; i < n; i++) {
+        virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]);
+        if (!lease)
+            goto cleanup;
+
+        def->leases[def->nleases++] = lease;
+    }
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    return ret;
+}
+
+
+static int
 virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
 {
     typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param);
@@ -19920,6 +19954,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
     virDomainPreaseDeviceFuc parseFuc[] = {
             virDomainDefParseControllerInfo,
             virDomainDefParseDisksInfo,
+            virDomainDefParseLeaseInfo,
             NULL
     };
 
@@ -19932,8 +19967,6 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
 
  out:
     return ret;
-
-
 }
 
 
@@ -20026,23 +20059,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         fun_index++;
     }
 
-    /* analysis of the resource leases */
-    if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot extract device leases"));
-        goto error;
-    }
-    if (n && VIR_ALLOC_N(def->leases, n) < 0)
-        goto error;
-    for (i = 0; i < n; i++) {
-        virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]);
-        if (!lease)
-            goto error;
-
-        def->leases[def->nleases++] = lease;
-    }
-    VIR_FREE(nodes);
-
     /* analysis of the filesystems */
     if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0)
         goto error;
-- 
2.8.3





More information about the libvir-list mailing list