[PATCH 05/14] qemu: Move feature filtering to qemuMonitorJSONGetCPUProperties

Jiri Denemark via Devel posted 14 patches 3 days, 12 hours ago
[PATCH 05/14] qemu: Move feature filtering to qemuMonitorJSONGetCPUProperties
Posted by Jiri Denemark via Devel 3 days, 12 hours ago
From: Jiri Denemark <jdenemar@redhat.com>

When getting enabled CPU features (qemuMonitorJSONGetCPUData), we used
to call qemuMonitorJSONGetCPUProperties to get the list of all boolean
properties and then queried their values and ignored properties that
were not true. By moving the filtering inside
qemuMonitorJSONGetCPUProperties we don't need to even add disabled
features to any list and also get ready for better QMP interface.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 0c78115e9d..be7ad21eca 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6595,14 +6595,29 @@ qemuMonitorJSONGetDeviceAliases(qemuMonitor *mon,
 }
 
 
+struct _qemuMonitorJSONCPUPropsFilterData {
+    qemuMonitor *mon;
+    const char *cpuQOMPath;
+};
+
 static int
-qemuMonitorJSONCPUPropsFilter(const char *name G_GNUC_UNUSED,
+qemuMonitorJSONCPUPropsFilter(const char *name,
                               virJSONValue *propData,
-                              void *data G_GNUC_UNUSED)
+                              void *opaque)
 {
+    qemuMonitorJSONObjectProperty prop = { .type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN };
+    struct _qemuMonitorJSONCPUPropsFilterData *data = opaque;
+
     if (STRNEQ_NULLABLE(virJSONValueObjectGetString(propData, "type"), "bool"))
         return 1;
 
+    if (qemuMonitorJSONGetObjectProperty(data->mon, data->cpuQOMPath,
+                                         name, &prop) < 0)
+        return -1;
+
+    if (!prop.val.b)
+        return 1;
+
     return 0;
 }
 
@@ -6614,6 +6629,10 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon,
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;
+    struct _qemuMonitorJSONCPUPropsFilterData filterData = {
+        .mon = mon,
+        .cpuQOMPath = cpuQOMPath,
+    };
 
     *props = NULL;
 
@@ -6629,7 +6648,7 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon,
         return 0;
 
     return qemuMonitorJSONParsePropsList(cmd, reply,
-                                         qemuMonitorJSONCPUPropsFilter, NULL,
+                                         qemuMonitorJSONCPUPropsFilter, &filterData,
                                          props);
 }
 
@@ -6640,7 +6659,6 @@ qemuMonitorJSONGetCPUData(qemuMonitor *mon,
                           qemuMonitorCPUFeatureTranslationCallback translate,
                           virCPUData *data)
 {
-    qemuMonitorJSONObjectProperty prop = { .type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN };
     g_auto(GStrv) props = NULL;
     char **p;
 
@@ -6650,12 +6668,6 @@ qemuMonitorJSONGetCPUData(qemuMonitor *mon,
     for (p = props; p && *p; p++) {
         const char *name = *p;
 
-        if (qemuMonitorJSONGetObjectProperty(mon, cpuQOMPath, name, &prop) < 0)
-            return -1;
-
-        if (!prop.val.b)
-            continue;
-
         if (translate)
             name = translate(data->arch, name);
 
-- 
2.51.0