numatune: finish the split from domain_conf and remove all dependencies

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>
This commit is contained in:
Martin Kletzander 2014-07-21 11:32:33 +02:00
parent 6675a0ab65
commit dc8b7ce7bc
6 changed files with 75 additions and 55 deletions

View 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; goto error;
if (virDomainNumatuneHasPlacementAuto(def->numatune) && !def->cpumask)
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO;
if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) { if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract resource nodes")); "%s", _("cannot extract resource nodes"));

View File

@ -1809,6 +1809,8 @@ struct _virDomainResourceDef {
* NB: if adding to this struct, virDomainDefCheckABIStability * NB: if adding to this struct, virDomainDefCheckABIStability
* may well need an update * may well need an update
*/ */
typedef struct _virDomainDef virDomainDef;
typedef virDomainDef *virDomainDefPtr;
struct _virDomainDef { struct _virDomainDef {
int virtType; int virtType;
int id; int id;

View File

@ -76,13 +76,15 @@ virDomainNumatuneNodeSpecified(virDomainNumatunePtr numatune,
} }
static int static int
virDomainNumatuneNodeParseXML(virDomainDefPtr def, virDomainNumatuneNodeParseXML(virDomainNumatunePtr *numatunePtr,
size_t ncells,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
char *tmp = NULL; char *tmp = NULL;
int n = 0;; int n = 0;;
int ret = -1; int ret = -1;
size_t i = 0; size_t i = 0;
virDomainNumatunePtr numatune = *numatunePtr;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
if ((n = virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) { if ((n = virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) {
@ -94,29 +96,31 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
if (!n) if (!n)
return 0; return 0;
if (def->numatune && def->numatune->memory.specified && if (numatune && numatune->memory.specified &&
def->numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) { numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Per-node binding is not compatible with " _("Per-node binding is not compatible with "
"automatic NUMA placement.")); "automatic NUMA placement."));
goto cleanup; goto cleanup;
} }
if (!def->cpu || !def->cpu->ncells) { if (!ncells) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Element 'memnode' is invalid without " _("Element 'memnode' is invalid without "
"any guest NUMA cells")); "any guest NUMA cells"));
goto cleanup; goto cleanup;
} }
if (!def->numatune && VIR_ALLOC(def->numatune) < 0) if (!numatune && VIR_ALLOC(numatune) < 0)
goto cleanup; goto cleanup;
VIR_FREE(def->numatune->mem_nodes); *numatunePtr = numatune;
if (VIR_ALLOC_N(def->numatune->mem_nodes, def->cpu->ncells) < 0)
VIR_FREE(numatune->mem_nodes);
if (VIR_ALLOC_N(numatune->mem_nodes, ncells) < 0)
goto cleanup; goto cleanup;
def->numatune->nmem_nodes = def->cpu->ncells; numatune->nmem_nodes = ncells;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int mode = 0; int mode = 0;
@ -139,14 +143,14 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
} }
VIR_FREE(tmp); VIR_FREE(tmp);
if (cellid >= def->numatune->nmem_nodes) { if (cellid >= numatune->nmem_nodes) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Argument 'cellid' in memnode element must " _("Argument 'cellid' in memnode element must "
"correspond to existing guest's NUMA cell")); "correspond to existing guest's NUMA cell"));
goto cleanup; goto cleanup;
} }
mem_node = &def->numatune->mem_nodes[cellid]; mem_node = &numatune->mem_nodes[cellid];
if (mem_node->nodeset) { if (mem_node->nodeset) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
@ -189,7 +193,9 @@ virDomainNumatuneNodeParseXML(virDomainDefPtr def,
} }
int int
virDomainNumatuneParseXML(virDomainDefPtr def, virDomainNumatuneParseXML(virDomainNumatunePtr *numatunePtr,
bool placement_static,
size_t ncells,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
char *tmp = NULL; char *tmp = NULL;
@ -212,23 +218,25 @@ virDomainNumatuneParseXML(virDomainDefPtr def,
node = virXPathNode("./numatune/memory[1]", ctxt); node = virXPathNode("./numatune/memory[1]", ctxt);
if (def->numatune) { if (*numatunePtr) {
virDomainNumatuneFree(def->numatune); virDomainNumatuneFree(*numatunePtr);
def->numatune = NULL; *numatunePtr = NULL;
} }
if (!node && def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { if (!node && placement_static) {
if (virDomainNumatuneNodeParseXML(def, ctxt) < 0) if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
goto cleanup; goto cleanup;
return 0; return 0;
} }
if (!node) { if (!node) {
/* We know that def->placement_mode is "auto" if we're here */ /* We know that placement_mode is "auto" if we're here */
if (virDomainNumatuneSet(def, VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO, ret = virDomainNumatuneSet(numatunePtr,
-1, NULL) < 0) placement_static,
goto cleanup; VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO,
return 0; -1,
NULL);
goto cleanup;
} }
tmp = virXMLPropString(node, "mode"); tmp = virXMLPropString(node, "mode");
@ -260,13 +268,16 @@ virDomainNumatuneParseXML(virDomainDefPtr def,
goto cleanup; goto cleanup;
VIR_FREE(tmp); VIR_FREE(tmp);
if (virDomainNumatuneSet(def, placement, mode, nodeset) < 0) if (virDomainNumatuneSet(numatunePtr,
placement_static,
placement,
mode,
nodeset) < 0)
goto cleanup; goto cleanup;
if (virDomainNumatuneNodeParseXML(def, ctxt) < 0) if (virDomainNumatuneNodeParseXML(numatunePtr, ncells, ctxt) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
virBitmapFree(nodeset); virBitmapFree(nodeset);
@ -420,12 +431,13 @@ virDomainNumatuneMaybeFormatNodeset(virDomainNumatunePtr numatune,
} }
int int
virDomainNumatuneSet(virDomainDefPtr def, virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
bool placement_static,
int placement, int placement,
int mode, int mode,
virBitmapPtr nodeset) virBitmapPtr nodeset)
{ {
bool create = !def->numatune; /* Whether we are creating new struct */ bool create = !*numatunePtr; /* Whether we are creating new struct */
int ret = -1; int ret = -1;
virDomainNumatunePtr numatune = NULL; virDomainNumatunePtr numatune = NULL;
@ -449,9 +461,9 @@ virDomainNumatuneSet(virDomainDefPtr def,
goto cleanup; goto cleanup;
} }
if (create && VIR_ALLOC(def->numatune) < 0) if (create && VIR_ALLOC(*numatunePtr) < 0)
goto cleanup; goto cleanup;
numatune = def->numatune; numatune = *numatunePtr;
if (create) { if (create) {
/* Defaults for new struct */ /* Defaults for new struct */
@ -474,8 +486,7 @@ virDomainNumatuneSet(virDomainDefPtr def,
} }
if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) { if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) {
if (numatune->memory.nodeset || if (numatune->memory.nodeset || placement_static)
def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC)
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC; placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC;
else else
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO; placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
@ -489,13 +500,6 @@ virDomainNumatuneSet(virDomainDefPtr def,
goto cleanup; 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) if (placement != -1)
numatune->memory.placement = placement; numatune->memory.placement = placement;

View File

@ -30,15 +30,6 @@
# include "virbitmap.h" # include "virbitmap.h"
# include "virbuffer.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 struct _virDomainNumatune virDomainNumatune;
typedef virDomainNumatune *virDomainNumatunePtr; typedef virDomainNumatune *virDomainNumatunePtr;
@ -60,8 +51,11 @@ void virDomainNumatuneFree(virDomainNumatunePtr numatune);
/* /*
* XML Parse/Format functions * XML Parse/Format functions
*/ */
int virDomainNumatuneParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt) int virDomainNumatuneParseXML(virDomainNumatunePtr *numatunePtr,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); bool placement_static,
size_t ncells,
xmlXPathContextPtr ctxt)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
int virDomainNumatuneFormatXML(virBufferPtr buf, virDomainNumatunePtr numatune) int virDomainNumatuneFormatXML(virBufferPtr buf, virDomainNumatunePtr numatune)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
@ -91,8 +85,11 @@ int virDomainNumatuneMaybeFormatNodeset(virDomainNumatunePtr numatune,
/* /*
* Setters * Setters
*/ */
int virDomainNumatuneSet(virDomainDefPtr def, int placement, int virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr,
int mode, virBitmapPtr nodeset) bool placement_static,
int placement,
int mode,
virBitmapPtr nodeset)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
/* /*

View File

@ -734,8 +734,12 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
value->str) { value->str) {
if (virBitmapParse(value->str, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) if (virBitmapParse(value->str, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
return -1; return -1;
if (virDomainNumatuneSet(def, VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC, if (virDomainNumatuneSet(&def->numatune,
VIR_DOMAIN_NUMATUNE_MEM_STRICT, nodeset) < 0) { def->placement_mode ==
VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC,
VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC,
VIR_DOMAIN_NUMATUNE_MEM_STRICT,
nodeset) < 0) {
virBitmapFree(nodeset); virBitmapFree(nodeset);
return -1; return -1;
} }

View File

@ -8788,12 +8788,18 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
qemuDomainSetNumaParamsLive(vm, caps, nodeset) < 0) qemuDomainSetNumaParamsLive(vm, caps, nodeset) < 0)
goto cleanup; 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; goto cleanup;
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { 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; goto cleanup;
if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)