[libvirt] [PATCH v1 46/51] util: conf: separate virDomainDefParseIdmapInfo from virDomainDefParseXML

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


separate virDomainDefParseIdmapInfo from virDomainDefParseXML
---
 src/conf/domain_conf.c | 83 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 50 insertions(+), 33 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e6498c3..de8a9fc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20948,6 +20948,55 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
 }
 
 
+static int
+virDomainDefParseIdmapInfo(virDomainParseTotalParamPtr param)
+{
+    virDomainDefPtr def = param->def;
+    xmlXPathContextPtr ctxt = param->ctxt;
+
+    int ret = -1;
+    int n = 0;
+    xmlNodePtr *nodes = NULL;
+
+    /* analysis of the user namespace mapping */
+    if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0)
+        goto cleanup;
+
+    if (n) {
+        def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, nodes, n);
+        if (!def->idmap.uidmap)
+            goto cleanup;
+
+        def->idmap.nuidmap = n;
+    }
+    VIR_FREE(nodes);
+
+    if  ((n = virXPathNodeSet("./idmap/gid", ctxt, &nodes)) < 0)
+        goto cleanup;
+
+    if (n) {
+        def->idmap.gidmap =  virDomainIdmapDefParseXML(ctxt, nodes, n);
+        if (!def->idmap.gidmap)
+            goto cleanup;
+
+        def->idmap.ngidmap = n;
+    }
+    VIR_FREE(nodes);
+
+    if ((def->idmap.uidmap && !def->idmap.gidmap) ||
+        (!def->idmap.uidmap && def->idmap.gidmap)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("uid and gid should be mapped both"));
+            goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    return ret;
+}
+
+
 static virDomainDefPtr
 virDomainDefParseXML(xmlDocPtr xml,
                      xmlNodePtr root,
@@ -20961,7 +21010,6 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     xmlNodePtr *nodes = NULL, node = NULL;
     char *tmp = NULL;
-    int n;
     size_t fun_index = 0;
     virDomainDefPtr def;
     bool uuid_generated = false;
@@ -21003,6 +21051,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             virDomainDefParseClockInfo,
             virDomainDefParseBootOptionsInfo,
             virDomainDefParseDeviceInfo,
+            virDomainDefParseIdmapInfo,
             NULL
     };
 
@@ -21034,38 +21083,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         fun_index++;
     }
 
-    /* analysis of the user namespace mapping */
-    if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0)
-        goto error;
-
-    if (n) {
-        def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, nodes, n);
-        if (!def->idmap.uidmap)
-            goto error;
-
-        def->idmap.nuidmap = n;
-    }
-    VIR_FREE(nodes);
-
-    if  ((n = virXPathNodeSet("./idmap/gid", ctxt, &nodes)) < 0)
-        goto error;
-
-    if (n) {
-        def->idmap.gidmap =  virDomainIdmapDefParseXML(ctxt, nodes, n);
-        if (!def->idmap.gidmap)
-            goto error;
-
-        def->idmap.ngidmap = n;
-    }
-    VIR_FREE(nodes);
-
-    if ((def->idmap.uidmap && !def->idmap.gidmap) ||
-        (!def->idmap.uidmap && def->idmap.gidmap)) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("uid and gid should be mapped both"));
-            goto error;
-    }
-
     if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) {
         xmlNodePtr oldnode = ctxt->node;
         ctxt->node = node;
-- 
2.8.3





More information about the libvir-list mailing list