On 4/26/19 5:22 PM, walling(a)linux.ibm.com wrote:
From: Collin Walling <walling(a)linux.ibm.com>
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 <walling(a)linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_monitor.c | 22 +++++++++++++++++
src/qemu/qemu_monitor.h | 9 +++++++
src/qemu/qemu_monitor_json.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 10 ++++++++
4 files changed, 99 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e1fcbac..10e312c 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3684,6 +3684,28 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
}
+int
+qemuMonitorGetCPUModelBaseline(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 qemuMonitorJSONGetCPUModelBaseline(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 9242d37..637a6c6 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1066,6 +1066,15 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
+int qemuMonitorGetCPUModelBaseline(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 9618d8e..6c17913 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5708,6 +5708,64 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
}
+int
+qemuMonitorJSONGetCPUModelBaseline(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;
+ virJSONValuePtr cpu_model;
+ virJSONValuePtr cpu_props = NULL;
+ const char *cpu_name = "";
+ qemuMonitorCPUModelInfoPtr baseline = 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-baseline",
+ "a:modela", &model_a,
+ "a:modelb", &model_b,
+ NULL)))
+ goto cleanup;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+ goto cleanup;
+
+ data = virJSONValueObjectGetObject(reply, "return");
+
+ if (qemuMonitorJSONParseCPUModelData(data, &cpu_model, &cpu_props,
&cpu_name) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, &baseline) < 0)
+ goto cleanup;
+
+ VIR_STEAL_PTR(*model_result, baseline);
+ ret = 0;
+
+ cleanup:
+ qemuMonitorCPUModelInfoFree(baseline);
+ 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 746b707..77b69af 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -367,6 +367,16 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelInfoPtr *model_info)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
+int qemuMonitorJSONGetCPUModelBaseline(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);