1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virQEMUQAPISchemaTraverseEnum: Allow query of enume type features

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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-09-20 15:22:36 +02:00
parent 2827c411c2
commit 626b53ba9b

View File

@ -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