virnuma: Move virNumaNodesetToCPUset() out of WITH_NUMACTL

Technically, there's nothing libnuma specific about
virNumaNodesetToCPUset(). It just implements a generic algorithm
over virNumaGetNodeCPUs() (which is then libnuma dependant).
Nevertheless, there's no need to have this function living inside
WITH_NUMACTL block. Any error returned from virNumaGetNodeCPUs()
(including the one that !WITH_NUMACTL stub returns) is propagated
properly.

Move the function out of the block into a generic one and drop
the !WITH_NUMACTL stub.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Michal Privoznik 2023-03-08 10:10:00 +01:00
parent 42d53ac799
commit 01e5111c3c

View File

@ -311,57 +311,6 @@ virNumaGetNodeCPUs(int node,
# undef MASK_CPU_ISSET
# undef n_bits
/**
* virNumaNodesetToCPUset:
* @nodeset: bitmap containing a set of NUMA nodes
* @cpuset: return location for a bitmap containing a set of CPUs
*
* Convert a set of NUMA node to the set of CPUs they contain.
*
* Returns 0 on success, <0 on failure.
*/
int
virNumaNodesetToCPUset(virBitmap *nodeset,
virBitmap **cpuset)
{
g_autoptr(virBitmap) allNodesCPUs = NULL;
size_t nodesetSize;
size_t i;
*cpuset = NULL;
if (!nodeset)
return 0;
allNodesCPUs = virBitmapNew(0);
nodesetSize = virBitmapSize(nodeset);
for (i = 0; i < nodesetSize; i++) {
g_autoptr(virBitmap) nodeCPUs = NULL;
int rc;
if (!virBitmapIsBitSet(nodeset, i))
continue;
rc = virNumaGetNodeCPUs(i, &nodeCPUs);
if (rc < 0) {
/* Error is reported for cases other than non-existent NUMA node. */
if (rc == -2) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("NUMA node %zu is not available"),
i);
}
return -1;
}
virBitmapUnion(allNodesCPUs, nodeCPUs);
}
*cpuset = g_steal_pointer(&allNodesCPUs);
return 0;
}
#else /* !WITH_NUMACTL */
int
@ -417,17 +366,6 @@ virNumaGetNodeCPUs(int node G_GNUC_UNUSED,
return -1;
}
int
virNumaNodesetToCPUset(virBitmap *nodeset G_GNUC_UNUSED,
virBitmap **cpuset)
{
*cpuset = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("NUMA isn't available on this host"));
return -1;
}
#endif /* !WITH_NUMACTL */
/**
@ -1050,3 +988,56 @@ virNumaGetHostMemoryNodeset(void)
return nodeset;
}
/**
* virNumaNodesetToCPUset:
* @nodeset: bitmap containing a set of NUMA nodes
* @cpuset: return location for a bitmap containing a set of CPUs
*
* Convert a set of NUMA node to the set of CPUs they contain.
*
* Returns 0 on success,
* -1 on failure (with error reported).
*/
int
virNumaNodesetToCPUset(virBitmap *nodeset,
virBitmap **cpuset)
{
g_autoptr(virBitmap) allNodesCPUs = NULL;
size_t nodesetSize;
size_t i;
*cpuset = NULL;
if (!nodeset)
return 0;
allNodesCPUs = virBitmapNew(0);
nodesetSize = virBitmapSize(nodeset);
for (i = 0; i < nodesetSize; i++) {
g_autoptr(virBitmap) nodeCPUs = NULL;
int rc;
if (!virBitmapIsBitSet(nodeset, i))
continue;
rc = virNumaGetNodeCPUs(i, &nodeCPUs);
if (rc < 0) {
/* Error is reported for cases other than non-existent NUMA node. */
if (rc == -2) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("NUMA node %zu is not available"),
i);
}
return -1;
}
virBitmapUnion(allNodesCPUs, nodeCPUs);
}
*cpuset = g_steal_pointer(&allNodesCPUs);
return 0;
}