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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Bing Bu Cao <mars@xxxxxxxxxxxxxxxxxx>

To retrieve node cpu statistics on Linux system, the
linuxNodeGetCPUstats function use STRPREFIX() to match the
cpuid with the cpuid read from /proc/cpustat, it will cause
obvious error.

For example:
'virsh nodecpustats 12' will display stats of cpu1 if the latter is online.

This patch fixes this bug.

Signed-off-by: Bing Bu Cao <mars@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Pradipta Kr. Banerjee <bpradip@xxxxxxxxxx>
---
 src/nodeinfo.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 05bc038..6d7926c 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -715,8 +715,9 @@ linuxNodeGetCPUStats(FILE *procstat,
 
     while (fgets(line, sizeof(line), procstat) != NULL) {
         char *buf = line;
+        char **buf_header = virStringSplit(buf, " ", 2);
 
-        if (STRPREFIX(buf, cpu_header)) { /* aka logical CPU time */
+        if (STREQ(buf_header[0], cpu_header)) { /* aka logical CPU time */
             size_t i;
 
             if (sscanf(buf,
@@ -775,6 +776,7 @@ linuxNodeGetCPUStats(FILE *procstat,
             ret = 0;
             goto cleanup;
         }
+        virStringFreeList(buf_header);
     }
 
     virReportInvalidArg(cpuNum,
@@ -782,6 +784,7 @@ linuxNodeGetCPUStats(FILE *procstat,
                         __FUNCTION__);
 
 cleanup:
+    virStringFreeList(buf_header);
     return ret;
 }
 
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]