[libvirt] [[PATCH v2]] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.

From: Bing Bu Cao <mars@linux.vnet.ibm.com> To retrieve node cpu statistics on Linux system, the linuxNodeGetCPUstats function simply uses STRPREFIX() to match the cpuid with the cpuid read from /proc/stat, it will cause obvious error. For example: 'virsh nodecpustats 1' will display stats of cpu1* if the latter is online and cpu1 is offline. This patch fixes this bug. Signed-off-by: Bing Bu Cao <mars@linux.vnet.ibm.com> --- src/nodeinfo.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 05bc038..cba2fc1 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -708,9 +708,9 @@ linuxNodeGetCPUStats(FILE *procstat, } if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) { - strcpy(cpu_header, "cpu"); + strcpy(cpu_header, "cpu "); } else { - snprintf(cpu_header, sizeof(cpu_header), "cpu%d", cpuNum); + snprintf(cpu_header, sizeof(cpu_header), "cpu%d ", cpuNum); } while (fgets(line, sizeof(line), procstat) != NULL) { -- 1.7.7.6

On 16.01.2014 09:18, mars@linux.vnet.ibm.com wrote:
From: Bing Bu Cao <mars@linux.vnet.ibm.com>
To retrieve node cpu statistics on Linux system, the linuxNodeGetCPUstats function simply uses STRPREFIX() to match the cpuid with the cpuid read from /proc/stat, it will cause obvious error.
For example: 'virsh nodecpustats 1' will display stats of cpu1* if the latter is online and cpu1 is offline.
This patch fixes this bug.
Signed-off-by: Bing Bu Cao <mars@linux.vnet.ibm.com> --- src/nodeinfo.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 05bc038..cba2fc1 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -708,9 +708,9 @@ linuxNodeGetCPUStats(FILE *procstat, }
if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) { - strcpy(cpu_header, "cpu"); + strcpy(cpu_header, "cpu "); } else { - snprintf(cpu_header, sizeof(cpu_header), "cpu%d", cpuNum); + snprintf(cpu_header, sizeof(cpu_header), "cpu%d ", cpuNum); }
while (fgets(line, sizeof(line), procstat) != NULL) {
ACK. I've changed the commit message a bit (if you git-log you'll see we use slightly different structure of commit messages) and pushed. Michal
participants (2)
-
mars@linux.vnet.ibm.com
-
Michal Privoznik