[PATCH 3/3] nodeinfo: Fix nodeGetCPUBitmap()'s fallback code path

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

 



During the recent refactoring/cleanups, a bug has been introduced
that caused all CPUs to be reported as online unless the sysfs
cpu/present file was available.

This commit fixes the fallback code path by building the directory
path passed to virNodeGetCpuValue() correctly.
---
 src/nodeinfo.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index c874fa6..105d7ab 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1300,6 +1300,7 @@ nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
 #ifdef __linux__
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     char *online_path = NULL;
+    char *cpudir = NULL;
     virBitmapPtr cpumap;
     int present;
 
@@ -1317,8 +1318,12 @@ nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
         cpumap = virBitmapNew(present);
         if (!cpumap)
             goto cleanup;
+
+        if (virAsprintf(&cpudir, "%s/cpu", prefix) < 0)
+            goto cleanup;
+
         for (i = 0; i < present; i++) {
-            int online = virNodeGetCpuValue(prefix, i, "online", 1);
+            int online = virNodeGetCpuValue(cpudir, i, "online", 1);
             if (online < 0) {
                 virBitmapFree(cpumap);
                 cpumap = NULL;
@@ -1332,6 +1337,7 @@ nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
         *max_id = present;
  cleanup:
     VIR_FREE(online_path);
+    VIR_FREE(cpudir);
     return cpumap;
 #else
     virReportError(VIR_ERR_NO_SUPPORT, "%s",
-- 
2.4.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]