]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_monitor: add features to CPU model for QMP command
authorCollin Walling <walling@linux.ibm.com>
Thu, 19 Sep 2019 20:24:55 +0000 (16:24 -0400)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 7 Oct 2019 08:09:49 +0000 (10:09 +0200)
query-cpu-model-baseline/comparison will accept a list of features
as part of the command. Since CPUs may be defined with CPU feature
policies, let's parse it to the appropriate boolean that the QMP
command expects.

A feature that is set to required, force, or if it is a hypervisor
CPU feature (-1), then set the property value to true. Otherwise
(optional, disabled) set the value to false.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Message-Id: <1568924706-2311-5-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_monitor_json.c

index d09e4d3491ff49285dcf4dfec83202f058be7eb3..3850c6c55be33bffbdc8b9f0ff17025df873b56e 100644 (file)
@@ -5690,6 +5690,7 @@ qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu,
 {
     virJSONValuePtr model = NULL;
     virJSONValuePtr props = NULL;
+    size_t i;
 
     if (!(model = virJSONValueNewObject()))
         goto error;
@@ -5697,12 +5698,31 @@ qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu,
     if (virJSONValueObjectAppendString(model, "name", cpu->model) < 0)
         goto error;
 
-    if (!migratable) {
-        if (!(props = virJSONValueNewObject()) ||
-            virJSONValueObjectAppendBoolean(props, "migratable", false) < 0 ||
-            virJSONValueObjectAppend(model, "props", props) < 0)
+    if (cpu->nfeatures || !migratable) {
+        if (!(props = virJSONValueNewObject()))
+            goto error;
+
+        for (i = 0; i < cpu->nfeatures; i++) {
+            char *name = cpu->features[i].name;
+            bool enabled = false;
+
+            /* policy may be reported as -1 if the CPU def is a host model */
+            if (cpu->features[i].policy == VIR_CPU_FEATURE_REQUIRE ||
+                cpu->features[i].policy == VIR_CPU_FEATURE_FORCE ||
+                cpu->features[i].policy == -1)
+                enabled = true;
+
+            if (virJSONValueObjectAppendBoolean(props, name, enabled) < 0)
+                goto error;
+        }
+
+        if (!migratable &&
+            virJSONValueObjectAppendBoolean(props, "migratable", false) < 0) {
+            goto error;
+        }
+
+        if (virJSONValueObjectAppend(model, "props", props) < 0)
             goto error;
-        props = NULL;
     }
 
     return model;