[libvirt] [PATCH] numatune: finish the split from domain_conf and remove all dependencies

Martin Kletzander mkletzan at redhat.com
Tue Jul 22 04:21:25 UTC 2014


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 at redhat.com>
---
 src/conf/domain_conf.c   |  9 +++++-
 src/conf/domain_conf.h   |  2 ++
 src/conf/numatune_conf.c | 78 +++++++++++++++++++++++++-----------------------
 src/conf/numatune_conf.h | 23 +++++++-------
 src/lxc/lxc_native.c     |  8 +++--
 src/qemu/qemu_driver.c   | 10 +++++--
 6 files changed, 75 insertions(+), 55 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1e27165..9f20a3a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11809,9 +11809,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"));
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cd3293b..1429568 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1853,6 +1853,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;
diff --git a/src/conf/numatune_conf.c b/src/conf/numatune_conf.c
index 82418aa..48d1d04 100644
--- a/src/conf/numatune_conf.c
+++ b/src/conf/numatune_conf.c
@@ -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;

diff --git a/src/conf/numatune_conf.h b/src/conf/numatune_conf.h
index c86118f..5254629 100644
--- a/src/conf/numatune_conf.h
+++ b/src/conf/numatune_conf.h
@@ -30,15 +30,6 @@
 # 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);

 /*
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 2fbc262..d32cb27 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -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;
         }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1782913..b49dd2e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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)
-- 
2.0.1




More information about the libvir-list mailing list