virnuma: Don't work around numa_node_to_cpus() for non-existent nodes

In a very distant past, we came around machines that has not
continuous node IDs. This made us error out when constructing
capabilities XML. We resolved it by utilizing strange behaviour
of numa_node_to_cpus() in which it returned a mask with all bits
set for a non-existent node. However, this is not the only case
when it returns all ones mask - if the node exists and has enough
CPUs to fill the mask up (e.g. 128 CPUs).

The fix consists of using nodemask_isset(&numa_all_nodes, ..)
prior to calling numa_node_to_cpus() to determine if the node
exists.

Fixes: 628c935747
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1860231
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2020-08-21 14:43:21 +02:00
parent d4eecbf662
commit 24d7d85208

View File

@ -256,28 +256,20 @@ virNumaGetNodeCPUs(int node,
int mask_n_bytes = max_n_cpus / 8;
size_t i;
g_autofree unsigned long *mask = NULL;
g_autofree unsigned long *allonesmask = NULL;
g_autoptr(virBitmap) cpumap = NULL;
*cpus = NULL;
if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0)
return -1;
if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0)
return -1;
memset(allonesmask, 0xff, mask_n_bytes);
/* The first time this returns -1, ENOENT if node doesn't exist... */
if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) {
VIR_WARN("NUMA topology for cell %d is not available, ignoring", node);
if (!nodemask_isset(&numa_all_nodes, node)) {
VIR_DEBUG("NUMA topology for cell %d is not available, ignoring", node);
return -2;
}
/* second, third... times it returns an all-1's mask */
if (memcmp(mask, allonesmask, mask_n_bytes) == 0) {
VIR_DEBUG("NUMA topology for cell %d is invalid, ignoring", node);
if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0)
return -1;
if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) {
VIR_WARN("NUMA topology for cell %d is not available, ignoring", node);
return -2;
}