[libvirt] [PATCH v2 5/8] qemu_monitor: implement query-cpu-model-comparison
Daniel Henrique Barboza
danielhb413 at gmail.com
Mon Apr 29 18:42:51 UTC 2019
On 4/26/19 5:22 PM, walling at linux.ibm.com wrote:
> From: Collin Walling <walling at linux.ibm.com>
>
> Interfaces with QEMU to compare CPU models. The command takes two
> CPU models, A and B, that are given a model name and an optional list
> of CPU features. Through the query-cpu-model-comparison command issued
> via QMP, a result is produced that contains the comparison evaluation
> string (identical, superset, subset, incompatible) as well as a list
> of properties (aka CPU features) responsible for the subset or
> superset result.
>
> Signed-off-by: Collin Walling <walling at linux.ibm.com>
> Tested-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
> ---
Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
> src/qemu/qemu_monitor.c | 22 +++++++++++
> src/qemu/qemu_monitor.h | 9 +++++
> src/qemu/qemu_monitor_json.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_monitor_json.h | 10 +++++
> 4 files changed, 130 insertions(+)
>
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 10e312c..176c070 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3706,6 +3706,28 @@ qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
> }
>
>
> +int
> +qemuMonitorGetCPUModelComparison(qemuMonitorPtr mon,
> + const char *model_a_name,
> + int model_a_nprops,
> + virCPUFeatureDefPtr model_a_props,
> + const char *model_b_name,
> + int model_b_nprops,
> + virCPUFeatureDefPtr model_b_props,
> + qemuMonitorCPUModelInfoPtr *model_result)
> +{
> + VIR_DEBUG("model_a_name=%s model_a_nprops=%d model_b_name=%s model_b_nprops=%d",
> + model_a_name, model_a_nprops, model_b_name, model_b_nprops);
> +
> + QEMU_CHECK_MONITOR(mon);
> +
> + return qemuMonitorJSONGetCPUModelComparison(mon, model_a_name, model_a_nprops,
> + model_a_props, model_b_name,
> + model_b_nprops, model_b_props,
> + model_result);
> +}
> +
> +
> void
> qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
> {
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index 637a6c6..03a45a1 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -1075,6 +1075,15 @@ int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
> virCPUFeatureDefPtr model_b_props,
> qemuMonitorCPUModelInfoPtr *model_result);
>
> +int qemuMonitorGetCPUModelComparison(qemuMonitorPtr mon,
> + const char *model_a_name,
> + int model_a_nprops,
> + virCPUFeatureDefPtr model_a_props,
> + const char *model_b_name,
> + int model_b_nprops,
> + virCPUFeatureDefPtr model_b_props,
> + qemuMonitorCPUModelInfoPtr *model_result);
> +
> qemuMonitorCPUModelInfoPtr
> qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
>
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 6c17913..017c65a 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5766,6 +5766,95 @@ qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
> }
>
>
> +static int
> +qemuMonitorJSONParseCPUModelPropName(size_t pos ATTRIBUTE_UNUSED,
> + virJSONValuePtr item,
> + void *opaque)
> +{
> + return qemuMonitorJSONParseCPUModelProperty(virJSONValueGetString(item),
> + item, opaque);
> +}
> +
> +
> +int
> +qemuMonitorJSONGetCPUModelComparison(qemuMonitorPtr mon,
> + const char *model_a_name,
> + int model_a_nprops,
> + virCPUFeatureDefPtr model_a_props,
> + const char *model_b_name,
> + int model_b_nprops,
> + virCPUFeatureDefPtr model_b_props,
> + qemuMonitorCPUModelInfoPtr *model_result)
> +{
> + int ret = -1;
> + virJSONValuePtr model_a;
> + virJSONValuePtr model_b = NULL;
> + virJSONValuePtr cmd = NULL;
> + virJSONValuePtr reply = NULL;
> + virJSONValuePtr data;
> + const char *result_name;
> + virJSONValuePtr props;
> + qemuMonitorCPUModelInfoPtr compare = NULL;
> +
> + if (!(model_a = qemuMonitorJSONMakeCPUModel(model_a_name, model_a_nprops, model_a_props, true)) ||
> + !(model_b = qemuMonitorJSONMakeCPUModel(model_b_name, model_b_nprops, model_b_props, true)))
> + goto cleanup;
> +
> + if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-comparison",
> + "a:modela", &model_a,
> + "a:modelb", &model_b,
> + NULL)))
> + goto cleanup;
> +
> + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> + goto cleanup;
> +
> + if (qemuMonitorJSONCheckError(cmd, reply) < 0)
> + goto cleanup;
> +
> + data = virJSONValueObjectGetObject(reply, "return");
> +
> + if (!(result_name = virJSONValueObjectGetString(data, "result"))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("query-cpu-model-comparison reply data was missing "
> + "'result'"));
> + goto cleanup;
> + }
> +
> + if (!(props = virJSONValueObjectGetArray(data, "responsible-properties"))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("query-cpu-model-comparison reply data was missing "
> + "'responsible-properties'"));
> + goto cleanup;
> + }
> +
> + if (VIR_ALLOC(compare) < 0)
> + goto cleanup;
> +
> + if (VIR_STRDUP(compare->name, result_name) < 0)
> + goto cleanup;
> +
> + if (VIR_ALLOC_N(compare->props, virJSONValueArraySize(props)) < 0)
> + goto cleanup;
> +
> + if (virJSONValueArrayForeachSteal(props,
> + qemuMonitorJSONParseCPUModelPropName,
> + compare) < 0)
> + goto cleanup;
> +
> + VIR_STEAL_PTR(*model_result, compare);
> + ret = 0;
> +
> + cleanup:
> + qemuMonitorCPUModelInfoFree(compare);
> + virJSONValueFree(cmd);
> + virJSONValueFree(reply);
> + virJSONValueFree(model_a);
> + virJSONValueFree(model_b);
> + return ret;
> +}
> +
> +
> int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
> char ***commands)
> {
> diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
> index 77b69af..9959426 100644
> --- a/src/qemu/qemu_monitor_json.h
> +++ b/src/qemu/qemu_monitor_json.h
> @@ -377,6 +377,16 @@ int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
> qemuMonitorCPUModelInfoPtr *model_result)
> ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(8);
>
> +int qemuMonitorJSONGetCPUModelComparison(qemuMonitorPtr mon,
> + const char *model_a_name,
> + int model_a_nprops,
> + virCPUFeatureDefPtr model_a_props,
> + const char *model_b_name,
> + int model_b_nprops,
> + virCPUFeatureDefPtr model_b_props,
> + qemuMonitorCPUModelInfoPtr *model_result)
> + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(8);
> +
> int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
> char ***commands)
> ATTRIBUTE_NONNULL(2);
More information about the libvir-list
mailing list