]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Move NUMA cell parsing code from cpu conf to numa conf
authorPeter Krempa <pkrempa@redhat.com>
Wed, 11 Feb 2015 11:27:53 +0000 (12:27 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Feb 2015 16:43:03 +0000 (17:43 +0100)
For weird historical reasons NUMA cells are added as a subelement of
<cpu> while the actual configuration is done in <numatune>.

This patch splits out the cell parser code from cpu config to NUMA
config. Note that the changes to the code are minimal just to make it
work and the function will be refactored in the next patch.

src/conf/cpu_conf.c
src/conf/domain_conf.c
src/conf/numa_conf.c
src/conf/numa_conf.h

index 4a367a1f6befaa07abf94b861faea535d1944ef3..f14b37ae190a3632035cf150905cbce8cf1474db 100644 (file)
@@ -426,96 +426,6 @@ virCPUDefParseXML(xmlNodePtr node,
         def->features[i].policy = policy;
     }
 
-    if (virXPathNode("./numa[1]", ctxt)) {
-        VIR_FREE(nodes);
-        n = virXPathNodeSet("./numa[1]/cell", ctxt, &nodes);
-        if (n <= 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("NUMA topology defined without NUMA cells"));
-            goto error;
-        }
-
-        if (VIR_RESIZE_N(def->cells, def->ncells_max,
-                         def->ncells, n) < 0)
-            goto error;
-
-        def->ncells = n;
-
-        for (i = 0; i < n; i++) {
-            char *cpus, *memAccessStr;
-            int ret, ncpus = 0;
-            unsigned int cur_cell;
-            char *tmp = NULL;
-
-            tmp = virXMLPropString(nodes[i], "id");
-            if (!tmp) {
-                cur_cell = i;
-            } else {
-                ret  = virStrToLong_ui(tmp, NULL, 10, &cur_cell);
-                if (ret == -1) {
-                    virReportError(VIR_ERR_XML_ERROR,
-                                   _("Invalid 'id' attribute in NUMA cell: %s"),
-                                   tmp);
-                    VIR_FREE(tmp);
-                    goto error;
-                }
-                VIR_FREE(tmp);
-            }
-
-            if (cur_cell >= n) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("Exactly one 'cell' element per guest "
-                                 "NUMA cell allowed, non-contiguous ranges or "
-                                 "ranges not starting from 0 are not allowed"));
-                goto error;
-            }
-
-            if (def->cells[cur_cell].cpustr) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("Duplicate NUMA cell info for cell id '%u'"),
-                               cur_cell);
-                goto error;
-            }
-
-            cpus = virXMLPropString(nodes[i], "cpus");
-            if (!cpus) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("Missing 'cpus' attribute in NUMA cell"));
-                goto error;
-            }
-            def->cells[cur_cell].cpustr = cpus;
-
-            ncpus = virBitmapParse(cpus, 0, &def->cells[cur_cell].cpumask,
-                                   VIR_DOMAIN_CPUMASK_LEN);
-            if (ncpus <= 0)
-                goto error;
-            def->cells_cpus += ncpus;
-
-            ctxt->node = nodes[i];
-            if (virDomainParseMemory("./@memory", "./@unit", ctxt,
-                                     &def->cells[cur_cell].mem, true, false) < 0)
-                goto cleanup;
-
-            memAccessStr = virXMLPropString(nodes[i], "memAccess");
-            if (memAccessStr) {
-                int rc = virMemAccessTypeFromString(memAccessStr);
-
-                if (rc <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("Invalid 'memAccess' attribute "
-                                     "value '%s'"),
-                                   memAccessStr);
-                    VIR_FREE(memAccessStr);
-                    goto error;
-                }
-
-                def->cells[cur_cell].memAccess = rc;
-
-                VIR_FREE(memAccessStr);
-            }
-        }
-    }
-
  cleanup:
     ctxt->node = oldnode;
     VIR_FREE(fallback);
index 2e352934cae003eda5a2a47e7891eaee5711397a..98549e10895beff0f3e9da300d382ab7f3301c77 100644 (file)
@@ -13495,12 +13495,17 @@ virDomainDefParseXML(xmlDocPtr xml,
             goto error;
         }
 
-        if (def->cpu->cells_cpus > def->maxvcpus) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Number of CPUs in <numa> exceeds the"
-                             " <vcpu> count"));
-            goto error;
-        }
+    }
+
+    if (virDomainNumaDefCPUParseXML(def->cpu, ctxt) < 0)
+        goto error;
+
+    if (def->cpu &&
+        def->cpu->cells_cpus > def->maxvcpus) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Number of CPUs in <numa> exceeds the"
+                         " <vcpu> count"));
+        goto error;
     }
 
     if (virDomainNumatuneParseXML(&def->numatune,
index 0bbc136e59a31e5319cb1bfe09adf39d82f4a186..b4f0fca13eeebf8a6cbd123e710f1ff1d33e84c5 100644 (file)
@@ -680,3 +680,114 @@ virDomainNumatuneNodesetIsAvailable(virDomainNumatunePtr numatune,
 
     return true;
 }
+
+
+int
+virDomainNumaDefCPUParseXML(virCPUDefPtr def,
+                            xmlXPathContextPtr ctxt)
+{
+    xmlNodePtr *nodes = NULL;
+    xmlNodePtr oldNode = ctxt->node;
+    int n;
+    size_t i;
+    int ret = -1;
+
+    if (virXPathNode("/domain/cpu/numa[1]", ctxt)) {
+        VIR_FREE(nodes);
+
+        n = virXPathNodeSet("/domain/cpu/numa[1]/cell", ctxt, &nodes);
+        if (n <= 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("NUMA topology defined without NUMA cells"));
+            goto error;
+        }
+
+        if (VIR_RESIZE_N(def->cells, def->ncells_max,
+                         def->ncells, n) < 0)
+            goto error;
+
+        def->ncells = n;
+
+        for (i = 0; i < n; i++) {
+            char *cpus, *memAccessStr;
+            int rc, ncpus = 0;
+            unsigned int cur_cell;
+            char *tmp = NULL;
+
+            tmp = virXMLPropString(nodes[i], "id");
+            if (!tmp) {
+                cur_cell = i;
+            } else {
+                rc  = virStrToLong_ui(tmp, NULL, 10, &cur_cell);
+                if (rc == -1) {
+                    virReportError(VIR_ERR_XML_ERROR,
+                                   _("Invalid 'id' attribute in NUMA cell: %s"),
+                                   tmp);
+                    VIR_FREE(tmp);
+                    goto error;
+                }
+                VIR_FREE(tmp);
+            }
+
+            if (cur_cell >= n) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Exactly one 'cell' element per guest "
+                                 "NUMA cell allowed, non-contiguous ranges or "
+                                 "ranges not starting from 0 are not allowed"));
+                goto error;
+            }
+
+            if (def->cells[cur_cell].cpustr) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("Duplicate NUMA cell info for cell id '%u'"),
+                               cur_cell);
+                goto error;
+            }
+
+            cpus = virXMLPropString(nodes[i], "cpus");
+            if (!cpus) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Missing 'cpus' attribute in NUMA cell"));
+                goto error;
+            }
+            def->cells[cur_cell].cpustr = cpus;
+
+            ncpus = virBitmapParse(cpus, 0, &def->cells[cur_cell].cpumask,
+                                   VIR_DOMAIN_CPUMASK_LEN);
+            if (ncpus <= 0)
+                goto error;
+            def->cells_cpus += ncpus;
+
+            ctxt->node = nodes[i];
+            if (virDomainParseMemory("./@memory", "./@unit", ctxt,
+                                     &def->cells[cur_cell].mem, true, false) < 0)
+                goto cleanup;
+
+            memAccessStr = virXMLPropString(nodes[i], "memAccess");
+            if (memAccessStr) {
+                rc = virMemAccessTypeFromString(memAccessStr);
+
+                if (rc <= 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("Invalid 'memAccess' attribute "
+                                     "value '%s'"),
+                                   memAccessStr);
+                    VIR_FREE(memAccessStr);
+                    goto error;
+                }
+
+                def->cells[cur_cell].memAccess = rc;
+
+                VIR_FREE(memAccessStr);
+            }
+        }
+    }
+
+    ret = 0;
+
+ error:
+ cleanup:
+    ctxt->node = oldNode;
+    VIR_FREE(nodes);
+    return ret;
+}
index 4891f15694616d3c6eec7a45d3458724ba1b9d73..78b24a1bc15e3e58afbbf8472f15050f0f0c4329 100644 (file)
@@ -29,6 +29,7 @@
 # include "virutil.h"
 # include "virbitmap.h"
 # include "virbuffer.h"
+# include "cpu_conf.h"
 
 
 typedef struct _virDomainNumatune virDomainNumatune;
@@ -114,4 +115,7 @@ bool virDomainNumatuneNodesetIsAvailable(virDomainNumatunePtr numatune,
 
 bool virDomainNumatuneNodeSpecified(virDomainNumatunePtr numatune,
                                     int cellid);
+
+int virDomainNumaDefCPUParseXML(virCPUDefPtr def, xmlXPathContextPtr ctxt);
+
 #endif /* __NUMA_CONF_H__ */