From: Andrea Bolognani Date: Fri, 17 Jul 2015 16:12:50 +0000 (+0200) Subject: nodeinfo: Fix nodeGetCPUBitmap()'s fallback code path X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2a6801892ac962d8176f764edde219ae00cb7f3a;p=libvirt.git nodeinfo: Fix nodeGetCPUBitmap()'s fallback code path 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. --- diff --git a/src/nodeinfo.c b/src/nodeinfo.c index d7d022395f..2bf611c642 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -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",