Re: [PATCHv2 02/11] qemu_monitor: Introduce qemuMonitorGetCPUModelBaseline (query-cpu-model-baseline)

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

 



Drop "(query-cpu-model-baseline)" from the subject to make it shorter.

On Mon, Jul 09, 2018 at 22:56:46 -0500, Chris Venteicher wrote:
> Wrap QMP query-cpu-model-baseline command transaction with QEMU.
> ---
>  src/qemu/qemu_monitor.c      | 13 ++++++++
>  src/qemu/qemu_monitor.h      |  6 ++++
>  src/qemu/qemu_monitor_json.c | 63 ++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |  7 ++++
>  4 files changed, 89 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 6ed475ede0..a3278c018e 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3707,6 +3707,19 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
>      return NULL;
>  }
>  
> +int
> +qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
> +                               qemuMonitorCPUModelInfoPtr model_a,
> +                               qemuMonitorCPUModelInfoPtr model_b,
> +                               qemuMonitorCPUModelInfoPtr *model_baseline)
> +{
> +    VIR_DEBUG("model_a->name=%s, model_a->nprops=%lu", model_a->name, model_a->nprops);
> +    VIR_DEBUG("model_b->name=%s, model_b->nprops=%lu", model_b->name, model_b->nprops);

Please, merge this into a single VIR_DEBUG, otherwise they would be
logged on two lines possibly with logs from other threads in between.

    VIR_DEBUG("model_a->name=%s, model_a->nprops=%lu "
              "model_b->name=%s, model_b->nprops=%lu",
              model_a->name, model_a->nprops,
              model_b->name, model_b->nprops);
> +
> +    QEMU_CHECK_MONITOR(mon);
> +
> +    return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model_baseline);
> +}
>  
>  int
>  qemuMonitorGetCommands(qemuMonitorPtr mon,
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index b3d62324b4..18b59be985 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -1025,6 +1025,12 @@ void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
>  qemuMonitorCPUModelInfoPtr
>  qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
>  
> +int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
> +                                   qemuMonitorCPUModelInfoPtr model_a,
> +                                   qemuMonitorCPUModelInfoPtr model_b,
> +                                   qemuMonitorCPUModelInfoPtr *model_baseline)
> +    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
> +
>  int qemuMonitorGetCommands(qemuMonitorPtr mon,
>                             char ***commands);
>  int qemuMonitorGetEvents(qemuMonitorPtr mon,
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index a18a1a1bf1..90d43eee97 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5540,6 +5540,69 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
>  }
>  
>  
> +/* Note: *model_baseline == NULL && return == 0 if command not supported by QEMU
> + */
> +int
> +qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
> +                                   qemuMonitorCPUModelInfoPtr model_a,
> +                                   qemuMonitorCPUModelInfoPtr model_b,
> +                                   qemuMonitorCPUModelInfoPtr *model_baseline)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd = NULL;
> +    virJSONValuePtr reply = NULL;
> +    virJSONValuePtr data = NULL;
> +    virJSONValuePtr modela = NULL;
> +    virJSONValuePtr modelb = NULL;
> +    virJSONValuePtr cpu_model = NULL;
> +
> +    *model_baseline = NULL;
> +
> +    if (!(modela = qemuMonitorJSONBuildCPUModelInfoToJSON(model_a)) ||
> +        !(modelb = qemuMonitorJSONBuildCPUModelInfoToJSON(model_b)))
> +        goto cleanup;
> +
> +    if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
> +                                           "a:modela", &modela,
> +                                           "a:modelb", &modelb,
> +                                           NULL)))
> +        goto cleanup;
> +
> +    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> +        goto cleanup;
> +
> +    if (qemuMonitorJSONHasError(reply, "GenericError")) {
> +        /* QEMU does not support query-cpu-model-baseline or cpu model */
> +        ret = 0;
> +        goto cleanup;
> +    }

This function is not called for any capabilities probing, is it? We
should normally report an error if QEMU does not support the command and
propagate it back to the user who asked for CPU baseline. Not reporting
an error is only useful if we don't care if the command is supported by
QEMU (i.e., when we probe for capabilities) or when we have a fallback
code.

> +
> +    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
> +        goto cleanup;
> +
> +    data = virJSONValueObjectGetObject(reply, "return");
> +
> +    if (!(cpu_model = virJSONValueObjectGetObject(data, "model"))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("query-cpu-model-baseline reply data was missing 'model'"));
> +        goto cleanup;
> +    }
> +
> +    if (!(*model_baseline = qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_model)))
> +        goto cleanup;
> +
> +    ret = 0;
> +
> + cleanup:
> +    virJSONValueFree(cmd);
> +    virJSONValueFree(reply);
> +    virJSONValueFree(modela);
> +    virJSONValueFree(modelb);
> +
> +    return ret;
> +}

Jirka

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



[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