[libvirt] [PATCH v1 27/51] util: conf: separate virDomainDefParseConsoleInfo from virDomainDefParseXML

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


separate virDomainDefParseConsoleInfo from virDomainDefParseXML,
move virDomainDefParseConsoleInfo into virDomainDefParseDeviceInfo
---
 src/conf/domain_conf.c | 68 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 24 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c4743cf..b74e332 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20163,6 +20163,48 @@ virDomainDefParseSerialInfo(virDomainParseTotalParamPtr param)
 
 
 static int
+virDomainDefParseConsoleInfo(virDomainParseTotalParamPtr param)
+{
+    virDomainDefPtr def = param->def;
+    xmlXPathContextPtr ctxt = param->ctxt;
+    virDomainXMLOptionPtr xmlopt = param->xmlopt;
+    unsigned int flags = param->flags;
+
+    int ret = -1;
+    int n = 0;
+    size_t i;
+    xmlNodePtr *nodes = NULL;
+
+    if ((n = virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("cannot extract console devices"));
+        goto cleanup;
+    }
+    if (n && VIR_ALLOC_N(def->consoles, n) < 0)
+        goto cleanup;
+
+    for (i = 0; i < n; i++) {
+        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
+                                                         ctxt,
+                                                         nodes[i],
+                                                         def->seclabels,
+                                                         def->nseclabels,
+                                                         flags);
+        if (!chr)
+            goto cleanup;
+
+        chr->target.port = i;
+        def->consoles[def->nconsoles++] = chr;
+    }
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    return ret;
+}
+
+
+static int
 virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
 {
     typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param);
@@ -20178,6 +20220,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
             virDomainDefParseSmartCardsInfo,
             virDomainDefParseParallelInfo,
             virDomainDefParseSerialInfo,
+            virDomainDefParseConsoleInfo,
             NULL
     };
 
@@ -20206,7 +20249,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     xmlNodePtr *nodes = NULL, node = NULL;
     char *tmp = NULL;
-    size_t i, j;
+    size_t i;
     int n;
     size_t fun_index = 0;
     virDomainDefPtr def;
@@ -20281,29 +20324,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         fun_index++;
     }
 
-    if ((n = virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot extract console devices"));
-        goto error;
-    }
-    if (n && VIR_ALLOC_N(def->consoles, n) < 0)
-        goto error;
-
-    for (i = 0; i < n; i++) {
-        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
-                                                         ctxt,
-                                                         nodes[i],
-                                                         def->seclabels,
-                                                         def->nseclabels,
-                                                         flags);
-        if (!chr)
-            goto error;
-
-        chr->target.port = i;
-        def->consoles[def->nconsoles++] = chr;
-    }
-    VIR_FREE(nodes);
-
     if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0)
         goto error;
     if (n && VIR_ALLOC_N(def->channels, n) < 0)
-- 
2.8.3





More information about the libvir-list mailing list