]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
nodeinfo: fix to parse present cpus rather than possible cpus
authorKothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
Fri, 26 Jun 2015 22:27:29 +0000 (03:57 +0530)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 13 Jul 2015 20:07:44 +0000 (16:07 -0400)
This patch resolves a situation where a core is defective and is not
in the present mask during boot. Optionally a host can have empty sockets
could be brought online if the socket is added. In this case the present
mask contains the cpu's that are actually there in the sockets even though
they might be offline for some reason. This patch excludes the cpu's that
are offline because the socket is defective/empty by checking the present
mask before reading the cpu directory. Otherwise, the nodeinfo on such
hosts always displays wrong output which includes the defective/empty
sockets as set of offline cpu's.

Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
src/nodeinfo.c

index ca9cb3a66e60672613574dbb2552e0de29ebd7bc..51586802c7c12b85d9d59ba9b6a8c568b95fd029 100644 (file)
@@ -43,6 +43,7 @@
 #include "c-ctype.h"
 #include "viralloc.h"
 #include "nodeinfopriv.h"
+#include "nodeinfo.h"
 #include "physmem.h"
 #include "virerror.h"
 #include "count-one-bits.h"
@@ -403,20 +404,23 @@ CPU_COUNT(cpu_set_t *set)
 /* parses a node entry, returning number of processors in the node and
  * filling arguments */
 static int
-ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
 ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
-ATTRIBUTE_NONNULL(6)
-virNodeParseNode(const char *node,
+ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7)
+virNodeParseNode(const char *sysfs_prefix,
+                 const char *node,
                  virArch arch,
                  int *sockets,
                  int *cores,
                  int *threads,
                  int *offline)
 {
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
     int ret = -1;
     int processors = 0;
     DIR *cpudir = NULL;
     struct dirent *cpudirent = NULL;
+    virBitmapPtr present_cpumap = NULL;
     int sock_max = 0;
     cpu_set_t sock_map;
     int sock;
@@ -437,12 +441,17 @@ virNodeParseNode(const char *node,
         goto cleanup;
     }
 
+    present_cpumap = nodeGetPresentCPUBitmap(prefix);
+
     /* enumerate sockets in the node */
     CPU_ZERO(&sock_map);
     while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
             continue;
 
+        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
+            continue;
+
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
             goto cleanup;
 
@@ -476,6 +485,9 @@ virNodeParseNode(const char *node,
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
             continue;
 
+        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
+            continue;
+
         if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
             goto cleanup;
 
@@ -536,6 +548,7 @@ virNodeParseNode(const char *node,
         ret = -1;
     }
     VIR_FREE(core_maps);
+    virBitmapFree(present_cpumap);
 
     return ret;
 }
@@ -657,7 +670,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
                         sysfs_dir, nodedirent->d_name) < 0)
             goto cleanup;
 
-        if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
+        if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch,
                                      &socks, &cores,
                                      &threads, &offline)) < 0)
             goto cleanup;
@@ -688,7 +701,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
     if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0)
         goto cleanup;
 
-    if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
+    if ((cpus = virNodeParseNode(sysfs_dir, sysfs_cpudir, arch,
                                  &socks, &cores,
                                  &threads, &offline)) < 0)
         goto cleanup;