]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: qmp query-cpu-model-expansion command
authorCollin L. Walling <walling@linux.vnet.ibm.com>
Sun, 18 Dec 2016 19:22:26 +0000 (14:22 -0500)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 6 Jan 2017 11:24:57 +0000 (12:24 +0100)
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@linux.vnet.ibm.com>
Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml

index 542705914cdb4544815b291580b2f9157dd350e7..996f273ee1da2e0ad7f6d3c7f5f7a949a0e1a418 100644 (file)
@@ -354,6 +354,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "gluster.debug_level",
               "vhost-scsi",
               "drive-iotune-group",
+
+              "query-cpu-model-expansion", /* 245 */
     );
 
 
@@ -1514,7 +1516,8 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
     { "rtc-reset-reinjection", QEMU_CAPS_RTC_RESET_REINJECTION },
     { "migrate-incoming", QEMU_CAPS_INCOMING_DEFER },
     { "query-hotpluggable-cpus", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS },
-    { "query-qmp-schema", QEMU_CAPS_QUERY_QMP_SCHEMA }
+    { "query-qmp-schema", QEMU_CAPS_QUERY_QMP_SCHEMA },
+    { "query-cpu-model-expansion", QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION},
 };
 
 struct virQEMUCapsStringFlags virQEMUCapsMigration[] = {
index cbab8798334aa24f2efa6531b962151a533c2030..b5ad95e4694c2aa68e444140958fef634583f72e 100644 (file)
@@ -390,6 +390,9 @@ typedef enum {
     QEMU_CAPS_DEVICE_VHOST_SCSI, /* -device vhost-scsi-{ccw,pci} */
     QEMU_CAPS_DRIVE_IOTUNE_GROUP, /* -drive throttling.group=<name> */
 
+    /* 245 */
+    QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION, /* qmp query-cpu-model-expansion */
+
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
 
index 815610b6d09a1a1ed8c893a26a15995567e0028f..1610ae3f4ea001f8cb6a972d507eaa63ef333f0c 100644 (file)
@@ -3635,6 +3635,68 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
 }
 
 
+int
+qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
+                                const char *type,
+                                const char *model_name,
+                                qemuMonitorCPUModelInfoPtr *model_info)
+{
+    VIR_DEBUG("type=%s model_name=%s", type, model_name);
+
+    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;
+
+    for (i = 0; i < model_info->nprops; i++)
+        VIR_FREE(model_info->props[i].name);
+
+    VIR_FREE(model_info->name);
+    VIR_FREE(model_info);
+}
+
+
+qemuMonitorCPUModelInfoPtr
+qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
+{
+    qemuMonitorCPUModelInfoPtr copy;
+    size_t i;
+
+    if (VIR_ALLOC(copy) < 0)
+        goto error;
+
+    if (VIR_ALLOC_N(copy->props, orig->nprops) < 0)
+        goto error;
+
+    if (VIR_STRDUP(copy->name, orig->name) < 0)
+        goto error;
+
+    copy->nprops = orig->nprops;
+
+    for (i = 0; i < orig->nprops; i++) {
+        if (VIR_STRDUP(copy->props[i].name, orig->props[i].name) < 0)
+            goto error;
+
+        copy->props[i].supported = orig->props[i].supported;
+    }
+
+    return copy;
+
+ error:
+    qemuMonitorCPUModelInfoFree(copy);
+    return NULL;
+}
+
+
 int
 qemuMonitorGetCommands(qemuMonitorPtr mon,
                        char ***commands)
index dce516afd6594c2577e135836179be833d761f57..8811d8501737af459088dbc53e8fb5394632c785 100644 (file)
@@ -921,6 +921,28 @@ 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);
+
+qemuMonitorCPUModelInfoPtr
+qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
+
 int qemuMonitorGetCommands(qemuMonitorPtr mon,
                            char ***commands);
 int qemuMonitorGetEvents(qemuMonitorPtr mon,
index 0c38b8f0df11870674a4cccf716bc4cbda7f1795..e767437c0f2fe893f83a961bf2d81c1cc847d047 100644 (file)
@@ -4973,6 +4973,123 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
     return ret;
 }
 
+static int
+qemuMonitorJSONParseCPUModelProperty(const char *key,
+                                     virJSONValue *value,
+                                     void *opaque)
+{
+    qemuMonitorCPUModelInfoPtr machine_model = opaque;
+    size_t n = machine_model->nprops;
+    bool supported;
+
+    if (!key) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data is missing a"
+                         " property name"));
+        return -1;
+    }
+    if (VIR_STRDUP(machine_model->props[n].name, key) < 0)
+        return -1;
+
+    if (virJSONValueGetBoolean(value, &supported) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data is missing a"
+                         " feature support value"));
+        return -1;
+    }
+    machine_model->props[n].supported = supported;
+
+    machine_model->nprops++;
+    return 0;
+}
+
+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 machine_model = NULL;
+    char const *cpu_name;
+
+    *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;
+
+    /* model will be freed when cmd is freed. we set model
+     * to NULL to avoid double freeing.
+     */
+    model = NULL;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    data = virJSONValueObjectGetObject(reply, "return");
+
+    if (!(cpu_model = virJSONValueObjectGetObject(data, "model"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'model'"));
+        goto cleanup;
+    }
+
+    if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'name'"));
+        goto cleanup;
+    }
+
+    if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'props'"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC(machine_model) < 0)
+        goto cleanup;
+
+    if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(machine_model->props, cpu_props->data.object.npairs) < 0)
+        goto cleanup;
+
+    if (virJSONValueObjectForeachKeyValue(cpu_props,
+                                          qemuMonitorJSONParseCPUModelProperty,
+                                          machine_model) < 0)
+        goto cleanup;
+
+    ret = 0;
+    *model_info = machine_model;
+    machine_model = NULL;
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(machine_model);
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    virJSONValueFree(model);
+    return ret;
+}
+
 
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
                                char ***commands)
index adff0c3bec1c3a71e7ae6ba1d92bd5be16bc154a..18b508d9cacc92908497229a181fa9a8b170dc50 100644 (file)
@@ -352,6 +352,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);
index cbba6b5a38cf85e0607d3ad3826d36ae1c183d94..1b955cf238f65089b6f57af5fb0aa56416f96482 100644 (file)
   <flag name='gluster.debug_level'/>
   <flag name='vhost-scsi'/>
   <flag name='drive-iotune-group'/>
+  <flag name='query-cpu-model-expansion'/>
   <version>2007093</version>
   <kvmVersion>0</kvmVersion>
   <package></package>