]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodeinfo: Fix nodeGetCPUBitmap()'s fallback code path
authorAndrea Bolognani <abologna@redhat.com>
Fri, 17 Jul 2015 16:12:50 +0000 (18:12 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 22 Jul 2015 07:57:57 +0000 (09:57 +0200)
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

index d7d022395ffab1b4d2254111dafca73f435458c9..2bf611c642fc7287e97a1a6df1bbc07bd03e22f0 100644 (file)
@@ -1301,6 +1301,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;
 
@@ -1318,8 +1319,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;
@@ -1333,6 +1338,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",