[PATCHv3 1/4] nodeinfo: enable nodeGetCPUCount for older kernels

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

 



Since /sys/devices/system/cpu/present is not available on
older kernels like on RHEL 5.x nodeGetCPUCount will
fail there. The fallback implemented is to scan for
/sys/devices/system/cpu/cpuNN entries.

Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx>
---
 src/nodeinfo.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index e3d7cfe..cea3775 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -978,11 +978,34 @@ int
 nodeGetCPUCount(void)
 {
 #ifdef __linux__
-    /* XXX should we also work on older kernels, like RHEL5, that lack
-     * cpu/present and cpu/online files?  Those kernels also lack cpu
-     * hotplugging, so it would be a matter of finding the largest
-     * cpu/cpuNN directory, and returning NN + 1 */
-    return linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
+    /* to support older kernels, like RHEL5, that lack
+     * cpu/present we fall back to count cpu/cpuNN
+     * entries.
+     */
+    char *cpupath = NULL;
+    int i = 0;
+
+    if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) {
+        i = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
+    } else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) {
+        do {
+            i++;
+            VIR_FREE(cpupath);
+            if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
+                            SYSFS_SYSTEM_PATH, i) < 0) {
+                virReportOOMError();
+                return -1;
+            }
+        } while (virFileExists(cpupath));
+    } else {
+        /* no cpu/cpu0: we give up */
+        virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                       _("host cpu counting not supported on this node"));
+        return -1;
+    }
+
+    VIR_FREE(cpupath);
+    return i;
 #else
     virReportError(VIR_ERR_NO_SUPPORT, "%s",
                    _("host cpu counting not implemented on this platform"));
-- 
1.7.12.4

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