[PATCH v2 4/8] virQEMUQAPISchemaTraverseEnum: Allow query of enume type features

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

 



QEMU-6.2 added feature flags for enum types. Add support for querying
them into our QMP schema query language.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
Reviewed-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_qapi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index 790f7c0fee..426db8d30d 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -242,6 +242,7 @@ virQEMUQAPISchemaTraverseEnum(virJSONValue *cur,
                               struct virQEMUQAPISchemaTraverseContext *ctxt)
 {
     const char *query = virQEMUQAPISchemaTraverseContextNextQuery(ctxt);
+    const char *featurequery = NULL;
     virJSONValue *values;
     virJSONValue *members;
     size_t i;
@@ -249,8 +250,16 @@ virQEMUQAPISchemaTraverseEnum(virJSONValue *cur,
     if (query[0] != '^')
         return 0;

-    if (virQEMUQAPISchemaTraverseContextHasNextQuery(ctxt))
-        return -3;
+    if (virQEMUQAPISchemaTraverseContextHasNextQuery(ctxt)) {
+        /* we might have a query for a feature flag of an enum value */
+        featurequery = virQEMUQAPISchemaTraverseContextNextQuery(ctxt);
+
+        if (*featurequery != '$' ||
+            virQEMUQAPISchemaTraverseContextHasNextQuery(ctxt))
+            return -3;
+
+        featurequery++;
+    }

     query++;

@@ -263,13 +272,21 @@ virQEMUQAPISchemaTraverseEnum(virJSONValue *cur,
             if (!member || !(name = virJSONValueObjectGetString(member, "name")))
                 return -2;

-            if (STREQ(name, query))
+            if (STREQ(name, query)) {
+                if (featurequery)
+                    return virQEMUQAPISchemaTraverseHasObjectFeature(featurequery, member);
+
                 return 1;
+            }
         }

         return 0;
     }

+    /* old-style "values" array doesn't have feature flags so any query is necessarily false */
+    if (featurequery)
+        return 0;
+
     if (!(values = virJSONValueObjectGetArray(cur, "values")))
         return -2;

@@ -439,7 +456,8 @@ virQEMUQAPISchemaTraverse(const char *baseName,
  *
  * The above types can be chained arbitrarily using slashes to construct any
  * path into the schema tree, booleans must be always the last component as they
- * don't refer to a type.
+ * don't refer to a type. An exception is querying feature of an enum value
+ * (.../^enumval/$featurename) which is allowed.
  *
  * Returns 1 if @query was found in @schema filling @entry if non-NULL, 0 if
  * @query was not found in @schema and -1 on other errors along with an appropriate
-- 
2.31.1




[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