[libvirt] [PATCH 02/27] qemu: monitor: Return struct from qemuMonitor(Text|Json)QueryCPUs

Pavel Hrdina phrdina at redhat.com
Mon Aug 8 17:03:37 UTC 2016


On Fri, Aug 05, 2016 at 03:55:58PM +0200, Peter Krempa wrote:
> Prepare to extract more data by returning a array of structs rather than
> just an array of thread ids. Additionally report fatal errors separately
> from qemu not being able to produce data.
> ---
>  src/qemu/qemu_monitor.c      | 31 ++++++++++++------
>  src/qemu/qemu_monitor.h      |  6 ++++
>  src/qemu/qemu_monitor_json.c | 77 +++++++++++++++++++++++---------------------
>  src/qemu/qemu_monitor_json.h |  3 +-
>  src/qemu/qemu_monitor_text.c | 39 +++++++++++-----------
>  src/qemu/qemu_monitor_text.h |  3 +-
>  tests/qemumonitorjsontest.c  | 39 +++++++++++++++-------
>  7 files changed, 119 insertions(+), 79 deletions(-)

[...]

> diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
> index ca04965..ef325ac 100644
> --- a/src/qemu/qemu_monitor_text.c
> +++ b/src/qemu/qemu_monitor_text.c
> @@ -502,12 +502,15 @@ int qemuMonitorTextSystemReset(qemuMonitorPtr mon)
> 
>  int
>  qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
> -                         int **pids)
> +                         struct qemuMonitorQueryCpusEntry **entries,
> +                         size_t *nentries)
>  {
>      char *qemucpus = NULL;
>      char *line;
> -    pid_t *cpupids = NULL;
> -    size_t ncpupids = 0;
> +    struct qemuMonitorQueryCpusEntry *cpus = NULL;
> +    size_t ncpus;

This was already pointed out, need's to be initialized.

> +    struct qemuMonitorQueryCpusEntry cpu = {0};
> +    int ret = -2; /* -2 denotes a non-fatal error to get the data */
> 
>      if (qemuMonitorHMPCommand(mon, "info cpus", &qemucpus) < 0)
>          return -1;
> @@ -529,15 +532,17 @@ qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
> 
>          /* Extract host Thread ID */
>          if ((offset = strstr(line, "thread_id=")) == NULL)
> -            goto error;
> +            goto cleanup;
> 
>          if (virStrToLong_i(offset + strlen("thread_id="), &end, 10, &tid) < 0)
> -            goto error;
> +            goto cleanup;
>          if (end == NULL || !c_isspace(*end))
> -            goto error;
> +            goto cleanup;
> 
> -        if (VIR_APPEND_ELEMENT_COPY(cpupids, ncpupids, tid) < 0)
> -            goto error;
> +        cpu.tid = tid;
> +
> +        if (VIR_APPEND_ELEMENT_COPY(cpus, ncpus, cpu) < 0)
> +            goto cleanup;

You should set 'ret = -1' in this case.

> 
>          VIR_DEBUG("tid=%d", tid);
> 

ACK




More information about the libvir-list mailing list