[PATCH 14/14] qemu: Don't query unavailable-features if qom-list-get is supported

Jiri Denemark via Devel posted 14 patches 3 days, 9 hours ago
[PATCH 14/14] qemu: Don't query unavailable-features if qom-list-get is supported
Posted by Jiri Denemark via Devel 3 days, 9 hours ago
From: Jiri Denemark <jdenemar@redhat.com>

With qom-list-get we already have the value of unavailable-features
property in the returned object (just like we have all values of all
bool properties). Let's use the value from there instead of querying for
it separately using qom-get.

After this patch only a single QMP command is used for getting all the
required info about guest CPUs created by QEMU 10.1 or newer.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor_json.c                  | 32 ++++++++++++++++---
 .../get-guest-cpu-SierraForest.json           | 23 -------------
 .../get-guest-cpu-SkylakeClient.json          | 14 --------
 3 files changed, 27 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f8be1a79b1..9345115241 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6598,6 +6598,7 @@ struct _qemuMonitorJSONCPUPropsFilterData {
     qemuMonitor *mon;
     bool values;
     const char *cpuQOMPath;
+    virJSONValue *unavailableFeatures;
 };
 
 static int
@@ -6607,8 +6608,22 @@ qemuMonitorJSONCPUPropsFilter(const char *name,
 {
     struct _qemuMonitorJSONCPUPropsFilterData *data = opaque;
     bool enabled = false;
+    const char *type = virJSONValueObjectGetString(propData, "type");
 
-    if (STRNEQ_NULLABLE(virJSONValueObjectGetString(propData, "type"), "bool"))
+    if (data->values &&
+        STREQ(name, "unavailable-features") &&
+        STREQ_NULLABLE(type, "strList")) {
+        data->unavailableFeatures = virJSONValueObjectGetArray(propData, "value");
+        if (!data->unavailableFeatures) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("property '%1$s' in reply data was missing value"),
+                           name);
+            return -1;
+        }
+        return 1;
+    }
+
+    if (STRNEQ_NULLABLE(type, "bool"))
         return 1;
 
     if (data->values) {
@@ -6651,6 +6666,7 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon,
         .mon = mon,
         .values = qomListGet,
         .cpuQOMPath = cpuQOMPath,
+        .unavailableFeatures = NULL,
     };
 
     *propsEnabled = NULL;
@@ -6704,10 +6720,16 @@ qemuMonitorJSONGetCPUProperties(qemuMonitor *mon,
                                       &filterData, propsEnabled) < 0)
         return -1;
 
-    if (qemuMonitorJSONGetStringListProperty(mon, cpuQOMPath,
-                                             "unavailable-features",
-                                             propsDisabled) < 0)
-        return -1;
+    if (filterData.unavailableFeatures) {
+        *propsDisabled = virJSONValueArrayToStringList(filterData.unavailableFeatures);
+        if (!*propsDisabled)
+            return -1;
+    } else {
+        if (qemuMonitorJSONGetStringListProperty(mon, cpuQOMPath,
+                                                 "unavailable-features",
+                                                 propsDisabled) < 0)
+            return -1;
+    }
 
     return 0;
 }
diff --git a/tests/qemumonitorjsondata/get-guest-cpu-SierraForest.json b/tests/qemumonitorjsondata/get-guest-cpu-SierraForest.json
index d64ae84532..f5c41cf9b6 100644
--- a/tests/qemumonitorjsondata/get-guest-cpu-SierraForest.json
+++ b/tests/qemumonitorjsondata/get-guest-cpu-SierraForest.json
@@ -2960,26 +2960,3 @@
   ],
   "id": "libvirt-1"
 }
-
-{
-  "execute": "qom-get",
-  "arguments": {
-    "path": "/machine/unattached/device[0]",
-    "property": "unavailable-features"
-  },
-  "id": "libvirt-2"
-}
-
-{
-  "return": [
-    "bus-lock-detect",
-    "cmpccxadd",
-    "avx-ifma",
-    "wbnoinvd",
-    "pbrsb-no",
-    "avx-vnni-int8",
-    "avx-ne-convert",
-    "mcdt-no"
-  ],
-  "id": "libvirt-2"
-}
diff --git a/tests/qemumonitorjsondata/get-guest-cpu-SkylakeClient.json b/tests/qemumonitorjsondata/get-guest-cpu-SkylakeClient.json
index 76b66ded20..b5bea8fd61 100644
--- a/tests/qemumonitorjsondata/get-guest-cpu-SkylakeClient.json
+++ b/tests/qemumonitorjsondata/get-guest-cpu-SkylakeClient.json
@@ -2951,17 +2951,3 @@
   ],
   "id": "libvirt-1"
 }
-
-{
-  "execute": "qom-get",
-  "arguments": {
-    "path": "/machine/unattached/device[0]",
-    "property": "unavailable-features"
-  },
-  "id": "libvirt-2"
-}
-
-{
-  "return": [],
-  "id": "libvirt-2"
-}
-- 
2.51.0