Starting from version 4.1 qemu allows reporting 'features' for a given
QAPI type object. This allows reporting support of fixes and additions
which are otherwise invisible in the QAPI schema.
Implement a possibility to query 'features' in the QAPI query strings.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
src/qemu/qemu_qapi.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index 4ed67b68bc..5e6dab4417 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -109,6 +109,38 @@ virQEMUQAPISchemaTraverse(const char *baseName,
struct virQEMUQAPISchemaTraverseContext *ctxt);
+/**
+ * @featurename: name of 'feature' field to select
+ * @elem: QAPI JSON entry for a type
+ *
+ * Looks for @featurename in the array of 'features' for given type passed in
+ * via @elem. Returns the pointer to the JSON string representing @feature.
+ */
+static int
+virQEMUQAPISchemaTraverseHasObjectFeature(const char *featurename,
+ virJSONValuePtr elem)
+{
+ virJSONValuePtr featuresarray;
+ virJSONValuePtr cur;
+ const char *curstr;
+ size_t i;
+
+ if (!(featuresarray = virJSONValueObjectGetArray(elem, "features")))
+ return 0;
+
+ for (i = 0; i < virJSONValueArraySize(featuresarray); i++) {
+ if (!(cur = virJSONValueArrayGet(featuresarray, i)) ||
+ !(curstr = virJSONValueGetString(cur)))
+ return -2;
+
+ if (STREQ(featurename, curstr))
+ return 1;
+ }
+
+ return 0;
+}
+
+
static int
virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
struct virQEMUQAPISchemaTraverseContext *ctxt)
@@ -124,6 +156,13 @@ virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
if (modifier == '^' || modifier == '!')
return 0;
+ if (modifier == '$') {
+ if (virQEMUQAPISchemaTraverseContextHasNextQuery(ctxt))
+ return -3;
+
+ return virQEMUQAPISchemaTraverseHasObjectFeature(query, cur);
+ }
+
if (modifier == '+') {
obj = virQEMUQAPISchemaObjectGet("variants", query, "case", cur);
} else {
@@ -339,6 +378,8 @@ virQEMUQAPISchemaTraverse(const char *baseName,
* '!basictype': returns true if previously selected type is of 'basictype'
* JSON type. Spported are 'null', 'string', 'number', 'value',
* 'int' and 'boolean.
+ * '$feature': returns true if the previously selected type supports 'feature'
+ * ('feature' is in the 'features' array of given type)
*
* If the name of any (sub)attribute starts with non-alphabetical symbols it
* needs to be prefixed by a single space.
--
2.21.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Jun 18, 2019 at 10:37:25 +0200, Peter Krempa wrote:
> Starting from version 4.1 qemu allows reporting 'features' for a given
> QAPI type object. This allows reporting support of fixes and additions
> which are otherwise invisible in the QAPI schema.
>
> Implement a possibility to query 'features' in the QAPI query strings.
>
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
> src/qemu/qemu_qapi.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
> index 4ed67b68bc..5e6dab4417 100644
> --- a/src/qemu/qemu_qapi.c
> +++ b/src/qemu/qemu_qapi.c
> @@ -109,6 +109,38 @@ virQEMUQAPISchemaTraverse(const char *baseName,
> struct virQEMUQAPISchemaTraverseContext *ctxt);
>
>
> +/**
> + * @featurename: name of 'feature' field to select
> + * @elem: QAPI JSON entry for a type
> + *
> + * Looks for @featurename in the array of 'features' for given type passed in
> + * via @elem. Returns the pointer to the JSON string representing @feature.
Hmm, the function actually returns some magic 0, 1, or -2 values rather
than a pointer to anything. Ah, I see the values are documented for
virQEMUQAPISchemaTraverseFunc function pointer so the values are not
really magic.
> + */
> +static int
> +virQEMUQAPISchemaTraverseHasObjectFeature(const char *featurename,
> + virJSONValuePtr elem)
> +{
> + virJSONValuePtr featuresarray;
> + virJSONValuePtr cur;
> + const char *curstr;
> + size_t i;
> +
> + if (!(featuresarray = virJSONValueObjectGetArray(elem, "features")))
> + return 0;
> +
> + for (i = 0; i < virJSONValueArraySize(featuresarray); i++) {
> + if (!(cur = virJSONValueArrayGet(featuresarray, i)) ||
> + !(curstr = virJSONValueGetString(cur)))
> + return -2;
> +
> + if (STREQ(featurename, curstr))
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> +
With the function documentation fixed...
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Jun 19, 2019 at 12:31:18 +0200, Jiri Denemark wrote: > On Tue, Jun 18, 2019 at 10:37:25 +0200, Peter Krempa wrote: > > Starting from version 4.1 qemu allows reporting 'features' for a given > > QAPI type object. This allows reporting support of fixes and additions > > which are otherwise invisible in the QAPI schema. > > > > Implement a possibility to query 'features' in the QAPI query strings. > > > > Signed-off-by: Peter Krempa <pkrempa@redhat.com> > > --- > > src/qemu/qemu_qapi.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 41 insertions(+) > > > > diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c > > index 4ed67b68bc..5e6dab4417 100644 > > --- a/src/qemu/qemu_qapi.c > > +++ b/src/qemu/qemu_qapi.c > > @@ -109,6 +109,38 @@ virQEMUQAPISchemaTraverse(const char *baseName, > > struct virQEMUQAPISchemaTraverseContext *ctxt); > > > > > > +/** > > + * @featurename: name of 'feature' field to select > > + * @elem: QAPI JSON entry for a type > > + * > > + * Looks for @featurename in the array of 'features' for given type passed in > > + * via @elem. Returns the pointer to the JSON string representing @feature. > > Hmm, the function actually returns some magic 0, 1, or -2 values rather > than a pointer to anything. Ah, I see the values are documented for > virQEMUQAPISchemaTraverseFunc function pointer so the values are not > really magic. Oops, right I forgot to fix docs after I changed the approach how to do it. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.