render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From ecd0ade9104cecedc1e82fac2b8e025ee98e2cb4 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <ecd0ade9104cecedc1e82fac2b8e025ee98e2cb4@dist-git>
7a3408
From: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
7a3408
Date: Wed, 5 Aug 2015 18:18:15 +0200
7a3408
Subject: [PATCH] nodeinfo: fix to parse present cpus rather than possible cpus
7a3408
7a3408
This patch resolves a situation where a core is defective and is not
7a3408
in the present mask during boot. Optionally a host can have empty sockets
7a3408
could be brought online if the socket is added. In this case the present
7a3408
mask contains the cpu's that are actually there in the sockets even though
7a3408
they might be offline for some reason. This patch excludes the cpu's that
7a3408
are offline because the socket is defective/empty by checking the present
7a3408
mask before reading the cpu directory. Otherwise, the nodeinfo on such
7a3408
hosts always displays wrong output which includes the defective/empty
7a3408
sockets as set of offline cpu's.
7a3408
7a3408
Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
7a3408
(cherry picked from commit bb31f4532b285a7392911f420bcdf05a126be8a0)
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 | 23 ++++++++++++++++++-----
7a3408
 1 file changed, 18 insertions(+), 5 deletions(-)
7a3408
7a3408
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
7a3408
index ca9cb3a..5158680 100644
7a3408
--- a/src/nodeinfo.c
7a3408
+++ b/src/nodeinfo.c
7a3408
@@ -43,6 +43,7 @@
7a3408
 #include "c-ctype.h"
7a3408
 #include "viralloc.h"
7a3408
 #include "nodeinfopriv.h"
7a3408
+#include "nodeinfo.h"
7a3408
 #include "physmem.h"
7a3408
 #include "virerror.h"
7a3408
 #include "count-one-bits.h"
7a3408
@@ -403,20 +404,23 @@ CPU_COUNT(cpu_set_t *set)
7a3408
 /* parses a node entry, returning number of processors in the node and
7a3408
  * filling arguments */
7a3408
 static int
7a3408
-ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3)
7a3408
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
7a3408
 ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
7a3408
-ATTRIBUTE_NONNULL(6)
7a3408
-virNodeParseNode(const char *node,
7a3408
+ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7)
7a3408
+virNodeParseNode(const char *sysfs_prefix,
7a3408
+                 const char *node,
7a3408
                  virArch arch,
7a3408
                  int *sockets,
7a3408
                  int *cores,
7a3408
                  int *threads,
7a3408
                  int *offline)
7a3408
 {
7a3408
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
7a3408
     int ret = -1;
7a3408
     int processors = 0;
7a3408
     DIR *cpudir = NULL;
7a3408
     struct dirent *cpudirent = NULL;
7a3408
+    virBitmapPtr present_cpumap = NULL;
7a3408
     int sock_max = 0;
7a3408
     cpu_set_t sock_map;
7a3408
     int sock;
7a3408
@@ -437,12 +441,17 @@ virNodeParseNode(const char *node,
7a3408
         goto cleanup;
7a3408
     }
7a3408
 
7a3408
+    present_cpumap = nodeGetPresentCPUBitmap(prefix);
7a3408
+
7a3408
     /* enumerate sockets in the node */
7a3408
     CPU_ZERO(&sock_map);
7a3408
     while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
7a3408
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
7a3408
             continue;
7a3408
 
7a3408
+        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
7a3408
+            continue;
7a3408
+
7a3408
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
7a3408
             goto cleanup;
7a3408
 
7a3408
@@ -476,6 +485,9 @@ virNodeParseNode(const char *node,
7a3408
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
7a3408
             continue;
7a3408
 
7a3408
+        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
7a3408
+            continue;
7a3408
+
7a3408
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
7a3408
             goto cleanup;
7a3408
 
7a3408
@@ -536,6 +548,7 @@ virNodeParseNode(const char *node,
7a3408
         ret = -1;
7a3408
     }
7a3408
     VIR_FREE(core_maps);
7a3408
+    virBitmapFree(present_cpumap);
7a3408
 
7a3408
     return ret;
7a3408
 }
7a3408
@@ -657,7 +670,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
7a3408
                         sysfs_dir, nodedirent->d_name) < 0)
7a3408
             goto cleanup;
7a3408
 
7a3408
-        if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
7a3408
+        if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch,
7a3408
                                      &socks, &cores,
7a3408
                                      &threads, &offline)) < 0)
7a3408
             goto cleanup;
7a3408
@@ -688,7 +701,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
7a3408
     if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0)
7a3408
         goto cleanup;
7a3408
 
7a3408
-    if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
7a3408
+    if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch,
7a3408
                                  &socks, &cores,
7a3408
                                  &threads, &offline)) < 0)
7a3408
         goto cleanup;
7a3408
-- 
7a3408
2.5.0
7a3408