From 93f8e4f797fe8480148328a3cc1dfcb40f16a49e Mon Sep 17 00:00:00 2001 Message-Id: <93f8e4f797fe8480148328a3cc1dfcb40f16a49e@dist-git> From: Michal Privoznik Date: Wed, 8 Mar 2023 10:10:00 +0100 Subject: [PATCH] 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 Reviewed-by: Kristina Hanicova Reviewed-by: Andrea Bolognani (cherry picked from commit 01e5111c3cfee2358961c47f9edaa1eb421d2e03) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2185039 Signed-off-by: Michal Privoznik --- src/util/virnuma.c | 115 +++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 62 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 43e299f4bb..dae0827c65 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -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; +} -- 2.40.0