The max value of number of cpus to compute(id) should not
be equal or greater than max cpu number.
The bug ocurrs when id value is equal to max cpu number which
leads to the off-by-one error in the following for loop.
# virsh cpu-stats guest --start 1
error: Failed to virDomainGetCPUStats()
error: internal error cpuacct parse error
---
src/qemu/qemu_driver.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dc35b91..54a6d35 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14259,9 +14259,9 @@ qemuDomainGetPercpuStats(virDomainObjPtr vm,
param_idx = 0;
/* number of cpus to compute */
- id = max_id;
-
- if (max_id - start_cpu > ncpus - 1)
+ if ((start_cpu + ncpus) >= max_id)
+ id = max_id - 1;
+ else
id = start_cpu + ncpus - 1;
for (i = 0; i <= id; i++) {
--
1.7.11.2