build: fix NUMA build on RHEL 5

Use NUMA's older nodemask_t (fixed-size map) rather than the newer
'struct bitmask' (variable-size) in order to still compile on RHEL 5,
with its numactl-devel-0.9.8.

* src/qemu/qemu_process.c [HAVE_NUMA]: Prefer back-compat mode.
(qemuProcessInitNumaMemoryPolicy): Use older nodemask_t.
This commit is contained in:
Eric Blake 2011-06-23 21:53:08 -06:00
parent b46832971c
commit 98d83094a0

View File

@ -40,6 +40,7 @@
#include "qemu_bridge_filter.h" #include "qemu_bridge_filter.h"
#if HAVE_NUMACTL #if HAVE_NUMACTL
# define NUMA_VERSION1_COMPATIBILITY 1
# include <numa.h> # include <numa.h>
#endif #endif
@ -1279,7 +1280,7 @@ qemuProcessDetectVcpuPIDs(struct qemud_driver *driver,
static int static int
qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm) qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
{ {
struct bitmask *mask = NULL; nodemask_t mask;
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
virErrorPtr err = NULL; virErrorPtr err = NULL;
int mode = -1; int mode = -1;
@ -1287,6 +1288,7 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
int ret = -1; int ret = -1;
int i = 0; int i = 0;
int maxnode = 0; int maxnode = 0;
bool warned = false;
if (!vm->def->numatune.memory.nodemask) if (!vm->def->numatune.memory.nodemask)
return 0; return 0;
@ -1299,47 +1301,23 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
return -1; return -1;
} }
if (VIR_ALLOC(mask) < 0) {
virReportOOMError();
return -1;
}
mask->size = VIR_DOMAIN_CPUMASK_LEN / sizeof (unsigned long);
if (VIR_ALLOC_N(mask->maskp, mask->size) < 0) {
virReportOOMError();
goto cleanup;
}
/* Convert nodemask to NUMA bitmask. */
for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
int cur = 0;
int mod = 0;
if (i) {
cur = i / (8 * sizeof (unsigned long));
mod = i % (8 * sizeof (unsigned long));
}
if (vm->def->numatune.memory.nodemask[i]) {
mask->maskp[cur] |= 1 << mod;
}
}
maxnode = numa_max_node() + 1; maxnode = numa_max_node() + 1;
for (i = 0; i < mask->size; i++) { /* Convert nodemask to NUMA bitmask. */
if (i < (maxnode % (8 * sizeof (unsigned long)))) { nodemask_zero(&mask);
if (mask->maskp[i] & ~maxnode) { for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
if (vm->def->numatune.memory.nodemask[i]) {
if (i > NUMA_NUM_NODES) {
qemuReportError(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 " VIR_WARN("nodeset is out of range, there is only %d NUMA "
"nodes on host", maxnode); "nodes on host", maxnode);
break; warned = true;
} }
nodemask_set(&mask, i);
continue;
}
if (mask->maskp[i]) {
VIR_WARN("nodeset is out of range, there is only %d NUMA nodes "
"on host", maxnode);
} }
} }
@ -1348,7 +1326,7 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
if (mode == VIR_DOMAIN_NUMATUNE_MEM_STRICT) { if (mode == VIR_DOMAIN_NUMATUNE_MEM_STRICT) {
numa_set_bind_policy(1); numa_set_bind_policy(1);
numa_set_membind(mask); numa_set_membind(&mask);
numa_set_bind_policy(0); numa_set_bind_policy(0);
err = virGetLastError(); err = virGetLastError();
@ -1362,8 +1340,8 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
} }
} else if (mode == VIR_DOMAIN_NUMATUNE_MEM_PREFERRED) { } else if (mode == VIR_DOMAIN_NUMATUNE_MEM_PREFERRED) {
int nnodes = 0; int nnodes = 0;
for (i = 0; i < mask->size; i++) { for (i = 0; i < NUMA_NUM_NODES; i++) {
if (numa_bitmask_isbitset(mask, i)) { if (nodemask_isset(&mask, i)) {
node = i; node = i;
nnodes++; nnodes++;
} }
@ -1389,7 +1367,7 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
goto cleanup; goto cleanup;
} }
} else if (mode == VIR_DOMAIN_NUMATUNE_MEM_INTERLEAVE) { } else if (mode == VIR_DOMAIN_NUMATUNE_MEM_INTERLEAVE) {
numa_set_interleave_mask(mask); numa_set_interleave_mask(&mask);
err = virGetLastError(); err = virGetLastError();
if ((err && (err->code != orig_err->code)) || if ((err && (err->code != orig_err->code)) ||
@ -1412,7 +1390,6 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm)
ret = 0; ret = 0;
cleanup: cleanup:
numa_bitmask_free(mask);
return ret; return ret;
} }
#else #else