]> git.ipfire.org Git - thirdparty/libvirt.git/commit
rpc: allow truncated return for virDomainGetCPUStats
authorEric Blake <eblake@redhat.com>
Wed, 7 Mar 2012 04:36:53 +0000 (21:36 -0700)
committerEric Blake <eblake@redhat.com>
Wed, 7 Mar 2012 14:14:11 +0000 (07:14 -0700)
commit462dc569ded0d781b7d827103d9df21502726ddc
tree8c9c27be36b1203c5dc6722ec3c78178842f2a86
parentd16a166eaf4452e8b01a4c50889617e1f37334eb
rpc: allow truncated return for virDomainGetCPUStats

The RPC code assumed that the array returned by the driver would be
fully populated; that is, ncpus on entry resulted in ncpus * return
value on exit.  However, while we don't support holes in the middle
of ncpus, we do want to permit the case of ncpus on entry being
longer than the array returned by the driver (that is, it should be
safe for the caller to pass ncpus=128 on entry, and the driver will
stop populating the array when it hits max_id).

Additionally, a successful return implies that the caller will then
use virTypedParamArrayClear on the entire array; for this to not
free uninitialized memory, the driver must ensure that all skipped
entries are explicitly zeroed (the RPC driver did this, but not
the qemu driver).

There are now three cases:
server 0.9.10 and client 0.9.10 or newer: No impact - there were no
hypervisor drivers that supported cpu stats

server 0.9.11 or newer and client 0.9.10: if the client calls with
ncpus beyond the max, then the rpc call will fail on the client side
and disconnect the client, but the server is no worse for the wear

server 0.9.11 or newer and client 0.9.11: the server can return a
truncated array and the client will do just fine

I reproduced the problem by using a host with 2 CPUs, and doing:
virsh cpu-stats $dom --start 1 --count 2

* daemon/remote.c (remoteDispatchDomainGetCPUStats): Allow driver
to omit tail of array.
* src/remote/remote_driver.c (remoteDomainGetCPUStats):
Accommodate driver that omits tail of array.
* src/libvirt.c (virDomainGetCPUStats): Document this.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Clear all
unpopulated entries.
daemon/remote.c
src/libvirt.c
src/qemu/qemu_driver.c
src/remote/remote_driver.c