[PATCHv2 02/11] qemu_monitor: Introduce qemuMonitorGetCPUModelBaseline (query-cpu-model-baseline)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wrap QMP query-cpu-model-baseline command transaction with QEMU.
---
 src/qemu/qemu_monitor.c      | 13 ++++++++
 src/qemu/qemu_monitor.h      |  6 ++++
 src/qemu/qemu_monitor_json.c | 63 ++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  7 ++++
 4 files changed, 89 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6ed475ede0..a3278c018e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3707,6 +3707,19 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
     return NULL;
 }
 
+int
+qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+                               qemuMonitorCPUModelInfoPtr model_a,
+                               qemuMonitorCPUModelInfoPtr model_b,
+                               qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+    VIR_DEBUG("model_a->name=%s, model_a->nprops=%lu", model_a->name, model_a->nprops);
+    VIR_DEBUG("model_b->name=%s, model_b->nprops=%lu", model_b->name, model_b->nprops);
+
+    QEMU_CHECK_MONITOR(mon);
+
+    return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model_baseline);
+}
 
 int
 qemuMonitorGetCommands(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b3d62324b4..18b59be985 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1025,6 +1025,12 @@ void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
 
+int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+                                   qemuMonitorCPUModelInfoPtr model_a,
+                                   qemuMonitorCPUModelInfoPtr model_b,
+                                   qemuMonitorCPUModelInfoPtr *model_baseline)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+
 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 a18a1a1bf1..90d43eee97 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5540,6 +5540,69 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 }
 
 
+/* Note: *model_baseline == NULL && return == 0 if command not supported by QEMU
+ */
+int
+qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+                                   qemuMonitorCPUModelInfoPtr model_a,
+                                   qemuMonitorCPUModelInfoPtr model_b,
+                                   qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+    int ret = -1;
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data = NULL;
+    virJSONValuePtr modela = NULL;
+    virJSONValuePtr modelb = NULL;
+    virJSONValuePtr cpu_model = NULL;
+
+    *model_baseline = NULL;
+
+    if (!(modela = qemuMonitorJSONBuildCPUModelInfoToJSON(model_a)) ||
+        !(modelb = qemuMonitorJSONBuildCPUModelInfoToJSON(model_b)))
+        goto cleanup;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
+                                           "a:modela", &modela,
+                                           "a:modelb", &modelb,
+                                           NULL)))
+        goto cleanup;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONHasError(reply, "GenericError")) {
+        /* QEMU does not support query-cpu-model-baseline or cpu model */
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+        goto cleanup;
+
+    data = virJSONValueObjectGetObject(reply, "return");
+
+    if (!(cpu_model = virJSONValueObjectGetObject(data, "model"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-baseline reply data was missing 'model'"));
+        goto cleanup;
+    }
+
+    if (!(*model_baseline = qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_model)))
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    virJSONValueFree(modela);
+    virJSONValueFree(modelb);
+
+    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 6bc0dd3ad2..73e1cb6ace 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -367,6 +367,13 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
                                         qemuMonitorCPUModelInfoPtr *model_info)
     ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
 
+int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+                                       qemuMonitorCPUModelInfoPtr model_a,
+                                       qemuMonitorCPUModelInfoPtr model_b,
+                                       qemuMonitorCPUModelInfoPtr *model_baseline)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+
+
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
                                char ***commands)
     ATTRIBUTE_NONNULL(2);
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux