---
src/conf/domain_conf.c | 24 +++++++++---------------
src/conf/domain_conf.h | 3 +--
src/lxc/lxc_controller.c | 14 ++++++--------
src/parallels/parallels_driver.c | 3 +--
src/qemu/qemu_process.c | 10 ++++------
src/test/test_driver.c | 5 ++++-
src/vmx/vmx.c | 28 ++++++++++++++++++----------
7 files changed, 43 insertions(+), 44 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index be4c9db..117e83b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8303,14 +8303,12 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt);
if (tmp) {
- char *set = tmp;
- def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
- if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) {
- goto no_memory;
- }
- if (virDomainCpuSetParse(set, 0, def->cpumask,
- def->cpumasklen) < 0)
+ if (virBitmapParse(tmp, 0, &def->cpumask,
+ VIR_DOMAIN_CPUMASK_LEN) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("topology cpuset syntax
error"));
goto error;
+ }
VIR_FREE(tmp);
}
}
@@ -12894,7 +12892,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
const char *type = NULL;
- int n, allones = 1;
+ int n;
int i;
bool blkio = false;
@@ -13023,17 +13021,13 @@ virDomainDefFormatInternal(virDomainDefPtr def,
" </memoryBacking>\n", NULL);
}
- for (n = 0 ; n < def->cpumasklen ; n++)
- if (def->cpumask[n] != 1)
- allones = 0;
-
virBufferAddLit(buf, " <vcpu");
virBufferAsprintf(buf, " placement='%s'",
virDomainCpuPlacementModeTypeToString(def->placement_mode));
- if (!allones) {
+
+ if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) {
char *cpumask = NULL;
- if ((cpumask =
- virDomainCpuSetFormat(def->cpumask, def->cpumasklen)) == NULL)
+ if ((cpumask = virBitmapFormat(def->cpumask)) == NULL)
goto cleanup;
virBufferAsprintf(buf, " cpuset='%s'", cpumask);
VIR_FREE(cpumask);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7fb1c82..524345e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1599,8 +1599,7 @@ struct _virDomainDef {
unsigned short vcpus;
unsigned short maxvcpus;
int placement_mode;
- int cpumasklen;
- char *cpumask;
+ virBitmapPtr cpumask;
struct {
unsigned long shares;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 4b0ceb8..b2fcabe 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -494,9 +494,9 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
*/
static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
{
- int i, hostcpus, maxcpu = CPU_SETSIZE;
+ int hostcpus, maxcpu = CPU_SETSIZE;
virNodeInfo nodeinfo;
- virBitmapPtr cpumap;
+ virBitmapPtr cpumap, cpumapToSet;
VIR_DEBUG("Setting CPU affinity");
@@ -513,12 +513,10 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr
ctrl)
if (!cpumap)
return -1;
+ cpumapToSet = cpumap;
+
if (ctrl->def->cpumask) {
- /* XXX why don't we keep 'cpumask' in the libvirt cpumap
- * format to start with ?!?! */
- for (i = 0 ; i < maxcpu && i < ctrl->def->cpumasklen ; i++)
- if (ctrl->def->cpumask[i])
- ignore_value(virBitmapSetBit(cpumap, i));
+ cpumapToSet = ctrl->def->cpumask;
} else {
/* You may think this is redundant, but we can't assume libvirtd
* itself is running on all pCPUs, so we need to explicitly set
@@ -531,7 +529,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
* so use '0' to indicate our own process ID. No threads are
* running at this point
*/
- if (virProcessInfoSetAffinity(0 /* Self */, cpumap) < 0) {
+ if (virProcessInfoSetAffinity(0 /* Self */, cpumapToSet) < 0) {
VIR_FREE(cpumap);
return -1;
}
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index f6fa64a..b72e208 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1407,8 +1407,7 @@ parallelsApplyChanges(virDomainObjPtr dom, virDomainDefPtr new)
return -1;
}
- if (old->cpumasklen != new->cpumasklen ||
- (memcmp(old->cpumask, new->cpumask, old->cpumasklen))) {
+ if (!virBitmapCmp(old->cpumask, new->cpumask)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("changing cpu mask is not supported "
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 491ae77..837bfdd 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1843,7 +1843,7 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver,
int ret = -1;
int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
virNodeInfo nodeinfo;
- virBitmapPtr cpumap;
+ virBitmapPtr cpumap, cpumapToSet;
VIR_DEBUG("Setting CPU affinity");
@@ -1862,6 +1862,8 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver,
return -1;
}
+ cpumapToSet = cpumap;
+
if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
VIR_DEBUG("Set CPU affinity with advisory nodeset from numad");
/* numad returns the NUMA node list, convert it to cpumap */
@@ -1880,11 +1882,7 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver,
} else {
VIR_DEBUG("Set CPU affinity with specified cpuset");
if (vm->def->cpumask) {
- /* XXX why don't we keep 'cpumask' in the libvirt cpumap
- * format to start with ?!?! */
- for (i = 0 ; i < maxcpu && i < vm->def->cpumasklen ;
i++)
- if (vm->def->cpumask[i])
- ignore_value(virBitmapSetBit(cpumap, i));
+ cpumapToSet = vm->def->cpumask;
} else {
/* You may think this is redundant, but we can't assume libvirtd
* itself is running on all pCPUs, so we need to explicitly set
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index aa4418a..2e2fb67 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -383,6 +383,7 @@ testDomainUpdateVCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
virVcpuInfoPtr info = &privdata->vcpu_infos[vcpu];
unsigned char *cpumap = VIR_GET_CPUMAP(privdata->cpumaps, maplen, vcpu);
int j;
+ bool cpu;
memset(info, 0, sizeof(virVcpuInfo));
memset(cpumap, 0, maplen);
@@ -394,7 +395,9 @@ testDomainUpdateVCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (dom->def->cpumask) {
for (j = 0; j < maxcpu && j < VIR_DOMAIN_CPUMASK_LEN; ++j) {
- if (dom->def->cpumask[j]) {
+ if (virBitmapGetBit(dom->def->cpumask, j, &cpu) < 0)
+ return -1;
+ if (cpu) {
VIR_USE_CPU(cpumap, j);
info->cpu = j;
}
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index db22624..d78a110 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1235,6 +1235,7 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char
*vmx)
int unit;
bool hgfs_disabled = true;
long long sharedFolder_maxNum = 0;
+ int cpumasklen;
if (ctx->parseFileName == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1417,9 +1418,10 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char
*vmx)
const char *current = sched_cpu_affinity;
int number, count = 0;
- def->cpumasklen = 0;
+ cpumasklen = 0;
- if (VIR_ALLOC_N(def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
+ def->cpumask = virBitmapAlloc(VIR_DOMAIN_CPUMASK_LEN);
+ if (!def->cpumask) {
virReportOOMError();
goto cleanup;
}
@@ -1444,11 +1446,11 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char
*vmx)
goto cleanup;
}
- if (number + 1 > def->cpumasklen) {
- def->cpumasklen = number + 1;
+ if (number + 1 > cpumasklen) {
+ cpumasklen = number + 1;
}
- def->cpumask[number] = 1;
+ ignore_value(virBitmapSetBit(def->cpumask, number));
++count;
virSkipSpaces(¤t);
@@ -3165,13 +3167,16 @@ virVMXFormatConfig(virVMXContext *ctx, virCapsPtr caps,
virDomainDefPtr def,
virBufferAsprintf(&buffer, "numvcpus = \"%d\"\n",
def->maxvcpus);
/* def:cpumask -> vmx:sched.cpu.affinity */
- if (def->cpumasklen > 0) {
+ if (def->cpumask && virBitmapSize(def->cpumask) > 0) {
virBufferAddLit(&buffer, "sched.cpu.affinity = \"");
sched_cpu_affinity_length = 0;
- for (i = 0; i < def->cpumasklen; ++i) {
- if (def->cpumask[i]) {
+ for (i = 0; i < virBitmapSize(def->cpumask); ++i) {
+ bool cpu;
+ if (virBitmapGetBit(def->cpumask, i, &cpu) < 0)
+ goto cleanup;
+ if (cpu) {
++sched_cpu_affinity_length;
}
}
@@ -3184,8 +3189,11 @@ virVMXFormatConfig(virVMXContext *ctx, virCapsPtr caps,
virDomainDefPtr def,
goto cleanup;
}
- for (i = 0; i < def->cpumasklen; ++i) {
- if (def->cpumask[i]) {
+ for (i = 0; i < virBitmapSize(def->cpumask); ++i) {
+ bool cpu;
+ if (virBitmapGetBit(def->cpumask, i, &cpu) < 0)
+ goto cleanup;
+ if (cpu) {
virBufferAsprintf(&buffer, "%d", i);
if (sched_cpu_affinity_length > 1) {
--
1.7.10.2