]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: virhostcpu: Fail when fetching CPU Stats for invalid cpu
authorMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>
Fri, 21 Feb 2020 18:10:45 +0000 (15:10 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 24 Mar 2020 10:31:07 +0000 (11:31 +0100)
commit75a4ec42f70b5324f95d7ffbbfbf7457620735e4
tree6ca91919981db5637c5c91038ddb953942d38292
parent223b370aaa6fcbcbfbd4045fde4ae67e047180ad
util: virhostcpu: Fail when fetching CPU Stats for invalid cpu

virHostCPUGetStatsLinux walks through every cpu in /proc/stat until it
finds cpu%cpuNum that matches with the requested cpu.
If none is found it logs the error but it should return -1, instead of 0.
Otherwise virsh nodecpustats --cpu <invalid cpu number> and API bindings
don't fail properly, printing a blank line instead of an error message.

This patch also includes an additional test for virhostcputest to avoid
this regression to happen again in the future.

Fixes: 93af79fba3fd75a8df6b7ca608719dd97f9511a0
Reported-by: Satheesh Rajendran <satheera@in.ibm.com>
Signed-off-by: Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Tested-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
src/util/virhostcpu.c
tests/virhostcputest.c