Hypervisor baseline has an expansion mode where the cpu property /
feature list is fully expanded to list all supported (true) features.

The output (expanded) cpu model should not list properties that are
false (unsupported.)

QEMU expansion output enumerates both true (supported) and false
(unsupported) properties.  This patch removes the false (unsupported)
entries from the output cpu property list.

This change makes the expanded output consistent when both the internal
libvirt utility functions and QEMU QMP commands are used to expand the
property list.

qemu_monitor: Introduce removal of true/false CPUModelInfo props

A utility function is created to squash CPU properties list in
qemuMonitorCPUmodelInfo structure by removing boolean properties
of matching value.

Signed-off-by: Chris Venteicher <cvent...@redhat.com>
---
 src/qemu/qemu_driver.c  |  4 ++++
 src/qemu/qemu_monitor.c | 30 ++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.h |  4 ++++
 3 files changed, 38 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4149e4794a..4f338f1b37 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13861,6 +13861,10 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
                                                 migratable, modelInfo, 
&expansion) < 0)
                 goto cleanup;
 
+            /* Expansion enumerates all features
+             * Baselines output enumerates only in-model (true) features */
+            qemuMonitorCPUModelInfoRemovePropByBoolValue(expansion, false);
+
             if (!(cpu = virQEMUCapsCPUModelInfoToCPUDef(migratable, 
expansion)))
                 goto cleanup;
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index c5266b6767..0c7d7b4b55 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3785,6 +3785,36 @@ qemuMonitorCPUModelInfoCopy(const 
qemuMonitorCPUModelInfo *orig)
 }
 
 
+/* Squash CPU Model Info property list
+ * removing props of type boolean matching value */
+void
+qemuMonitorCPUModelInfoRemovePropByBoolValue(qemuMonitorCPUModelInfoPtr model,
+                                             bool value)
+{
+    qemuMonitorCPUPropertyPtr src;
+    qemuMonitorCPUPropertyPtr dst;
+    size_t i;
+    size_t dst_nprops = 0;
+
+    for (i = 0; i < model->nprops; i++) {
+        src = &(model->props[i]);
+        dst = &(model->props[dst_nprops]);
+
+        if (src->type == QEMU_MONITOR_CPU_PROPERTY_BOOLEAN &&
+            src->value.boolean == value)
+            continue;
+
+        *dst = *src;
+
+        dst_nprops++;
+    }
+
+    model->nprops = dst_nprops;
+
+    ignore_value(VIR_REALLOC_N_QUIET(model->props, dst_nprops));
+}
+
+
 int
 qemuMonitorCPUModelInfoBoolPropAdd(qemuMonitorCPUModelInfoPtr model,
                                    const char *prop_name,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c87a2d5e47..7aaecd97dd 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1053,6 +1053,10 @@ int 
qemuMonitorCPUModelInfoBoolPropAdd(qemuMonitorCPUModelInfoPtr model,
                                        bool prop_value)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+void qemuMonitorCPUModelInfoRemovePropByBoolValue(qemuMonitorCPUModelInfoPtr 
model,
+                                                  bool value)
+    ATTRIBUTE_NONNULL(1);
+
 int qemuMonitorGetCommands(qemuMonitorPtr mon,
                            char ***commands);
 int qemuMonitorGetEvents(qemuMonitorPtr mon,
-- 
2.17.1

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

Reply via email to