char *res = NULL;
int ncpus;
int nb_vcpu;
- char *cpulist = NULL;
+ virBitmapPtr cpulist = NULL;
unsigned char *cpumap = NULL;
size_t cpumaplen;
int nb = 0;
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return NULL;
- if (VIR_ALLOC_N(cpulist, priv->nbNodeCpus) < 0) {
+ if (!(cpulist = virBitmapNew(priv->nbNodeCpus))) {
virReportOOMError();
goto done;
}
cpumap, cpumaplen)) >= 0) {
for (n = 0 ; n < ncpus ; n++) {
for (m = 0 ; m < priv->nbNodeCpus; m++) {
- if ((cpulist[m] == 0) &&
+ bool used;
+ ignore_value(virBitmapGetBit(cpulist, m, &used));
+ if ((!used) &&
(VIR_CPU_USABLE(cpumap, cpumaplen, n, m))) {
- cpulist[m] = 1;
+ ignore_value(virBitmapSetBit(cpulist, m));
nb++;
/* if all CPU are used just return NULL */
if (nb == priv->nbNodeCpus)
}
}
}
- res = virDomainCpuSetFormat(cpulist, priv->nbNodeCpus);
+ res = virBitmapFormat(cpulist);
}
done:
- VIR_FREE(cpulist);
+ virBitmapFree(cpulist);
VIR_FREE(cpumap);
VIR_FREE(cpuinfo);
return res;
{
const char *nodeToCpu;
const char *cur;
- char *cpuset = NULL;
+ virBitmapPtr cpuset = NULL;
int *cpuNums = NULL;
int cell, cpu, nb_cpus;
int n = 0;
numCpus = sexpr_int(root, "node/nr_cpus");
- if (VIR_ALLOC_N(cpuset, numCpus) < 0)
- goto memory_error;
if (VIR_ALLOC_N(cpuNums, numCpus) < 0)
goto memory_error;
virSkipSpacesAndBackslash(&cur);
if (STRPREFIX(cur, "no cpus")) {
nb_cpus = 0;
- for (cpu = 0; cpu < numCpus; cpu++)
- cpuset[cpu] = 0;
+ if (!(cpuset = virBitmapNew(numCpus)))
+ goto memory_error;
} else {
- nb_cpus = virDomainCpuSetParse(cur, 'n', cpuset, numCpus);
+ nb_cpus = virBitmapParse(cur, 'n', &cpuset, numCpus);
if (nb_cpus < 0)
goto error;
}
- for (n = 0, cpu = 0; cpu < numCpus; cpu++)
- if (cpuset[cpu] == 1)
+ for (n = 0, cpu = 0; cpu < numCpus; cpu++) {
+ bool used;
+
+ ignore_value(virBitmapGetBit(cpuset, cpu, &used));
+ if (used)
cpuNums[n++] = cpu;
+ }
if (virCapabilitiesAddHostNUMACell(caps,
cell,
goto memory_error;
}
VIR_FREE(cpuNums);
- VIR_FREE(cpuset);
+ virBitmapFree(cpuset);
return 0;
parse_error:
virReportError(VIR_ERR_XEN_CALL, "%s", _("topology syntax error"));
error:
VIR_FREE(cpuNums);
- VIR_FREE(cpuset);
+ virBitmapFree(cpuset);
return -1;
memory_error:
VIR_FREE(cpuNums);
- VIR_FREE(cpuset);
+ virBitmapFree(cpuset);
virReportOOMError();
return -1;
}