Re: [PATCH v2 2/4] qemu_agent: Add qemuAgentGetLoadAvg()

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

 



On Tue, Feb 25, 2025 at 15:52:30 +0100, Martin Kletzander wrote:
> With qemu guest agent 9.3 we are able to get the load averages with a
> new command.
> 
> Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
> ---
>  src/qemu/qemu_agent.c | 55 +++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_agent.h |  6 +++++
>  tests/qemuagenttest.c | 53 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 43fca86f10ed..27efb4b389ee 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -2568,3 +2568,58 @@ int qemuAgentGetDisks(qemuAgent *agent,
>      g_free(*disks);
>      return -1;
>  }
> +
> +
> +int
> +qemuAgentGetLoadAvg(qemuAgent *agent,
> +                    double *load1m,
> +                    double *load5m,
> +                    double *load15m,
> +                    bool report_unsupported)
> +{
> +    g_autoptr(virJSONValue) cmd = NULL;
> +    g_autoptr(virJSONValue) reply = NULL;
> +    virJSONValue *data = NULL;
> +    int rc;
> +
> +    if (load1m)
> +        *load1m = 0;
> +
> +    if (load5m)
> +        *load5m = 0;
> +
> +    if (load15m)
> +        *load15m = 0;

Clearing these is pointless ...

> +
> +    if (!(cmd = qemuAgentMakeCommand("guest-get-load", NULL)))
> +        return -1;
> +
> +    if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
> +                                   report_unsupported)) < 0)
> +        return rc;
> +
> +    if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("qemu agent didn't return an array of loads"));
> +        return -1;
> +    }
> +
> +#define GET_NUMBER_PARAM(param_) \
> +    do { \
> +        if (param_ && \
> +            virJSONValueObjectGetNumberDouble(data, #param_, param_) < 0) { \

... as they are unconditionally overwritten ...

> +            virReportError(VIR_ERR_INTERNAL_ERROR, \
> +                           _("'%1$s' missing in reply of guest-get-load"), \

How about: parameter '%1%s' missing ...

> +                           #param_); \
> +            return -1; \

... or error is returned.

> +        } \
> +    } while (0)
> +
> +    GET_NUMBER_PARAM(load1m);
> +    GET_NUMBER_PARAM(load5m);
> +    GET_NUMBER_PARAM(load15m);



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux