[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv5 2/8] qemu: bulk stats: implement CPU stats group



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 redhat com>
> ---
>  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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]