[libvirt] [PATCH v3] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.
From: Bing Bu Cao 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 --- src/nodeinfo.c |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 05bc038..cf6d29b 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -691,7 +691,7 @@ linuxNodeGetCPUStats(FILE *procstat, char line[1024]; unsigned long long usr, ni, sys, idle, iowait; unsigned long long irq, softirq, steal, guest, guest_nice; -char cpu_header[3 + INT_BUFSIZE_BOUND(cpuNum)]; +char cpu_header[4 + INT_BUFSIZE_BOUND(cpuNum)]; if ((*nparams) == 0) { /* Current number of cpu stats supported by linux */ @@ -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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [[PATCH v2]] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.
From: Bing Bu Cao 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 --- 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.
From: Bing Bu Cao 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 --- 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.
From: Bing Bu Cao 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 Signed-off-by: Pradipta Kr. Banerjee --- 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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Make virsh command 'domxml-to-native' copy the MAC addr parsed from XML
From: Bing Bu Cao virsh command 'domxml-to-native' did not copy the MAC address which parsed from a domain xml, in the commandline the MAC addr of network device always was 00:00:00:00:00:00. This patch fix it. Signed-off-by: Bing Bu Cao --- src/qemu/qemu_driver.c |5 + 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8a1eefd..4693dad 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5821,6 +5821,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, virDomainNetDefPtr net = def->nets[i]; int bootIndex = net->info.bootIndex; char *model = net->model; +virMacAddr mac = net->mac; if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { int actualType = virDomainNetGetActualType(net); @@ -5843,6 +5844,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, net->script = NULL; net->data.ethernet.dev = brnamecopy; net->data.ethernet.ipaddr = NULL; +net->mac = mac; } else { /* actualType is either NETWORK or DIRECT. In either * case, the best we can do is NULL everything out. @@ -5854,6 +5856,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, net->script = NULL; net->data.ethernet.dev = NULL; net->data.ethernet.ipaddr = NULL; +net->mac = mac; } } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) { VIR_FREE(net->data.direct.linkdev); @@ -5864,6 +5867,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, net->script = NULL; net->data.ethernet.dev = NULL; net->data.ethernet.ipaddr = NULL; +net->mac = mac; } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { char *script = net->script; char *brname = net->data.bridge.brname; @@ -5875,6 +5879,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, net->script = script; net->data.ethernet.dev = brname; net->data.ethernet.ipaddr = ipaddr; +net->mac = mac; } VIR_FREE(net->virtPortProfile); -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Fix: helper function virCompareLimitUlong should return -1 when the latter parameter is 0
From: Bing Bu Cao The helper function virCompareLimitUlong compare limit values, where value of 0 is equal to unlimited, if the latter parameter is 0, it should return -1 instead of 1, hence the user can only set hard_limit when swap_hard_limit currently is unlimited. Signed-off-by: Bing Bu Cao --- src/util/virutil.c |3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index d9e0bc4..3dcf1fe 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2067,6 +2067,9 @@ virCompareLimitUlong(unsigned long long a, unsigned long b) if (a == b) return 0; +if (0 == b) +return -1; + if (a == 0 || a > b) return 1; -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list