On Fri, Jan 19, 2018 at 14:53:10 -0500, John Ferlan wrote:
> Add the query-dump API's in order to allow the dump-guest-memory
> to be used to monitor progress.
> 
> Signed-off-by: John Ferlan <jfer...@redhat.com>
> ---
>  src/qemu/qemu_monitor.c      | 14 +++++++++
>  src/qemu/qemu_monitor.h      | 11 +++++++
>  src/qemu/qemu_monitor_json.c | 69 
> ++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |  4 +++
>  4 files changed, 98 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 031cd0a68..e9096d329 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -2772,6 +2772,20 @@ qemuMonitorMigrateCancel(qemuMonitorPtr mon)
>  }
>  
>  
> +int
> +qemuMonitorQueryDump(qemuMonitorPtr mon,
> +                     qemuMonitorDumpStatsPtr stats)
> +{
> +    QEMU_CHECK_MONITOR(mon);
> +
> +    /* No capability is supported without JSON monitor */
> +    if (!mon->json)
> +        return 0;

Just use QEMU_CHECK_MONITOR_JSON(mon), which will report an error if
JSON is not enabled.

> +
> +    return qemuMonitorJSONQueryDump(mon, stats);
> +}
> +
> +
>  /**
>   * Returns 1 if @capability is supported, 0 if it's not, or -1 on error.
>   */
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index f2ac71071..f7ce9ed40 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -777,6 +777,17 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
>  int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
>                                              const char *capability);
>  
> +typedef struct _qemuMonitorDumpStats qemuMonitorDumpStats;
> +typedef qemuMonitorDumpStats *qemuMonitorDumpStatsPtr;
> +struct _qemuMonitorDumpStats {
> +    int status; /* qemuMonitorDumpStatus */
> +    unsigned long long completed; /* bytes written */
> +    unsigned long long total; /* total bytes to be written */
> +};
> +
> +int qemuMonitorQueryDump(qemuMonitorPtr mon,
> +                         qemuMonitorDumpStatsPtr stats);
> +
>  int qemuMonitorDumpToFd(qemuMonitorPtr mon,
>                          int fd,
>                          const char *dumpformat);
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 169c01205..ddb1ec3c6 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -3136,6 +3136,75 @@ int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
>      return ret;
>  }
>  
> +
> +/* qemuMonitorJSONQueryDump:
> + * @mon: Monitor pointer
> + * @stats: Dump "stats"
> + *
> + * Attempt to make a "query-dump" call, check for errors, and get/return
> + * the current from the reply
> + *
> + * Returns: 0 on success, -1 on failure
> + */
> +int
> +qemuMonitorJSONQueryDump(qemuMonitorPtr mon,
> +                         qemuMonitorDumpStatsPtr stats)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-dump", NULL);
> +    virJSONValuePtr reply = NULL;
> +    virJSONValuePtr result = NULL;
> +    const char *statusstr;
> +
> +    if (!cmd)
> +        return -1;
> +
> +    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> +        goto cleanup;
> +
> +    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
> +        goto cleanup;
> +
> +    if (!(result = virJSONValueObjectGetObject(reply, "return")))
> +        goto cleanup;

When qemuMonitorJSONCheckError doesn't report an error, the reply is
guaranteed to have an object with "return" key. In other words, just do

    result = virJSONValueObjectGetObject(reply, "return");

> +
> +    if (!(statusstr = virJSONValueObjectGetString(result, "status"))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("incomplete result, failed to get status"));
> +        goto cleanup;
> +    }
> +
> +    stats->status = qemuMonitorDumpStatusTypeFromString(statusstr);
> +    if (stats->status < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("incomplete result, unknown status string '%s'"),
> +                       statusstr);
> +        goto cleanup;
> +    }
> +
> +    if (virJSONValueObjectGetNumberUlong(result, "completed",
> +                                         &stats->completed) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("incomplete result, failed to get completed"));
> +        goto cleanup;
> +    }
> +
> +    if (virJSONValueObjectGetNumberUlong(result, "total", &stats->total) < 
> 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("incomplete result, failed to get total"));
> +        goto cleanup;
> +    }

This stats parsing code could be moved into a separate function since
the DUMP_COMPLETED event contains the same structure. And we could
benefit from using it to filling the priv->job.completed data after
qemuDumpWaitForCompletion() returns without having to ask for the stats.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to