Blame SOURCES/libvirt-nodeinfo-Add-old-kernel-compatibility-to-nodeGetPresentCPUBitmap.patch

7a3408
From 77f24a2e6276d06d1da1f6d9223b5b15e6ab04ac Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <77f24a2e6276d06d1da1f6d9223b5b15e6ab04ac@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Wed, 5 Aug 2015 18:18:25 +0200
7a3408
Subject: [PATCH] nodeinfo: Add old kernel compatibility to
7a3408
 nodeGetPresentCPUBitmap()
7a3408
7a3408
If the cpu/present file is not available, we assume that the kernel
7a3408
is too old to support non-consecutive CPU ids and return a bitmap
7a3408
with all the bits set to represent this fact. This assumption is
7a3408
already exploited in nodeGetCPUCount().
7a3408
7a3408
This means users of this API can expect the information to always
7a3408
be available unless an error has occurred, and no longer need to
7a3408
treat the NULL return value as a special case.
7a3408
7a3408
The error message has been updated as well.
7a3408
7a3408
(cherry picked from commit 37f73e4ad5b049edbd92951330db2c071ca93b87)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1213713
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/nodeinfo.c | 43 +++++++++++++++++++++++++++++--------------
7a3408
 1 file changed, 29 insertions(+), 14 deletions(-)
7a3408
7a3408
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
7a3408
index a7a5d98..ceb517a 100644
7a3408
--- a/src/nodeinfo.c
7a3408
+++ b/src/nodeinfo.c
7a3408
@@ -441,6 +441,8 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
     }
7a3408
 
7a3408
     present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix);
7a3408
+    if (!present_cpumap)
7a3408
+        goto cleanup;
7a3408
 
7a3408
     /* enumerate sockets in the node */
7a3408
     CPU_ZERO(&sock_map);
7a3408
@@ -448,7 +450,7 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
7a3408
             continue;
7a3408
 
7a3408
-        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
7a3408
+        if (!virBitmapIsBitSet(present_cpumap, cpu))
7a3408
             continue;
7a3408
 
7a3408
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
7a3408
@@ -484,7 +486,7 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
7a3408
             continue;
7a3408
 
7a3408
-        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
7a3408
+        if (!virBitmapIsBitSet(present_cpumap, cpu))
7a3408
             continue;
7a3408
 
7a3408
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
7a3408
@@ -1284,27 +1286,40 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
7a3408
 }
7a3408
 
7a3408
 virBitmapPtr
7a3408
-nodeGetPresentCPUBitmap(const char *sysfs_prefix)
7a3408
+nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
7a3408
 {
7a3408
-    int max_present;
7a3408
 #ifdef __linux__
7a3408
+    virBitmapPtr present_cpus = NULL;
7a3408
     char *present_path = NULL;
7a3408
-    virBitmapPtr bitmap = NULL;
7a3408
-#endif
7a3408
+    int npresent_cpus;
7a3408
 
7a3408
-    if ((max_present = nodeGetCPUCount(sysfs_prefix)) < 0)
7a3408
-        return NULL;
7a3408
+    if ((npresent_cpus = nodeGetCPUCount(sysfs_prefix)) < 0)
7a3408
+        goto cleanup;
7a3408
 
7a3408
-#ifdef __linux__
7a3408
     if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix)))
7a3408
-        return NULL;
7a3408
-    if (virFileExists(present_path))
7a3408
-        bitmap = linuxParseCPUmap(max_present, present_path);
7a3408
+        goto cleanup;
7a3408
+
7a3408
+    /* If the cpu/present file is available, parse it and exit */
7a3408
+    if (virFileExists(present_path)) {
7a3408
+        present_cpus = linuxParseCPUmap(npresent_cpus, present_path);
7a3408
+        goto cleanup;
7a3408
+    }
7a3408
+
7a3408
+    /* If the file is not available, we can assume that the kernel is
7a3408
+     * too old to support non-consecutive CPU ids and just mark all
7a3408
+     * possible CPUs as present */
7a3408
+    if (!(present_cpus = virBitmapNew(npresent_cpus)))
7a3408
+        goto cleanup;
7a3408
+
7a3408
+    virBitmapSetAll(present_cpus);
7a3408
+
7a3408
+ cleanup:
7a3408
     VIR_FREE(present_path);
7a3408
-    return bitmap;
7a3408
+
7a3408
+    return present_cpus;
7a3408
 #endif
7a3408
     virReportError(VIR_ERR_NO_SUPPORT, "%s",
7a3408
-                   _("non-continuous host cpu numbers not implemented on this platform"));
7a3408
+                   _("node present CPU map not implemented on this platform"));
7a3408
     return NULL;
7a3408
 }
7a3408
 
7a3408
-- 
7a3408
2.5.0
7a3408