conf: numa: Always allocate the NUMA config

Since our formatter now handles well if the config is allocated and not
filled we can safely always-allocate the NUMA config and remove the
ad-hoc allocation code.

This will help in later patches as the parser will be refactored to just
fill the data.
This commit is contained in:
Peter Krempa 2015-02-16 16:42:13 +01:00
parent c03411199e
commit 21008c013c
4 changed files with 24 additions and 25 deletions

View File

@ -2319,9 +2319,17 @@ virDomainDefNew(void)
{ {
virDomainDefPtr ret; virDomainDefPtr ret;
ignore_value(VIR_ALLOC(ret)); if (VIR_ALLOC(ret) < 0)
return NULL;
if (!(ret->numa = virDomainNumaNew()))
goto error;
return ret; return ret;
error:
virDomainDefFree(ret);
return NULL;
} }

View File

@ -117,11 +117,6 @@ virDomainNumatuneNodeParseXML(virDomainNumaPtr *numatunePtr,
goto cleanup; goto cleanup;
} }
if (!numatune && VIR_ALLOC(numatune) < 0)
goto cleanup;
*numatunePtr = numatune;
VIR_FREE(numatune->mem_nodes); VIR_FREE(numatune->mem_nodes);
if (VIR_ALLOC_N(numatune->mem_nodes, ncells) < 0) if (VIR_ALLOC_N(numatune->mem_nodes, ncells) < 0)
goto cleanup; goto cleanup;
@ -224,11 +219,6 @@ virDomainNumatuneParseXML(virDomainNumaPtr *numatunePtr,
node = virXPathNode("./numatune/memory[1]", ctxt); node = virXPathNode("./numatune/memory[1]", ctxt);
if (*numatunePtr) {
virDomainNumaFree(*numatunePtr);
*numatunePtr = NULL;
}
if (!placement_static && !node) if (!placement_static && !node)
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO; placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
@ -454,27 +444,20 @@ virDomainNumatuneSet(virDomainNumaPtr *numatunePtr,
int mode, int mode,
virBitmapPtr nodeset) virBitmapPtr nodeset)
{ {
bool created = false;
int ret = -1; int ret = -1;
virDomainNumaPtr numatune; virDomainNumaPtr numatune = *numatunePtr;
/* No need to do anything in this case */ /* No need to do anything in this case */
if (mode == -1 && placement == -1 && !nodeset) if (mode == -1 && placement == -1 && !nodeset)
return 0; return 0;
if (!(*numatunePtr)) { if (!numatune->memory.specified) {
if (VIR_ALLOC(*numatunePtr) < 0)
goto cleanup;
created = true;
if (mode == -1) if (mode == -1)
mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
if (placement == -1) if (placement == -1)
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT; placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT;
} }
numatune = *numatunePtr;
/* Range checks */ /* Range checks */
if (mode != -1 && if (mode != -1 &&
(mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) { (mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) {
@ -534,11 +517,6 @@ virDomainNumatuneSet(virDomainNumaPtr *numatunePtr,
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0 && created) {
virDomainNumaFree(*numatunePtr);
*numatunePtr = NULL;
}
return ret; return ret;
} }
@ -827,3 +805,14 @@ virDomainNumaGetCPUCountTotal(virCPUDefPtr numa)
return ret; return ret;
} }
virDomainNumaPtr
virDomainNumaNew(void)
{
virDomainNumaPtr ret = NULL;
ignore_value(VIR_ALLOC(ret));
return ret;
}

View File

@ -56,6 +56,7 @@ typedef enum {
VIR_ENUM_DECL(virNumaMemAccess) VIR_ENUM_DECL(virNumaMemAccess)
virDomainNumaPtr virDomainNumaNew(void);
void virDomainNumaFree(virDomainNumaPtr numa); void virDomainNumaFree(virDomainNumaPtr numa);
/* /*

View File

@ -629,6 +629,7 @@ virNodeDeviceObjUnlock;
# conf/numa_conf.h # conf/numa_conf.h
virDomainNumaEquals; virDomainNumaEquals;
virDomainNumaFree; virDomainNumaFree;
virDomainNumaNew;
virDomainNumatuneFormatNodeset; virDomainNumatuneFormatNodeset;
virDomainNumatuneFormatXML; virDomainNumatuneFormatXML;
virDomainNumatuneGetMode; virDomainNumatuneGetMode;