virDomainVcpuPinDefFree(def->cputune.emulatorpin);
- VIR_FREE(def->numatune.memory.nodemask);
+ virBitmapFree(def->numatune.memory.nodemask);
virSysinfoDefFree(def->sysinfo);
nodeset = virXMLPropString(cur, "nodeset");
if (nodeset) {
- char *set = nodeset;
- int nodemasklen = VIR_DOMAIN_CPUMASK_LEN;
-
- if (VIR_ALLOC_N(def->numatune.memory.nodemask,
- nodemasklen) < 0) {
- virReportOOMError();
- goto error;
- }
-
- /* "nodeset" uses the same syntax as "cpuset". */
- if (virDomainCpuSetParse(set, 0,
- def->numatune.memory.nodemask,
- nodemasklen) < 0) {
+ if (virBitmapParse(nodeset,
+ 0,
+ &def->numatune.memory.nodemask,
+ VIR_DOMAIN_CPUMASK_LEN) < 0) {
VIR_FREE(nodeset);
goto error;
}
/* Ignore 'nodeset' if 'placement' is 'auto' finally */
if (placement_mode == VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_AUTO)
- VIR_FREE(def->numatune.memory.nodemask);
+ virBitmapFree(def->numatune.memory.nodemask);
/* Copy 'placement' of <numatune> to <vcpu> if its 'placement'
* is not specified and 'placement' of <numatune> is specified.
if (def->numatune.memory.placement_mode ==
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC) {
- nodemask = virDomainCpuSetFormat(def->numatune.memory.nodemask,
- VIR_DOMAIN_CPUMASK_LEN);
+ nodemask = virBitmapFormat(def->numatune.memory.nodemask);
if (nodemask == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to format nodeset for "
typedef virDomainNumatuneDef *virDomainNumatuneDefPtr;
struct _virDomainNumatuneDef {
struct {
- char *nodemask;
+ virBitmapPtr nodemask;
int mode;
int placement_mode; /* enum virDomainNumatuneMemPlacementMode */
} memory;
/* Convert nodemask to NUMA bitmask. */
nodemask_zero(&mask);
- for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
- if (ctrl->def->numatune.memory.nodemask[i]) {
- if (i > NUMA_NUM_NODES) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Host cannot support NUMA node %d"), i);
- return -1;
- }
- if (i > maxnode && !warned) {
- VIR_WARN("nodeset is out of range, there is only %d NUMA "
- "nodes on host", maxnode);
- warned = true;
- }
- nodemask_set(&mask, i);
+ i = -1;
+ while ((i = virBitmapNextSetBit(ctrl->def->numatune.memory.nodemask, i)) >= 0) {
+ if (i > NUMA_NUM_NODES) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Host cannot support NUMA node %d"), i);
+ return -1;
+ }
+ if (i > maxnode && !warned) {
+ VIR_WARN("nodeset is out of range, there is only %d NUMA "
+ "nodes on host", maxnode);
+ warned = true;
}
+ nodemask_set(&mask, i);
}
mode = ctrl->def->numatune.memory.mode;
if (old->numatune.memory.mode != new->numatune.memory.mode ||
old->numatune.memory.placement_mode != new->numatune.memory.placement_mode ||
- !STREQ_NULLABLE(old->numatune.memory.nodemask, new->numatune.memory.nodemask)) {
+ !virBitmapEqual(old->numatune.memory.nodemask, new->numatune.memory.nodemask)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("numa parameters are not supported "
int qemuSetupCgroup(struct qemud_driver *driver,
virDomainObjPtr vm,
- char *nodemask)
+ virBitmapPtr nodemask)
{
virCgroupPtr cgroup = NULL;
int rc;
char *mask = NULL;
if (vm->def->numatune.memory.placement_mode ==
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_AUTO)
- mask = virDomainCpuSetFormat(nodemask, VIR_DOMAIN_CPUMASK_LEN);
+ mask = virBitmapFormat(nodemask);
else
- mask = virDomainCpuSetFormat(vm->def->numatune.memory.nodemask,
- VIR_DOMAIN_CPUMASK_LEN);
+ mask = virBitmapFormat(vm->def->numatune.memory.nodemask);
if (!mask) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to convert memory nodemask"));
void *opaque);
int qemuSetupCgroup(struct qemud_driver *driver,
virDomainObjPtr vm,
- char *nodemask);
+ virBitmapPtr nodemask);
int qemuSetupCgroupVcpuBW(virCgroupPtr cgroup,
unsigned long long period,
long long quota);
}
} else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) {
int rc;
- char *nodeset = NULL;
+ virBitmapPtr nodeset = NULL;
char *nodeset_str = NULL;
- if (VIR_ALLOC_N(nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) {
- virReportOOMError();
- ret = -1;
- goto cleanup;
- };
-
- if (virDomainCpuSetParse(params[i].value.s,
- 0, nodeset,
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
+ if (virBitmapParse(params[i].value.s,
+ 0, &nodeset,
+ VIR_DOMAIN_CPUMASK_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to parse nodeset"));
ret = -1;
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("change of nodeset for running domain "
"requires strict numa mode"));
- VIR_FREE(nodeset);
+ virBitmapFree(nodeset);
ret = -1;
continue;
}
/* Ensure the cpuset string is formated before passing to cgroup */
- if (!(nodeset_str = virDomainCpuSetFormat(nodeset,
- VIR_DOMAIN_CPUMASK_LEN))) {
+ if (!(nodeset_str = virBitmapFormat(nodeset))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to format nodeset"));
- VIR_FREE(nodeset);
+ virBitmapFree(nodeset);
ret = -1;
continue;
}
if ((rc = virCgroupSetCpusetMems(group, nodeset_str) != 0)) {
virReportSystemError(-rc, "%s",
_("unable to set numa tunable"));
- VIR_FREE(nodeset);
+ virBitmapFree(nodeset);
VIR_FREE(nodeset_str);
ret = -1;
continue;
/* update vm->def here so that dumpxml can read the new
* values from vm->def. */
- if (!vm->def->numatune.memory.nodemask) {
- if (VIR_ALLOC_N(vm->def->numatune.memory.nodemask,
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
- virReportOOMError();
- VIR_FREE(nodeset);
- ret = -1;
- goto cleanup;
- }
- } else {
- VIR_FREE(vm->def->numatune.memory.nodemask);
- }
+ virBitmapFree(vm->def->numatune.memory.nodemask);
- vm->def->numatune.memory.nodemask = nodeset;
vm->def->numatune.memory.placement_mode =
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC;
+ vm->def->numatune.memory.nodemask = virBitmapNewCopy(nodeset);
}
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- if (!persistentDef->numatune.memory.nodemask) {
- if (VIR_ALLOC_N(persistentDef->numatune.memory.nodemask,
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
- virReportOOMError();
- VIR_FREE(nodeset);
- ret = -1;
- goto cleanup;
- }
- } else {
- VIR_FREE(persistentDef->numatune.memory.nodemask);
- }
+ virBitmapFree(persistentDef->numatune.memory.nodemask);
persistentDef->numatune.memory.nodemask = nodeset;
persistentDef->numatune.memory.placement_mode =
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC;
+ nodeset = NULL;
}
+ virBitmapFree(nodeset);
}
}
case 1: /* fill numa nodeset here */
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- char *mask = persistentDef->numatune.memory.nodemask;
- if (mask)
- nodeset = virDomainCpuSetFormat(mask,
- VIR_DOMAIN_CPUMASK_LEN);
- else
+ nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask);
+ if (!nodeset)
nodeset = strdup("");
} else {
rc = virCgroupGetCpusetMems(group, &nodeset);
#include "uuid.h"
#include "virtime.h"
#include "virnetdevtap.h"
+#include "bitmap.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
#if HAVE_NUMACTL
static int
qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm,
- const char *nodemask)
+ virBitmapPtr nodemask)
{
nodemask_t mask;
int mode = -1;
int maxnode = 0;
bool warned = false;
virDomainNumatuneDef numatune = vm->def->numatune;
- const char *tmp_nodemask = NULL;
+ virBitmapPtr tmp_nodemask = NULL;
if (numatune.memory.placement_mode ==
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC) {
maxnode = numa_max_node() + 1;
/* Convert nodemask to NUMA bitmask. */
nodemask_zero(&mask);
- for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
- if (tmp_nodemask[i]) {
- if (i > NUMA_NUM_NODES) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Host cannot support NUMA node %d"), i);
- return -1;
- }
- if (i > maxnode && !warned) {
- VIR_WARN("nodeset is out of range, there is only %d NUMA "
- "nodes on host", maxnode);
- warned = true;
- }
- nodemask_set(&mask, i);
+ i = -1;
+ while ((i = virBitmapNextSetBit(tmp_nodemask, i)) >= 0) {
+ if (i > NUMA_NUM_NODES) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Host cannot support NUMA node %d"), i);
+ return -1;
}
+ if (i > maxnode && !warned) {
+ VIR_WARN("nodeset is out of range, there is only %d NUMA "
+ "nodes on host", maxnode);
+ warned = true;
+ }
+ nodemask_set(&mask, i);
}
mode = numatune.memory.mode;
static int
qemuProcessInitCpuAffinity(struct qemud_driver *driver,
virDomainObjPtr vm,
- const char *nodemask)
+ virBitmapPtr nodemask)
{
int ret = -1;
int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
for (i = 0; i < driver->caps->host.nnumaCell; i++) {
int j;
int cur_ncpus = driver->caps->host.numaCell[i]->ncpus;
- if (nodemask[i]) {
+ bool result;
+ if (virBitmapGetBit(nodemask, i, &result) < 0)
+ goto cleanup;
+ if (result) {
for (j = 0; j < cur_ncpus; j++)
ignore_value(virBitmapSetBit(cpumap,
driver->caps->host.numaCell[i]->cpus[j]));
virConnectPtr conn;
virDomainObjPtr vm;
struct qemud_driver *driver;
- char *nodemask;
+ virBitmapPtr nodemask;
};
static int qemuProcessHook(void *data)
unsigned long cur_balloon;
int i;
char *nodeset = NULL;
- char *nodemask = NULL;
+ virBitmapPtr nodemask = NULL;
unsigned int stop_flags;
/* Okay, these are just internal flags,
VIR_DEBUG("Nodeset returned from numad: %s", nodeset);
- if (VIR_ALLOC_N(nodemask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
- virReportOOMError();
- goto cleanup;
- }
-
- if (virDomainCpuSetParse(nodeset, 0, nodemask,
- VIR_DOMAIN_CPUMASK_LEN) < 0)
+ if (virBitmapParse(nodeset, 0, &nodemask,
+ VIR_DOMAIN_CPUMASK_LEN) < 0)
goto cleanup;
}
hookData.nodemask = nodemask;
* if we failed to initialize the now running VM. kill it off and
* pretend we never started it */
VIR_FREE(nodeset);
- VIR_FREE(nodemask);
+ virBitmapFree(nodemask);
virCommandFree(cmd);
VIR_FORCE_CLOSE(logfile);
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, stop_flags);