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_XML_ERROR,
+ "%s", _("topology cpuset syntax error"));
goto error;
+ }
VIR_FREE(tmp);
}
}
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
const char *type = NULL;
- int n, allones = 1;
+ int n;
int i;
bool blkio = false;
" </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);
unsigned short vcpus;
unsigned short maxvcpus;
int placement_mode;
- int cpumasklen;
- char *cpumask;
+ virBitmapPtr cpumask;
struct {
unsigned long shares;
*/
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");
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
* 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) {
virBitmapFree(cpumap);
return -1;
}
return -1;
}
- if (old->cpumasklen != new->cpumasklen ||
- (memcmp(old->cpumask, new->cpumask, old->cpumasklen))) {
+ if (!virBitmapEqual(old->cpumask, new->cpumask)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("changing cpu mask is not supported "
int ret = -1;
int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
virNodeInfo nodeinfo;
- virBitmapPtr cpumap;
+ virBitmapPtr cpumap, cpumapToSet;
VIR_DEBUG("Setting CPU affinity");
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 */
} 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
* 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)
goto cleanup;
ret = 0;
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);
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;
}
int unit;
bool hgfs_disabled = true;
long long sharedFolder_maxNum = 0;
+ int cpumasklen;
if (ctx->parseFileName == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
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 = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN);
+ if (!def->cpumask) {
virReportOOMError();
goto cleanup;
}
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);
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]) {
- ++sched_cpu_affinity_length;
- }
+ i = -1;
+ while ((i = virBitmapNextSetBit(def->cpumask, i)) >= 0) {
+ ++sched_cpu_affinity_length;
}
if (sched_cpu_affinity_length < def->maxvcpus) {
goto cleanup;
}
- for (i = 0; i < def->cpumasklen; ++i) {
- if (def->cpumask[i]) {
- virBufferAsprintf(&buffer, "%d", i);
-
- if (sched_cpu_affinity_length > 1) {
- virBufferAddChar(&buffer, ',');
- }
+ i = -1;
+ while ((i = virBitmapNextSetBit(def->cpumask, i)) >= 0) {
+ virBufferAsprintf(&buffer, "%d", i);
- --sched_cpu_affinity_length;
+ if (sched_cpu_affinity_length > 1) {
+ virBufferAddChar(&buffer, ',');
}
+
+ --sched_cpu_affinity_length;
}
virBufferAddLit(&buffer, "\"\n");
char *mapstr = NULL, *mapsave = NULL;
int i, j, n, comma = 0;
int ret = -1;
- char *cpuset = NULL;
+ virBitmapPtr cpuset = NULL;
int maxcpu = XEN_MAX_PHYSICAL_CPU;
if (domain == NULL || domain->conn == NULL || domain->name == NULL
mapstr = virBufferContentAndReset(&mapbuf);
mapsave = mapstr;
- if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- if (virDomainCpuSetParse(mapstr, 0, cpuset, maxcpu) < 0)
+ if (virBitmapParse(mapstr, 0, &cpuset, maxcpu) < 0)
goto cleanup;
- VIR_FREE(entry->def->cpumask);
+ virBitmapFree(entry->def->cpumask);
entry->def->cpumask = cpuset;
- entry->def->cpumasklen = maxcpu;
cpuset = NULL;
if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0)
def->mem.cur_balloon = def->mem.max_balloon;
if (cpus != NULL) {
- def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
- if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) {
- virReportOOMError();
- goto error;
- }
-
- if (virDomainCpuSetParse(cpus, 0, def->cpumask,
- def->cpumasklen) < 0) {
+ if (virBitmapParse(cpus, 0, &def->cpumask,
+ VIR_DOMAIN_CPUMASK_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid CPU mask %s"), cpus);
goto error;
virBufferAsprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);
if (def->cpumask) {
- char *ranges = virDomainCpuSetFormat(def->cpumask, def->cpumasklen);
+ char *ranges = virBitmapFormat(def->cpumask);
if (ranges == NULL)
goto error;
virBufferEscapeSexpr(&buf, "(cpus '%s')", ranges);
if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0)
goto cleanup;
- if (str) {
- def->cpumasklen = 4096;
- if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0)
- goto no_memory;
-
- if (virDomainCpuSetParse(str, 0,
- def->cpumask, def->cpumasklen) < 0)
+ if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0))
goto cleanup;
- }
-
if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0)
goto cleanup;
goto no_memory;
if ((def->cpumask != NULL) &&
- ((cpus = virDomainCpuSetFormat(def->cpumask,
- def->cpumasklen)) == NULL))
+ ((cpus = virBitmapFormat(def->cpumask)) == NULL)) {
goto cleanup;
+ }
if (cpus &&
xenXMConfigSetString(conf, "cpus", cpus) < 0)
$abs_top_builddir/tools/virsh --connect test:///default define xml-invalid > out 2>&1 && fail=1
cat <<\EOF > exp || fail=1
error: Failed to define domain from xml-invalid
-error: internal error topology cpuset syntax error
+error: XML error: topology cpuset syntax error
EOF
compare exp out || fail=1