On 09/15/14 10:48, Francesco Romani wrote: > This patch implements the VIR_DOMAIN_STATS_CPU_TOTAL > group of statistics. > > Signed-off-by: Francesco Romani <fromani@xxxxxxxxxx> > --- > include/libvirt/libvirt.h.in | 1 + > src/libvirt.c | 7 +++++++ > src/qemu/qemu_driver.c | 41 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 49 insertions(+) > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index 39e9d27..d0fad61 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -17388,6 +17389,45 @@ typedef enum { > #define HAVE_MONITOR(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_MONITOR) > > > +static int > +qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, > + virDomainObjPtr dom, > + virDomainStatsRecordPtr record, > + int *maxparams, > + unsigned int privflags ATTRIBUTE_UNUSED) > +{ > + qemuDomainObjPrivatePtr priv = dom->privateData; > + unsigned long long cpu_time = 0; > + unsigned long long user_time = 0; > + unsigned long long sys_time = 0; > + int err = 0; > + > + err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time); This code doesn't check if priv->cgroup isn't NULL and dereferences it unconditionally. This would crash with shutoff machines. I'll add an if (priv->group) return 0; right at the beginning. > + if (!err && virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "cpu.time", > + cpu_time) < 0) > + return -1; > + > + err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time); > + if (!err && virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "cpu.user", > + user_time) < 0) > + return -1; > + if (!err && virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "cpu.system", > + sys_time) < 0) > + return -1; > + > + return 0; > +} > + > + > typedef int > (*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver, > virDomainObjPtr dom, Peter
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list