[libvirt] [PATCH v2 03/10] qemu: qapi: Allow selecting specifically optional schema entries in virQEMUQAPISchemaTraverse

Peter Krempa posted 10 patches 4 years, 9 months ago
[libvirt] [PATCH v2 03/10] qemu: qapi: Allow selecting specifically optional schema entries in virQEMUQAPISchemaTraverse
Posted by Peter Krempa 4 years, 9 months ago
Add a new modifier character which will select given schema entry only
when it is optional.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_qapi.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index cd28c69a96..070379b335 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -105,6 +105,7 @@ virQEMUQAPISchemaTraverse(const char *baseName,
                           virHashTablePtr schema)
 {
     virJSONValuePtr base;
+    virJSONValuePtr obj;
     const char *metatype;
     const char *querystr;
     char modifier;
@@ -132,14 +133,20 @@ virQEMUQAPISchemaTraverse(const char *baseName,
             if (!c_isalpha(modifier))
                 querystr++;

-            if (modifier == '+')
+            if (modifier == '+') {
                 baseName = virQEMUQAPISchemaObjectGetType("variants",
                                                           querystr,
                                                           "case", base);
-            else
-                baseName = virQEMUQAPISchemaObjectGetType("members",
-                                                          querystr,
-                                                          "name", base);
+            } else {
+                obj = virQEMUQAPISchemaObjectGet("members", querystr,
+                                                 "name", base);
+
+                if (modifier == '*' &&
+                    !virJSONValueObjectHasKey(obj, "default"))
+                    return NULL;
+
+                baseName = virQEMUQAPISchemaTypeFromObject(obj);
+            }

             if (!baseName)
                 return NULL;
@@ -175,6 +182,7 @@ virQEMUQAPISchemaTraverse(const char *baseName,
  * attribute: selects whether arguments or return type should be introspected
  *            ("arg-type" or "ret-type" for commands, "arg-type" for events)
  * subattribute: specifies member name of object types
+ * *subattribute: same as above but must be optional
  * +variant_discriminator: In the case of unionized objects, select a
  *                         specific case to introspect.
  *
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 03/10] qemu: qapi: Allow selecting specifically optional schema entries in virQEMUQAPISchemaTraverse
Posted by John Ferlan 4 years, 9 months ago

On 08/15/2018 05:18 AM, Peter Krempa wrote:
> Add a new modifier character which will select given schema entry only
> when it is optional.
> 

So when the object has a "*" modifier, then we need to ...?

And the check for the "default" key means what? Is it only ever present
when "*" is the modifier?

I bet I learn in subsequent patches, but I'm going 1 by 1.

> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_qapi.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 

Please just fill in the above details - as it's not "obvious" to this
reader, but I don't believe the code is wrong, so...

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

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