[PATCH v2 01/15] virnuma: Move virNumaNodesetToCPUset() our of WITH_NUMACTL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reviewed-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 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.39.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux