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

[libvirt] [PATCH] 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.

Signed-off-by: Kothapally Madhu Pavan <kmp linux vnet ibm com>
---
 src/nodeinfo.c |   36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 22df95c..602c76c 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1639,28 +1639,38 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
 {
     virNodeInfo nodeinfo;
     virCapsHostNUMACellCPUPtr cpus;
-    int ncpus;
+    int ncpus, onlinecpus;
     int s, c, t;
-    int id;
+    int id, cid;
+    char *sysfs_cpudir = NULL;
 
     if (nodeGetInfo(&nodeinfo) < 0)
         return -1;
 
     ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    onlinecpus = nodeinfo.cpus;
+
+    if (VIR_ALLOC_N(cpus, onlinecpus) < 0)
+        return -1;
 
-    if (VIR_ALLOC_N(cpus, ncpus) < 0)
+    if (virAsprintf(&sysfs_cpudir, SYSFS_CPU_PATH) < 0)
         return -1;
 
     id = 0;
+    cid = 0;
     for (s = 0; s < nodeinfo.sockets; s++) {
         for (c = 0; c < nodeinfo.cores; c++) {
             for (t = 0; t < nodeinfo.threads; t++) {
-                cpus[id].id = id;
-                cpus[id].socket_id = s;
-                cpus[id].core_id = c;
-                if (!(cpus[id].siblings = virBitmapNew(ncpus)))
-                    goto error;
-                ignore_value(virBitmapSetBit(cpus[id].siblings, id));
+                if (virNodeGetCpuValue(sysfs_cpudir, id, "online", 0)) {
+                    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++;
             }
         }
@@ -1668,17 +1678,19 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
 
     if (virCapabilitiesAddHostNUMACell(caps, 0,
                                        nodeinfo.memory,
-                                       ncpus, cpus,
+                                       onlinecpus, cpus,
                                        0, NULL,
                                        0, NULL) < 0)
         goto error;
 
+    VIR_FREE(sysfs_cpudir);
     return 0;
 
  error:
-    for (; id >= 0; id--)
-        virBitmapFree(cpus[id].siblings);
+    for (; cid >= 0; cid--)
+        virBitmapFree(cpus[cid].siblings);
     VIR_FREE(cpus);
+    VIR_FREE(sysfs_cpudir);
     return -1;
 }
 


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