From b0b582263d1406084ca19157784a90ed7471606b Mon Sep 17 00:00:00 2001 From: Collin Walling Date: Thu, 19 Sep 2019 16:24:58 -0400 Subject: [PATCH] qemu_monitor: implement query-cpu-model-baseline Interfaces with QEMU to baseline 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-baseline command issued via QMP, a result is produced that contains a new baselined CPU model that is guaranteed to run on both A and B. Signed-off-by: Collin Walling Reviewed-by: Daniel Henrique Barboza Message-Id: <1568924706-2311-8-git-send-email-walling@linux.ibm.com> Reviewed-by: Jiri Denemark --- src/qemu/qemu_monitor.c | 14 ++++++++++++ src/qemu/qemu_monitor.h | 5 +++++ src/qemu/qemu_monitor_json.c | 42 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 6 ++++++ 4 files changed, 67 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index f841fb32a6..b2e0f07d7e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3561,6 +3561,20 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, } +int +qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, + virCPUDefPtr cpu_a, + virCPUDefPtr cpu_b, + qemuMonitorCPUModelInfoPtr *baseline) +{ + VIR_DEBUG("cpu_a=%p cpu_b=%p", cpu_a, cpu_b); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONGetCPUModelBaseline(mon, cpu_a, cpu_b, baseline); +} + + void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1d72ac40da..42326b04ef 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1153,6 +1153,11 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info); +int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, + virCPUDefPtr cpu_a, + virCPUDefPtr cpu_b, + qemuMonitorCPUModelInfoPtr *baseline); + qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index b9b66826e3..b7a9d0cba7 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5877,6 +5877,48 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, } +int +qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon, + virCPUDefPtr cpu_a, + virCPUDefPtr cpu_b, + qemuMonitorCPUModelInfoPtr *baseline) +{ + VIR_AUTOPTR(virJSONValue) model_a = NULL; + VIR_AUTOPTR(virJSONValue) model_b = NULL; + VIR_AUTOPTR(virJSONValue) cmd = NULL; + VIR_AUTOPTR(virJSONValue) reply = NULL; + virJSONValuePtr data; + virJSONValuePtr cpu_model; + virJSONValuePtr cpu_props = NULL; + const char *cpu_name = ""; + + if (!(model_a = qemuMonitorJSONMakeCPUModel(cpu_a, true)) || + !(model_b = qemuMonitorJSONMakeCPUModel(cpu_b, true))) + return -1; + + if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline", + "a:modela", &model_a, + "a:modelb", &model_b, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) + return -1; + + data = virJSONValueObjectGetObject(reply, "return"); + + if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-baseline", + false, &cpu_model, &cpu_props, + &cpu_name) < 0) + return -1; + + return qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, baseline); +} + + int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, char ***commands) { diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 569fb656f0..3d5f76eb77 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -387,6 +387,12 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelInfoPtr *model_info) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(6); +int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon, + virCPUDefPtr cpu_a, + virCPUDefPtr cpu_b, + qemuMonitorCPUModelInfoPtr *baseline) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); + int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, char ***commands) ATTRIBUTE_NONNULL(2); -- GitLab