From: "Collin L. Walling" <walling(a)linux.vnet.ibm.com>
query-cpu-model-expansion is used to get a list of features for a given cpu
model name or to get the model and features of the host hardware/environment
as seen by Qemu/kvm.
Signed-off-by: Collin L. Walling <walling(a)linux.vnet.ibm.com>
Signed-off-by: Jason J. Herne <jjherne(a)linux.vnet.ibm.com>
---
src/qemu/qemu_monitor.c | 28 +++++++++++++
src/qemu/qemu_monitor.h | 19 +++++++++
src/qemu/qemu_monitor_json.c | 98 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 6 +++
4 files changed, 151 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a5e14b2..a7f056b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3615,6 +3615,34 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
int
+qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
+ const char *type,
+ const char *model_name,
+ qemuMonitorCPUModelInfoPtr *model_info)
+{
+ VIR_DEBUG("model_info=%p", model_info);
+
+ QEMU_CHECK_MONITOR_JSON(mon);
+
+ return qemuMonitorJSONGetCPUModelExpansion(mon, type, model_name, model_info);
+}
+
+
+void
+qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
+{
+ size_t i;
+
+ if (!model_info)
+ return;
+ VIR_FREE(model_info->name);
+ for (i = 0; i < model_info->nprops; i++)
+ VIR_FREE(model_info->props[i].name);
+ VIR_FREE(model_info);
+}
+
+
+int
qemuMonitorGetCommands(qemuMonitorPtr mon,
char ***commands)
{
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c3133c4..60e72df 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -920,6 +920,25 @@ int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
qemuMonitorCPUDefInfoPtr **cpus);
void qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu);
+typedef struct _qemuMonitorCPUModelInfo qemuMonitorCPUModelInfo;
+typedef qemuMonitorCPUModelInfo *qemuMonitorCPUModelInfoPtr;
+
+struct _qemuMonitorCPUModelInfo {
+ char *name;
+ size_t nprops;
+ struct {
+ char *name;
+ bool supported;
+ } *props;
+};
+
+int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
+ const char *type,
+ const char *model_name,
+ qemuMonitorCPUModelInfoPtr *model_info);
+
+void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
+
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 6c13832..dbb92e1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4975,6 +4975,104 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
return ret;
}
+int
+qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
+ const char *type,
+ const char *model_name,
+ qemuMonitorCPUModelInfoPtr *model_info)
+{
+ int ret = -1;
+ virJSONValuePtr model;
+ virJSONValuePtr cmd = NULL;
+ virJSONValuePtr reply = NULL;
+ virJSONValuePtr data;
+ virJSONValuePtr cpu_model;
+ virJSONValuePtr cpu_props;
+ qemuMonitorCPUModelInfoPtr newmodel = NULL;
+ char const *cpu_name;
+ int n;
+ size_t i;
+
+ *model_info = NULL;
+
+ if (!(model = virJSONValueNewObject()))
+ goto cleanup;
+
+ if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
+ goto cleanup;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
+ "s:type", type,
+ "a:model", model,
+ NULL)))
+ goto cleanup;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONHasError(reply, "GenericError")) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-cpu-model-expansion reply was missing return
data"));
+ goto cleanup;
+ }
+
+ if (!(cpu_model = virJSONValueObjectGetObject(data, "model")))
+ goto cleanup;
+
+ if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name")))
+ goto cleanup;
+
+ if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props")))
+ goto cleanup;
+
+ if (VIR_ALLOC(newmodel) < 0)
+ goto cleanup;
+
+ if (VIR_STRDUP(newmodel->name, cpu_name) < 0)
+ goto cleanup;
+
+ n = newmodel->nprops = cpu_props->data.object.npairs;
+
+ if (VIR_ALLOC_N(newmodel->props, n) < 0)
+ goto cleanup;
+
+ for (i = 0; i < n; i++) {
+ const char *prop_name;
+ bool supported;
+
+ if (!(prop_name = virJSONValueObjectGetKey(cpu_props, i))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-cpu-model-expansion reply data is missing a
property"));
+ goto cleanup;
+ }
+ if (VIR_STRDUP(newmodel->props[i].name, prop_name) < 0)
+ goto cleanup;
+
+ if (virJSONValueObjectGetBoolean(cpu_props, prop_name, &supported) < 0)
+ goto cleanup;
+ newmodel->props[i].supported = supported;
+ }
+
+ ret = 0;
+ *model_info = newmodel;
+ newmodel = NULL;
+
+ cleanup:
+ qemuMonitorCPUModelInfoFree(newmodel);
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ virJSONValueFree(model);
+ 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 77b2e02..6e544c6 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -351,6 +351,12 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
qemuMonitorCPUDefInfoPtr **cpus)
ATTRIBUTE_NONNULL(2);
+int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
+ const char *type,
+ const char *model_name,
+ qemuMonitorCPUModelInfoPtr *model_info)
+ ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
char ***commands)
ATTRIBUTE_NONNULL(2);
--
1.9.1