[libvirt] [PATCH v1 10/51] util: conf: separate virDomainDefParseCputuneInfo from virDomainDefParseXML

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


separate virDomainDefParseCputuneInfo from virDomainDefParseXML
---
 src/conf/domain_conf.c | 227 +++++++++++++++++++++++++++----------------------
 1 file changed, 124 insertions(+), 103 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1d74631..e50e56f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18996,88 +18996,24 @@ virDomainDefParseIoThreadInfo(virDomainParseTotalParamPtr param)
 }
 
 
-static virDomainDefPtr
-virDomainDefParseXML(xmlDocPtr xml,
-                     xmlNodePtr root,
-                     xmlXPathContextPtr ctxt,
-                     virCapsPtr caps,
-                     virDomainXMLOptionPtr xmlopt,
-                     void *parseOpaque,
-                     unsigned int flags)
+static int
+virDomainDefParseCputuneInfo(virDomainParseTotalParamPtr param)
 {
-    typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params);
-
-    xmlNodePtr *nodes = NULL, node = NULL;
-    char *tmp = NULL;
-    size_t i, j;
-    int n, gic_version;
-    size_t fun_index = 0;
-    virDomainDefPtr def;
-    bool uuid_generated = false;
-    virHashTablePtr bootHash = NULL;
-    bool usb_none = false;
-    bool usb_other = false;
-    bool usb_master = false;
-    char *netprefix = NULL;
-    virDomainParseTotalParam param = {
-            NULL,
-            xml,
-            root,
-            ctxt,
-            caps,
-            xmlopt,
-            parseOpaque,
-            flags,
-            false,
-            false,
-            false,
-            false
-
-    };
-
-    virDomainPreaseInfoFunc parse_funs[] = {
-            virDomainDefParseIdInfo,
-            virDomainDefParseVirtTypeInfo,
-            virDomainDefParseOsNodeInfo,
-            virDomainDefParseDomainInfo,
-            virDomainDefParseSecurityLabelInfo,
-            virDomainDefParseMemoryInfo,
-            virDomainDefParseBikiotuneInfo,
-            virDomainDefParseVcpuInfo,
-            virDomainDefParseIoThreadInfo,
-            NULL
-    };
-
-    if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) {
-        char *schema = virFileFindResource("domain.rng",
-                                           abs_topsrcdir "/docs/schemas",
-                                           PKGDATADIR "/schemas");
-        if (!schema)
-            return NULL;
-        if (virXMLValidateAgainstSchema(schema, xml) < 0) {
-            VIR_FREE(schema);
-            return NULL;
-        }
-        VIR_FREE(schema);
-    }
-
-    if (!(def = virDomainDefNew()))
-        return NULL;
-
-    param.def = def;
+    virDomainDefPtr def = param->def;
+    xmlXPathContextPtr ctxt = param->ctxt;
+    unsigned int flags = param->flags;
 
-    while (parse_funs[fun_index]) {
-        if (parse_funs[fun_index](&param) < 0)
-            goto error;
-        fun_index++;
-    }
+    int ret = -1;
+    int n;
+    size_t i;
+    xmlNodePtr *nodes = NULL;
 
     /* Extract cpu tunables. */
     if ((n = virXPathULongLong("string(./cputune/shares[1])", ctxt,
                                &def->cputune.shares)) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune shares value"));
-        goto error;
+        goto cleanup;
     } else if (n == 0) {
         def->cputune.sharesSpecified = true;
     }
@@ -19086,7 +19022,7 @@ virDomainDefParseXML(xmlDocPtr xml,
                           &def->cputune.period) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune period value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.period > 0 &&
@@ -19094,14 +19030,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune period must be in range "
                          "[1000, 1000000]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
                          &def->cputune.quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune quota value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.quota > 0 &&
@@ -19110,14 +19046,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune quota must be in range "
                          "[1000, 18446744073709551]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathULongLong("string(./cputune/global_period[1])", ctxt,
                           &def->cputune.global_period) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune global period value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.global_period > 0 &&
@@ -19125,14 +19061,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune global period must be in range "
                          "[1000, 1000000]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathLongLong("string(./cputune/global_quota[1])", ctxt,
                          &def->cputune.global_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune global quota value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.global_quota > 0 &&
@@ -19141,14 +19077,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune global quota must be in range "
                          "[1000, 18446744073709551]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
                           &def->cputune.emulator_period) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune emulator period value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.emulator_period > 0 &&
@@ -19157,14 +19093,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune emulator_period must be in range "
                          "[1000, 1000000]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
                          &def->cputune.emulator_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune emulator quota value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.emulator_quota > 0 &&
@@ -19173,14 +19109,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune emulator_quota must be in range "
                          "[1000, 18446744073709551]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathULongLong("string(./cputune/iothread_period[1])", ctxt,
                           &def->cputune.iothread_period) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune iothread period value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.iothread_period > 0 &&
@@ -19189,14 +19125,14 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune iothread_period must be in range "
                          "[1000, 1000000]"));
-        goto error;
+        goto cleanup;
     }
 
     if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt,
                          &def->cputune.iothread_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune iothread quota value"));
-        goto error;
+        goto cleanup;
     }
 
     if (def->cputune.iothread_quota > 0 &&
@@ -19205,22 +19141,22 @@ virDomainDefParseXML(xmlDocPtr xml,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Value of cputune iothread_quota must be in range "
                          "[1000, 18446744073709551]"));
-        goto error;
+        goto cleanup;
     }
 
     if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
-        goto error;
+        goto cleanup;
 
     for (i = 0; i < n; i++) {
         if (virDomainVcpuPinDefParseXML(def, nodes[i]))
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
     if ((n = virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract emulatorpin nodes"));
-        goto error;
+        goto cleanup;
     }
 
     if (n) {
@@ -19228,11 +19164,11 @@ virDomainDefParseXML(xmlDocPtr xml,
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("only one emulatorpin is supported"));
             VIR_FREE(nodes);
-            goto error;
+            goto cleanup;
         }
 
         if (!(def->cputune.emulatorpin = virDomainEmulatorPinDefParseXML(nodes[0])))
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
@@ -19240,51 +19176,136 @@ virDomainDefParseXML(xmlDocPtr xml,
     if ((n = virXPathNodeSet("./cputune/iothreadpin", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract iothreadpin nodes"));
-        goto error;
+        goto cleanup;
     }
 
     for (i = 0; i < n; i++) {
         if (virDomainIOThreadPinDefParseXML(nodes[i], def) < 0)
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
     if ((n = virXPathNodeSet("./cputune/vcpusched", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract vcpusched nodes"));
-        goto error;
+        goto cleanup;
     }
 
     for (i = 0; i < n; i++) {
         if (virDomainVcpuThreadSchedParse(nodes[i], def) < 0)
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
     if ((n = virXPathNodeSet("./cputune/iothreadsched", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract iothreadsched nodes"));
-        goto error;
+        goto cleanup;
     }
 
     for (i = 0; i < n; i++) {
         if (virDomainIOThreadSchedParse(nodes[i], def) < 0)
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
     if ((n = virXPathNodeSet("./cputune/cachetune", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("cannot extract cachetune nodes"));
-        goto error;
+        goto cleanup;
     }
 
     for (i = 0; i < n; i++) {
         if (virDomainCachetuneDefParse(def, ctxt, nodes[i], flags) < 0)
-            goto error;
+            goto cleanup;
     }
     VIR_FREE(nodes);
 
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    return ret;
+}
+
+
+static virDomainDefPtr
+virDomainDefParseXML(xmlDocPtr xml,
+                     xmlNodePtr root,
+                     xmlXPathContextPtr ctxt,
+                     virCapsPtr caps,
+                     virDomainXMLOptionPtr xmlopt,
+                     void *parseOpaque,
+                     unsigned int flags)
+{
+    typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params);
+
+    xmlNodePtr *nodes = NULL, node = NULL;
+    char *tmp = NULL;
+    size_t i, j;
+    int n, gic_version;
+    size_t fun_index = 0;
+    virDomainDefPtr def;
+    bool uuid_generated = false;
+    virHashTablePtr bootHash = NULL;
+    bool usb_none = false;
+    bool usb_other = false;
+    bool usb_master = false;
+    char *netprefix = NULL;
+    virDomainParseTotalParam param = {
+            NULL,
+            xml,
+            root,
+            ctxt,
+            caps,
+            xmlopt,
+            parseOpaque,
+            flags,
+            false,
+            false,
+            false,
+            false
+
+    };
+
+    virDomainPreaseInfoFunc parse_funs[] = {
+            virDomainDefParseIdInfo,
+            virDomainDefParseVirtTypeInfo,
+            virDomainDefParseOsNodeInfo,
+            virDomainDefParseDomainInfo,
+            virDomainDefParseSecurityLabelInfo,
+            virDomainDefParseMemoryInfo,
+            virDomainDefParseBikiotuneInfo,
+            virDomainDefParseVcpuInfo,
+            virDomainDefParseIoThreadInfo,
+            virDomainDefParseCputuneInfo,
+            NULL
+    };
+
+    if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) {
+        char *schema = virFileFindResource("domain.rng",
+                                           abs_topsrcdir "/docs/schemas",
+                                           PKGDATADIR "/schemas");
+        if (!schema)
+            return NULL;
+        if (virXMLValidateAgainstSchema(schema, xml) < 0) {
+            VIR_FREE(schema);
+            return NULL;
+        }
+        VIR_FREE(schema);
+    }
+
+    if (!(def = virDomainDefNew()))
+        return NULL;
+
+    param.def = def;
+
+    while (parse_funs[fun_index]) {
+        if (parse_funs[fun_index](&param) < 0)
+            goto error;
+        fun_index++;
+    }
+
     if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu) < 0)
         goto error;
 
-- 
2.8.3





More information about the libvir-list mailing list