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

[libvirt] [PATCH v2] virsh: Fix to list online cpus using virsh capabilities



Virsh capabilities will list offline cpus as online when
libvirt is compiled with numactl option disabled. This
fix will list correct set of online cpus.
---
 src/nodeinfo.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 22df95c..410c9de 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1651,6 +1651,47 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
     if (VIR_ALLOC_N(cpus, ncpus) < 0)
         return -1;
 
+#ifdef __linux__
+    {
+    int cid = 0;
+    int onlinecpus = nodeinfo.cpus;
+
+    id = 0;
+    for (s = 0; s < nodeinfo.sockets; s++) {
+        for (c = 0; c < nodeinfo.cores; c++) {
+            for (t = 0; t < nodeinfo.threads; t++) {
+                if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) {
+                    cpus[cid].id = id;
+                    cpus[cid].socket_id = s;
+                    cpus[cid].core_id = c;
+                    if (!(cpus[cid].siblings = virBitmapNew(ncpus)))
+                        goto error;
+                    ignore_value(virBitmapSetBit(cpus[cid].siblings, id));
+                    cid++;
+                }
+
+                id++;
+            }
+        }
+    }
+
+    if (virCapabilitiesAddHostNUMACell(caps, 0,
+                                       nodeinfo.memory,
+                                       onlinecpus, cpus,
+                                       0, NULL,
+                                       0, NULL) < 0)
+        goto error;
+
+    return 0;
+
+ error:
+    for (; cid >= 0; cid--)
+        virBitmapFree(cpus[cid].siblings);
+    VIR_FREE(cpus);
+    return -1;
+    }
+#else
+    {
     id = 0;
     for (s = 0; s < nodeinfo.sockets; s++) {
         for (c = 0; c < nodeinfo.cores; c++) {
@@ -1680,6 +1721,8 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
         virBitmapFree(cpus[id].siblings);
     VIR_FREE(cpus);
     return -1;
+    }
+#endif
 }
 
 static int


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