]> xenbits.xensource.com Git - libvirt.git/commitdiff
numatune: finish the split from domain_conf and remove all dependencies
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 21 Jul 2014 09:32:33 +0000 (11:32 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Thu, 24 Jul 2014 06:40:25 +0000 (08:40 +0200)
This patch adds back the virDomainDef typedef into domain_conf and
makes all the numatune_conf functions independent of any virDomainDef
definitions.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/numatune_conf.c
src/conf/numatune_conf.h
src/lxc/lxc_native.c
src/qemu/qemu_driver.c

index 56589eef34c8831de27147c8cac8713f5a65e92f..577a971dded1f601fcbea622a71146f6a7dbd836 100644 (file)
@@ -11800,9 +11800,16 @@ virDomainDefParseXML(xmlDocPtr xml,
         }
     }
 
-    if (virDomainNumatuneParseXML(def, ctxt) < 0)
+    if (virDomainNumatuneParseXML(&def->numatune,
+                                  def->placement_mode ==
+                                  VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
+                                  def->cpu ? def->cpu->ncells : 0,
+                                  ctxt) < 0)
         goto error;
 
+    if (virDomainNumatuneHasPlacementAuto(def->numatune) && !def->cpumask)
+        def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO;
+
     if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("cannot extract resource nodes"));
index d79ef9b2d422446c462df5e13af8281725d78b95..2a7a55ac9aabc1133e089a90d0a7c6da14fb4ace 100644 (file)
@@ -1809,6 +1809,8 @@ struct _virDomainResourceDef {
  * NB: if adding to this struct, virDomainDefCheckABIStability
  * may well need an update
  */
+typedef struct _virDomainDef virDomainDef;
+typedef virDomainDef *virDomainDefPtr;
 struct _virDomainDef {
     int virtType;
     int id;
index 82418aae9c9b50fb19a1178db27cd1909eb068df..48d1d04fe68dced383d9e0c7ab0b08613870f028 100644 (file)
@@ -76,13 +76,15 @@ virDomainNumatuneNodeSpecified(virDomainNumatunePtr numatune,
 }
 
 static int
-virDomainNumatuneNodeParseXML(virDomainDefPtr def,
+virDomainNumatuneNodeParseXML(virDomainNumatunePtr *numatunePtr,
+                              size_t ncells,
                               xmlXPathContextPtr ctxt)
 {
     char *tmp = NULL;
     int n = 0;;
     int ret = -1;
     size_t i = 0;
+    virDomainNumatunePtr numatune = *numatunePtr;
     xmlNodePtr *nodes = NULL;
 
     if ((n = virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) {
@@ -94,29 +96,31 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
     if (!n)
         return 0;
 
-    if (def->numatune && def->numatune->memory.specified &&
-        def->numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) {
+    if (numatune && numatune->memory.specified &&
+        numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Per-node binding is not compatible with "
                          "automatic NUMA placement."));
         goto cleanup;
     }
 
-    if (!def->cpu || !def->cpu->ncells) {
+    if (!ncells) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("Element 'memnode' is invalid without "
                          "any guest NUMA cells"));
         goto cleanup;
     }
 
-    if (!def->numatune && VIR_ALLOC(def->numatune) < 0)
+    if (!numatune && VIR_ALLOC(numatune) < 0)
         goto cleanup;
 
-    VIR_FREE(def->numatune->mem_nodes);
-    if (VIR_ALLOC_N(def->numatune->mem_nodes, def->cpu->ncells) < 0)
+    *numatunePtr = numatune;
+
+    VIR_FREE(numatune->mem_nodes);
+    if (VIR_ALLOC_N(numatune->mem_nodes, ncells) < 0)
         goto cleanup;
 
-    def->numatune->nmem_nodes = def->cpu->ncells;
+    numatune->nmem_nodes = ncells;
 
     for (i = 0; i < n; i++) {
         int mode = 0;
@@ -139,14 +143,14 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
         }
         VIR_FREE(tmp);
 
-        if (cellid >= def->numatune->nmem_nodes) {
+        if (cellid >= numatune->nmem_nodes) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("Argument 'cellid' in memnode element must "
                              "correspond to existing guest's NUMA cell"));
             goto cleanup;
         }
 
-        mem_node = &def->numatune->mem_nodes[cellid];
+        mem_node = &numatune->mem_nodes[cellid];
 
         if (mem_node->nodeset) {
             virReportError(VIR_ERR_XML_ERROR,
@@ -189,7 +193,9 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
 }
 
 int
-virDomainNumatuneParseXML(virDomainDefPtr def,
+virDomainNumatuneParseXML(virDomainNumatunePtr *numatunePtr,
+                          bool placement_static,
+                          size_t ncells,
                           xmlXPathContextPtr ctxt)
 {
     char *tmp = NULL;
@@ -212,23 +218,25 @@ virDomainNumatuneParseXML(virDomainDefPtr def,
 
     node = virXPathNode("./numatune/memory[1]", ctxt);
 
-    if (def->numatune) {
-        virDomainNumatuneFree(def->numatune);
-        def->numatune = NULL;
+    if (*numatunePtr) {
+        virDomainNumatuneFree(*numatunePtr);
+        *numatunePtr = NULL;
     }
 
-    if (!node && def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
-        if (virDomainNumatuneNodeParseXML(def, ctxt) < 0)
+    if (!node && placement_static) {
+        if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
             goto cleanup;
         return 0;
     }
 
     if (!node) {
-        /* We know that def->placement_mode is "auto" if we're here */
-        if (virDomainNumatuneSet(def, VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO,
-                                 -1, NULL) < 0)
-            goto cleanup;
-        return 0;
+        /* We know that placement_mode is "auto" if we're here */
+        ret = virDomainNumatuneSet(numatunePtr,
+                                   placement_static,
+                                   VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO,
+                                   -1,
+                                   NULL);
+        goto cleanup;
     }
 
     tmp = virXMLPropString(node, "mode");
@@ -260,13 +268,16 @@ virDomainNumatuneParseXML(virDomainDefPtr def,
         goto cleanup;
     VIR_FREE(tmp);
 
-    if (virDomainNumatuneSet(def, placement, mode, nodeset) < 0)
+    if (virDomainNumatuneSet(numatunePtr,
+                             placement_static,
+                             placement,
+                             mode,
+                             nodeset) < 0)
         goto cleanup;
 
-    if (virDomainNumatuneNodeParseXML(def, ctxt) < 0)
+    if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
         goto cleanup;
 
-
     ret = 0;
  cleanup:
     virBitmapFree(nodeset);
@@ -420,12 +431,13 @@ virDomainNumatuneMaybeFormatNodeset(virDomainNumatunePtr numatune,
 }
 
 int
-virDomainNumatuneSet(virDomainDefPtr def,
+virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
+                     bool placement_static,
                      int placement,
                      int mode,
                      virBitmapPtr nodeset)
 {
-    bool create = !def->numatune;  /* Whether we are creating new struct */
+    bool create = !*numatunePtr;  /* Whether we are creating new struct */
     int ret = -1;
     virDomainNumatunePtr numatune = NULL;
 
@@ -449,9 +461,9 @@ virDomainNumatuneSet(virDomainDefPtr def,
         goto cleanup;
     }
 
-    if (create && VIR_ALLOC(def->numatune) < 0)
+    if (create && VIR_ALLOC(*numatunePtr) < 0)
         goto cleanup;
-    numatune = def->numatune;
+    numatune = *numatunePtr;
 
     if (create) {
         /* Defaults for new struct */
@@ -474,8 +486,7 @@ virDomainNumatuneSet(virDomainDefPtr def,
     }
 
     if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) {
-        if (numatune->memory.nodeset ||
-            def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC)
+        if (numatune->memory.nodeset || placement_static)
             placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC;
         else
             placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
@@ -489,13 +500,6 @@ virDomainNumatuneSet(virDomainDefPtr def,
         goto cleanup;
     }
 
-    if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) {
-        virBitmapFree(numatune->memory.nodeset);
-        numatune->memory.nodeset = NULL;
-        if (!def->cpumask)
-            def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO;
-    }
-
     if (placement != -1)
         numatune->memory.placement = placement;
 
index c86118f9e688ffa2ee69ba82add6aa8b2f02e7e0..5254629b53dd53e5db7278df8cd03cf3a82234c4 100644 (file)
 # include "virbitmap.h"
 # include "virbuffer.h"
 
-/*
- * Since numatune configuration is closely bound to the whole config,
- * and because we don't have separate domain_conf headers for
- * typedefs, structs and functions, we need to have a forward
- * declaration here for virDomainDef due to circular dependencies.
- */
-typedef struct _virDomainDef virDomainDef;
-typedef virDomainDef *virDomainDefPtr;
-
 
 typedef struct _virDomainNumatune virDomainNumatune;
 typedef virDomainNumatune *virDomainNumatunePtr;
@@ -60,8 +51,11 @@ void virDomainNumatuneFree(virDomainNumatunePtr numatune);
 /*
  * XML Parse/Format functions
  */
-int virDomainNumatuneParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int virDomainNumatuneParseXML(virDomainNumatunePtr *numatunePtr,
+                              bool placement_static,
+                              size_t ncells,
+                              xmlXPathContextPtr ctxt)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
 
 int virDomainNumatuneFormatXML(virBufferPtr buf, virDomainNumatunePtr numatune)
     ATTRIBUTE_NONNULL(1);
@@ -91,8 +85,11 @@ int virDomainNumatuneMaybeFormatNodeset(virDomainNumatunePtr numatune,
 /*
  * Setters
  */
-int virDomainNumatuneSet(virDomainDefPtr def, int placement,
-                         int mode, virBitmapPtr nodeset)
+int virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
+                         bool placement_static,
+                         int placement,
+                         int mode,
+                         virBitmapPtr nodeset)
     ATTRIBUTE_NONNULL(1);
 
 /*
index d3fde07cd26b260379c9bc73ec079552afed27a9..41e069f10d64cbf42f8e1fe6d6ac6ff461103335 100644 (file)
@@ -734,8 +734,12 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
         value->str) {
         if (virBitmapParse(value->str, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
             return -1;
-        if (virDomainNumatuneSet(def, VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC,
-                                 VIR_DOMAIN_NUMATUNE_MEM_STRICT, nodeset) < 0) {
+        if (virDomainNumatuneSet(&def->numatune,
+                                 def->placement_mode ==
+                                 VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
+                                 VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC,
+                                 VIR_DOMAIN_NUMATUNE_MEM_STRICT,
+                                 nodeset) < 0) {
             virBitmapFree(nodeset);
             return -1;
         }
index 26db4e92258b33030f13e173dae9bb945626b8cf..539164fea3e059656e092f9ab5a552237fc95b26 100644 (file)
@@ -8788,12 +8788,18 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
             qemuDomainSetNumaParamsLive(vm, caps, nodeset) < 0)
             goto cleanup;
 
-        if (virDomainNumatuneSet(vm->def, -1, mode, nodeset) < 0)
+        if (virDomainNumatuneSet(&vm->def->numatune,
+                                 vm->def->placement_mode ==
+                                 VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
+                                 -1, mode, nodeset) < 0)
             goto cleanup;
     }
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        if (virDomainNumatuneSet(persistentDef, -1, mode, nodeset) < 0)
+        if (virDomainNumatuneSet(&persistentDef->numatune,
+                                 persistentDef->placement_mode ==
+                                 VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
+                                 -1, mode, nodeset) < 0)
             goto cleanup;
 
         if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)