render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
e8e641
From 93f8e4f797fe8480148328a3cc1dfcb40f16a49e Mon Sep 17 00:00:00 2001
e8e641
Message-Id: <93f8e4f797fe8480148328a3cc1dfcb40f16a49e@dist-git>
e8e641
From: Michal Privoznik <mprivozn@redhat.com>
e8e641
Date: Wed, 8 Mar 2023 10:10:00 +0100
e8e641
Subject: [PATCH] virnuma: Move virNumaNodesetToCPUset() out of WITH_NUMACTL
e8e641
e8e641
Technically, there's nothing libnuma specific about
e8e641
virNumaNodesetToCPUset(). It just implements a generic algorithm
e8e641
over virNumaGetNodeCPUs() (which is then libnuma dependant).
e8e641
Nevertheless, there's no need to have this function living inside
e8e641
WITH_NUMACTL block. Any error returned from virNumaGetNodeCPUs()
e8e641
(including the one that !WITH_NUMACTL stub returns) is propagated
e8e641
properly.
e8e641
e8e641
Move the function out of the block into a generic one and drop
e8e641
the !WITH_NUMACTL stub.
e8e641
e8e641
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e8e641
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
e8e641
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
e8e641
(cherry picked from commit 01e5111c3cfee2358961c47f9edaa1eb421d2e03)
e8e641
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2185039
e8e641
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
e8e641
---
e8e641
 src/util/virnuma.c | 115 +++++++++++++++++++++------------------------
e8e641
 1 file changed, 53 insertions(+), 62 deletions(-)
e8e641
e8e641
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
e8e641
index 43e299f4bb..dae0827c65 100644
e8e641
--- a/src/util/virnuma.c
e8e641
+++ b/src/util/virnuma.c
e8e641
@@ -311,57 +311,6 @@ virNumaGetNodeCPUs(int node,
e8e641
 # undef MASK_CPU_ISSET
e8e641
 # undef n_bits
e8e641
 
e8e641
-/**
e8e641
- * virNumaNodesetToCPUset:
e8e641
- * @nodeset: bitmap containing a set of NUMA nodes
e8e641
- * @cpuset: return location for a bitmap containing a set of CPUs
e8e641
- *
e8e641
- * Convert a set of NUMA node to the set of CPUs they contain.
e8e641
- *
e8e641
- * Returns 0 on success, <0 on failure.
e8e641
- */
e8e641
-int
e8e641
-virNumaNodesetToCPUset(virBitmap *nodeset,
e8e641
-                       virBitmap **cpuset)
e8e641
-{
e8e641
-    g_autoptr(virBitmap) allNodesCPUs = NULL;
e8e641
-    size_t nodesetSize;
e8e641
-    size_t i;
e8e641
-
e8e641
-    *cpuset = NULL;
e8e641
-
e8e641
-    if (!nodeset)
e8e641
-        return 0;
e8e641
-
e8e641
-    allNodesCPUs = virBitmapNew(0);
e8e641
-    nodesetSize = virBitmapSize(nodeset);
e8e641
-
e8e641
-    for (i = 0; i < nodesetSize; i++) {
e8e641
-        g_autoptr(virBitmap) nodeCPUs = NULL;
e8e641
-        int rc;
e8e641
-
e8e641
-        if (!virBitmapIsBitSet(nodeset, i))
e8e641
-            continue;
e8e641
-
e8e641
-        rc = virNumaGetNodeCPUs(i, &nodeCPUs);
e8e641
-        if (rc < 0) {
e8e641
-            /* Error is reported for cases other than non-existent NUMA node. */
e8e641
-            if (rc == -2) {
e8e641
-                virReportError(VIR_ERR_OPERATION_FAILED,
e8e641
-                               _("NUMA node %zu is not available"),
e8e641
-                               i);
e8e641
-            }
e8e641
-            return -1;
e8e641
-        }
e8e641
-
e8e641
-        virBitmapUnion(allNodesCPUs, nodeCPUs);
e8e641
-    }
e8e641
-
e8e641
-    *cpuset = g_steal_pointer(&allNodesCPUs);
e8e641
-
e8e641
-    return 0;
e8e641
-}
e8e641
-
e8e641
 #else /* !WITH_NUMACTL */
e8e641
 
e8e641
 int
e8e641
@@ -417,17 +366,6 @@ virNumaGetNodeCPUs(int node G_GNUC_UNUSED,
e8e641
     return -1;
e8e641
 }
e8e641
 
e8e641
-int
e8e641
-virNumaNodesetToCPUset(virBitmap *nodeset G_GNUC_UNUSED,
e8e641
-                       virBitmap **cpuset)
e8e641
-{
e8e641
-    *cpuset = NULL;
e8e641
-
e8e641
-    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
e8e641
-                   _("NUMA isn't available on this host"));
e8e641
-    return -1;
e8e641
-}
e8e641
-
e8e641
 #endif /* !WITH_NUMACTL */
e8e641
 
e8e641
 /**
e8e641
@@ -1050,3 +988,56 @@ virNumaGetHostMemoryNodeset(void)
e8e641
 
e8e641
     return nodeset;
e8e641
 }
e8e641
+
e8e641
+
e8e641
+/**
e8e641
+ * virNumaNodesetToCPUset:
e8e641
+ * @nodeset: bitmap containing a set of NUMA nodes
e8e641
+ * @cpuset: return location for a bitmap containing a set of CPUs
e8e641
+ *
e8e641
+ * Convert a set of NUMA node to the set of CPUs they contain.
e8e641
+ *
e8e641
+ * Returns 0 on success,
e8e641
+ *         -1 on failure (with error reported).
e8e641
+ */
e8e641
+int
e8e641
+virNumaNodesetToCPUset(virBitmap *nodeset,
e8e641
+                       virBitmap **cpuset)
e8e641
+{
e8e641
+    g_autoptr(virBitmap) allNodesCPUs = NULL;
e8e641
+    size_t nodesetSize;
e8e641
+    size_t i;
e8e641
+
e8e641
+    *cpuset = NULL;
e8e641
+
e8e641
+    if (!nodeset)
e8e641
+        return 0;
e8e641
+
e8e641
+    allNodesCPUs = virBitmapNew(0);
e8e641
+    nodesetSize = virBitmapSize(nodeset);
e8e641
+
e8e641
+    for (i = 0; i < nodesetSize; i++) {
e8e641
+        g_autoptr(virBitmap) nodeCPUs = NULL;
e8e641
+        int rc;
e8e641
+
e8e641
+        if (!virBitmapIsBitSet(nodeset, i))
e8e641
+            continue;
e8e641
+
e8e641
+        rc = virNumaGetNodeCPUs(i, &nodeCPUs);
e8e641
+        if (rc < 0) {
e8e641
+            /* Error is reported for cases other than non-existent NUMA node. */
e8e641
+            if (rc == -2) {
e8e641
+                virReportError(VIR_ERR_OPERATION_FAILED,
e8e641
+                               _("NUMA node %zu is not available"),
e8e641
+                               i);
e8e641
+            }
e8e641
+            return -1;
e8e641
+        }
e8e641
+
e8e641
+        virBitmapUnion(allNodesCPUs, nodeCPUs);
e8e641
+    }
e8e641
+
e8e641
+    *cpuset = g_steal_pointer(&allNodesCPUs);
e8e641
+
e8e641
+    return 0;
e8e641
+}
e8e641
-- 
e8e641
2.40.0