file-posix: Add dynamic-auto-read-only QAPI feature
cover file-posix: Add dynamic-auto-read-only QAPI feature
This series adds optional feature lists to struct definitions in the QAPI schema and makes use of them to advertise the new behaviour of auto-read-only=on in file-posix.
Kevin Wolf (4):
qapi: Support features for structs tests/qapi-schema: Test for good feature lists in structs tests/qapi-schema: Error case tests for features in structs
file-posix: Add dynamic-auto-read-only QAPI feature
qapi/block-core.json | 11 ++++- qapi/introspect.json | 8 ++- tests/qapi-schema/features-bad-type.json | 3 ++ tests/qapi-schema/features-missing-name.json | 3 ++ tests/qapi-schema/features-name-bad-type.json | 3 ++ tests/qapi-schema/features-no-list.json | 3 ++ tests/qapi-schema/features-unknown-key.json | 3 ++ tests/qapi-schema/qapi-schema-test.json | 27 ++++++++++ docs/devel/qapi-code-gen.txt | 38 ++++++++++++++ scripts/qapi/common.py | 49 +++++++++++++++---- scripts/qapi/doc.py | 3 +- scripts/qapi/introspect.py | 6 ++- scripts/qapi/types.py | 3 +- scripts/qapi/visit.py | 3 +- tests/Makefile.include | 5 ++ tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/features-bad-type.err | 1 + tests/qapi-schema/features-bad-type.exit | 1 + tests/qapi-schema/features-bad-type.out | 0 tests/qapi-schema/features-missing-name.err | 1 + tests/qapi-schema/features-missing-name.exit | 1 + tests/qapi-schema/features-missing-name.out | 0 tests/qapi-schema/features-name-bad-type.err | 1 + tests/qapi-schema/features-name-bad-type.exit | 1 + tests/qapi-schema/features-name-bad-type.out | 0 tests/qapi-schema/features-no-list.err | 1 + tests/qapi-schema/features-no-list.exit | 1 + tests/qapi-schema/features-no-list.out | 0 tests/qapi-schema/features-unknown-key.err | 2 + tests/qapi-schema/features-unknown-key.exit | 1 + tests/qapi-schema/features-unknown-key.out | 0 tests/qapi-schema/qapi-schema-test.out | 26 ++++++++++ tests/qapi-schema/test-qapi.py | 7 ++- tests/qapi-schema/unknown-expr-key.err | 2 +- 34 files changed, 197 insertions(+), 19 deletions(-) create mode 100644 tests/qapi-schema/features-bad-type.json create mode 100644 tests/qapi-schema/features-missing-name.json create mode 100644 tests/qapi-schema/features-name-bad-type.json create mode 100644 tests/qapi-schema/features-no-list.json create mode 100644 tests/qapi-schema/features-unknown-key.json create mode 100644 tests/qapi-schema/features-bad-type.err create mode 100644 tests/qapi-schema/features-bad-type.exit create mode 100644 tests/qapi-schema/features-bad-type.out create mode 100644 tests/qapi-schema/features-missing-name.err create mode 100644 tests/qapi-schema/features-missing-name.exit create mode 100644 tests/qapi-schema/features-missing-name.out create mode 100644 tests/qapi-schema/features-name-bad-type.err create mode 100644 tests/qapi-schema/features-name-bad-type.exit create mode 100644 tests/qapi-schema/features-name-bad-type.out create mode 100644 tests/qapi-schema/features-no-list.err create mode 100644 tests/qapi-schema/features-no-list.exit create mode 100644 tests/qapi-schema/features-no-list.out create mode 100644 tests/qapi-schema/features-unknown-key.err create mode 100644 tests/qapi-schema/features-unknown-key.exit create mode 100644 tests/qapi-schema/features-unknown-key.out
Signature · 1 line
2.20.1
PATCH 1/4 qapi: Support features for structs
Sometimes, the behaviour of QEMU changes compatibly, but without a change in the QMP syntax (usually by allowing values or operations that previously resulted in an error). QMP clients may still need to know whether the extension is available.
This allows to add a list of features to struct definitions that will be made visible to QMP clients through schema introspection.
--- qapi/introspect.json | 8 ++++- docs/devel/qapi-code-gen.txt | 38 ++++++++++++++++++++ scripts/qapi/common.py | 49 ++++++++++++++++++++------ scripts/qapi/doc.py | 3 +- scripts/qapi/introspect.py | 6 +++- scripts/qapi/types.py | 3 +- scripts/qapi/visit.py | 3 +- tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/test-qapi.py | 3 +- tests/qapi-schema/unknown-expr-key.err | 2 +- 10 files changed, 99 insertions(+), 18 deletions(-)
qapi/introspect.json +7 -1
@@ -174,6 +174,11 @@ # and may even differ from the order of the values of the # enum type of the @tag. # +# @features: names of features that are supported by this version and build and +# aren't othervise visible through schema introspection (e.g. change +# of behaviour related to an object type that didn't come with a +# syntactic change in the schema of the object type) (since: 4.1) +# # Values of this type are JSON object on the wire. # # Since: 2.5
@@ -181,7 +186,8 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ], + '*features': [ 'str' ] } } ## # @SchemaInfoObjectMember:
docs/devel/qapi-code-gen.txt +38 -0
@@ -719,6 +719,34 @@ any non-empty complex type (struct, union, or alternate), and a pointer to that QAPI type is passed as a single argument. +=== Features === + +Sometimes, the behaviour of QEMU changes compatibly, but without a +change in the QMP syntax (usually by allowing values or operations that +previously resulted in an error). QMP clients may still need to know +whether the extension is available. + +For this purpose, a list of features can be specified for a struct type. +This is exposed to the client as a list of string, where each string +signals that this build of QEMU shows a certain behaviour. + +In the schema, features can be specified as simple strings, for example: + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ 'allow-negative-numbers' ] } + +Another option is to specify features as dictionaries, where the key +'name' specifies the feature string to be exposed to clients: + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ { 'name': 'allow-negative-numbers' } ] } + +This expanded form is necessary if you want to make the feature +conditional (see below in "Configuring the schema"). + + === Downstream extensions === QAPI schema names that are externally visible, say in the Client JSON
@@ -771,6 +799,16 @@ Example: a conditional 'bar' enum member. [ 'foo', { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } +Similarly, features can be specified as a dictionary with a 'name' and +an 'if' key. + +Example: a conditional 'allow-negative-numbers' feature + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ { 'name': 'allow-negative-numbers', + 'if' 'defined(IFCOND)' } ] } + Please note that you are responsible to ensure that the C code will compile with an arbitrary combination of conditions, since the generators are unable to check it at this point.
scripts/qapi/common.py +39 -10
127 lines not on this page · raw message
scripts/qapi/doc.py +2 -1
@@ -220,7 +220,8 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): body=texi_entity(doc, 'Values', ifcond, member_func=texi_enum_value))) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): doc = self.cur_doc if base and base.is_implicit(): base = None
scripts/qapi/introspect.py +5 -1
@@ -188,11 +188,15 @@ const QLitObject %(c_name)s = %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, ifcond) - def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): obj = {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) + if features: + obj['features'] = [ (f['name'], f) for f in features ] + self._gen_qlit(name, 'object', obj, ifcond) def visit_alternate_type(self, name, info, ifcond, variants):
scripts/qapi/types.py +2 -1
@@ -227,7 +227,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): # Nothing to do for the special empty builtin if name == 'q_empty': return
scripts/qapi/visit.py +2 -1
@@ -326,7 +326,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): # Nothing to do for the special empty builtin if name == 'q_empty': return
tests/qapi-schema/double-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' -Valid keys are 'base', 'data', 'if', 'struct'. +Valid keys are 'base', 'data', 'features', 'if', 'struct'.
tests/qapi-schema/test-qapi.py +2 -1
@@ -38,7 +38,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('array %s %s' % (name, element_type.name)) self._print_if(ifcond) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): print('object %s' % name) if base: print(' base %s' % base.name)
tests/qapi-schema/unknown-expr-key.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/unknown-expr-key.json:2: Unknown keys 'bogus', 'phony' in struct 'bar' -Valid keys are 'base', 'data', 'if', 'struct'. +Valid keys are 'base', 'data', 'features', 'if', 'struct'.
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
Quoted 7 lines · Kevin Wolf
Sometimes, the behaviour of QEMU changes compatibly, but without a change in the QMP syntax (usually by allowing values or operations that previously resulted in an error). QMP clients may still need to know whether the extension is available.
This allows to add a list of features to struct definitions that will be made visible to QMP clients through schema introspection.
Only a first step, but that's okay. I think we want to be able to tack features to all user-defined types, commands, and events. Ideally even to members of enum and object types.
Use case: feature 'deprecated'. We talked about ways to communicate deprecation to management applications. Introspection was proposed. Feature 'deprecated' delivers it.
Quoted 45 lines
Signed-off-by Kevin Wolf <[email protected]>--- qapi/introspect.json | 8 ++++- docs/devel/qapi-code-gen.txt | 38 ++++++++++++++++++++ scripts/qapi/common.py | 49 ++++++++++++++++++++------ scripts/qapi/doc.py | 3 +- scripts/qapi/introspect.py | 6 +++- scripts/qapi/types.py | 3 +- scripts/qapi/visit.py | 3 +- tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/test-qapi.py | 3 +- tests/qapi-schema/unknown-expr-key.err | 2 +- 10 files changed, 99 insertions(+), 18 deletions(-)qapi/introspect.json +7
-1@@ -174,6 +174,11 @@ # and may even differ from the order of the values of the # enum type of the @tag. # +# @features: names of features that are supported by this version and build and +# aren't othervise visible through schema introspection (e.g. change +# of behaviour related to an object type that didn't come with a +# syntactic change in the schema of the object type) (since: 4.1) +# # Values of this type are JSON object on the wire. # # Since: 2.5@@ -181,7 +186,8 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ], + '*features': [ 'str' ] } } ## # @SchemaInfoObjectMember:docs/devel/qapi-code-gen.txt +0
-0
docs/devel/qapi-code-gen.txt any non-empty complex type (struct, union, or alternate), and a · line 722
Quoted 4 lines
docs/devel/qapi-code-gen.txt +1
-0@@ -719,6 +719,34 @@ any non-empty complex type (struct, union, or alternate), and a pointer to that QAPI type is passed as a single argument. +=== Features ===
This bolts on features similar to how we bolted on conditionals. Minimally invasive, but the result is suboptimal. It'll do for now.
Quoted 15 lines
docs/devel/qapi-code-gen.txt +15
-0+ +Sometimes, the behaviour of QEMU changes compatibly, but without a +change in the QMP syntax (usually by allowing values or operations that +previously resulted in an error). QMP clients may still need to know +whether the extension is available. + +For this purpose, a list of features can be specified for a struct type. +This is exposed to the client as a list of string, where each string +signals that this build of QEMU shows a certain behaviour. + +In the schema, features can be specified as simple strings, for example: + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ 'allow-negative-numbers' ] }
docs/devel/qapi-code-gen.txt any non-empty complex type (struct, union, or alternate), and a · line 747
Quoted 10 lines
docs/devel/qapi-code-gen.txt +10
-0+ +Another option is to specify features as dictionaries, where the key +'name' specifies the feature string to be exposed to clients: + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ { 'name': 'allow-negative-numbers' } ] } + +This expanded form is necessary if you want to make the feature +conditional (see below in "Configuring the schema").
You justify the general form with a forward reference. I guess that's the best you can do without reorganizing the document. Let's worry about that later.
docs/devel/qapi-code-gen.txt Example: a conditional 'bar' enum member.
Quoted 6 lines
docs/devel/qapi-code-gen.txt +2
-0+ + === Downstream extensions === QAPI schema names that are externally visible, say in the Client JSON@@ -771,6 +799,16 @@ Example: a conditional 'bar' enum member.
Example: a conditional 'bar' enum member.
{ 'enum': 'IfEnum', 'data':
docs/devel/qapi-code-gen.txt Example: a conditional 'bar' enum member. · line 811
Quoted 13 lines
docs/devel/qapi-code-gen.txt +10
-0[ 'foo', { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } +Similarly, features can be specified as a dictionary with a 'name' and +an 'if' key. + +Example: a conditional 'allow-negative-numbers' feature + +{ 'struct': 'TestType', + 'data': { 'number': 'int' }, + 'features': [ { 'name': 'allow-negative-numbers', + 'if' 'defined(IFCOND)' } ] } +
Note the structure of enum's 'data' is identical to struct's 'features'. We'll get back to that below.
Quoted 24 lines
docs/devel/qapi-code-gen.txt +0
-0Please note that you are responsible to ensure that the C code will compile with an arbitrary combination of conditions, since the generators are unable to check it at this point.scripts/qapi/common.py +7
-0@@ -886,12 +886,29 @@ def check_enum(expr, info): def check_struct(expr, info): name = expr['struct'] members = expr['data'] + features = expr.get('features') check_type(info, "'data' for struct '%s'" % name, members, allow_dict=True, allow_optional=True) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct']) + if features: + if not isinstance(features, list): + raise QAPISemError(info, + "Struct '%s' requires an array for 'features'" % + name) + for f in features:
scripts/qapi/common.py def check_enum(expr, info): · line 911
Quoted 10 lines
scripts/qapi/common.py +10
-0+ assert isinstance(f, dict) + check_known_keys(info, "feature of struct %s" % (name), f, + ['name'], ['if']) + + check_if(f, info) + f['if'] = listify_cond(f.get('if')) + + if not isinstance(f['name'], str): + raise QAPISemError(info, "Feature names for struct '%s' must " + "be strings" % name)
Duplicates much of check_enum(). That's because the list of features has the same structure as the list of enumeration values. We can worry about avoiding duplication later.
Let's examine the differences to check_enum().
check_enum() additionally checks prefix, which we don't have here.
check_enum() checks member names with check_name(). Here, we check only "feature name is str". I think requiring feature names to conform to the common rules for QAPI names would be prudent. Let's call check_name().
check_enum() doesn't call listify_cond(). Only QAPISchemaFOO methods do. I think it should be called in QAPISchemaObjectType.__init__() instead. See there.
scripts/qapi/common.py def normalize_members(members): · line 970
Quoted 11 lines
scripts/qapi/common.py +4
-0def check_known_keys(info, source, keys, required, optional):@@ -947,6 +964,10 @@ def normalize_members(members): continue members[key] = {'type': arg} +def normalize_features(features): + if isinstance(features, list): + features[:] = [f if isinstance(f, dict) else {'name': f} + for f in features]
Duplicates much of normalize_enum() for the same reason.
Quoted 40 lines
scripts/qapi/common.py +8
-4def check_exprs(exprs): global all_names@@ -986,8 +1007,10 @@ def check_exprs(exprs): normalize_members(expr['data']) elif 'struct' in expr: meta = 'struct' - check_keys(expr_elem, 'struct', ['data'], ['base', 'if']) + check_keys(expr_elem, 'struct', ['data'], + ['base', 'if', 'features']) normalize_members(expr['data']) + normalize_features(expr.get('features')) struct_types[expr[meta]] = expr elif 'command' in expr: meta = 'command'@@ -1126,10 +1149,12 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, ifcond, element_type): pass - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): pass - def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): pass def visit_alternate_type(self, name, info, ifcond, variants):@@ -1290,7 +1315,7 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, doc, ifcond, - base, local_members, variants): + base, local_members, variants, features): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base
scripts/qapi/common.py class QAPISchemaObjectType(QAPISchemaType): · line 1335
Quoted 4 lines
scripts/qapi/common.py +1
-0@@ -1307,6 +1332,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.local_members = local_members self.variants = variants self.members = None + self.features = features
I think this should be
self.features = listify_cond(features)
Quoted 18 lines
scripts/qapi/common.py +4
-2def check(self, schema): QAPISchemaType.check(self, schema)@@ -1368,9 +1394,11 @@ class QAPISchemaObjectType(QAPISchemaType): def visit(self, visitor): visitor.visit_object_type(self.name, self.info, self.ifcond, - self.base, self.local_members, self.variants) + self.base, self.local_members, self.variants, + self.features) visitor.visit_object_type_flat(self.name, self.info, self.ifcond, - self.members, self.variants) + self.members, self.variants, + self.features) class QAPISchemaMember(object):
scripts/qapi/common.py class QAPISchema(object): · line 1706
Quoted 5 lines
scripts/qapi/common.py +1
-1@@ -1675,7 +1703,7 @@ class QAPISchema(object): ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type = QAPISchemaObjectType( - 'q_empty', None, None, None, None, [], None) + 'q_empty', None, None, None, None, [], None, [])
The built-in empty object has no features. Good.
scripts/qapi/common.py class QAPISchema(object): · line 1752
Quoted 9 lines
scripts/qapi/common.py +1
-1self._def_entity(self.the_empty_object_type) qtypes = ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist',@@ -1721,7 +1749,7 @@ class QAPISchema(object): assert ifcond == typ._ifcond # pylint: disable=protected-access else: self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, - None, members, None)) + None, members, None, []))
Implicit object types have no features. These are:
* Simple union variant wrapper types
The wrapped type can carry the feature
* Flat union's anonymous base type
If you want features, use a named type.
* Command's anonymous parameter type
Likewise.
* Event's anonymous parameter type
Likewise.
Okay.
scripts/qapi/common.py class QAPISchema(object): · line 1786
Quoted 12 lines
scripts/qapi/common.py +2
-1return name def _def_enum_type(self, expr, info, doc):@@ -1752,9 +1780,10 @@ class QAPISchema(object): base = expr.get('base') data = expr['data'] ifcond = expr.get('if') + features = expr.get('features') self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, base, self._make_members(data, info), - None)) + None, features))
This is struct. Okay.
For enum, we do:
self._def_entity(QAPISchemaEnumType(
name, info, doc, ifcond, self._make_enum_members(data), prefix))
where
def _make_enum_members(self, values):
return [QAPISchemaMember(v['name'], v.get('if')) for v in values]
i.e. we represent the enum members as a list of QAPISchemaMember.
Features remain a list of dicts.
Any particular reason for not making them QAPISchemaMember?
scripts/qapi/common.py class QAPISchema(object): · line 1827
Quoted 9 lines
scripts/qapi/common.py +1
-1def _make_variant(self, case, typ, ifcond): return QAPISchemaObjectTypeVariant(case, typ, ifcond)@@ -1795,7 +1824,7 @@ class QAPISchema(object): QAPISchemaObjectType(name, info, doc, ifcond, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, - variants))) + variants), []))
This is union. We clearly want to support features there. This patch only implements them for struct. That's okay, we don't need to implement them everywhere we want them in one go.
Quoted 24 lines
scripts/qapi/common.py +0
-0def _def_alternate_type(self, expr, info, doc): name = expr['alternate']scripts/qapi/doc.py +2
-1@@ -220,7 +220,8 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): body=texi_entity(doc, 'Values', ifcond, member_func=texi_enum_value))) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): doc = self.cur_doc if base and base.is_implicit(): base = Nonescripts/qapi/introspect.py +0
-0@@ -188,11 +188,15 @@ const QLitObject %(c_name)s = %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, ifcond)
scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 198
Quoted 10 lines
scripts/qapi/introspect.py +4
-1- def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): obj = {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) + if features: + obj['features'] = [ (f['name'], f) for f in features ]
Compare:
def visit_enum_type(self, name, info, ifcond, members, prefix):
self._gen_qlit(name, 'enum',
{'values':
[(m.name, {'if': m.ifcond}) for m in members]},
ifcond)Since f is a dict, not an object, we need to use f['name'].
Since f is a dict, abusing it as the tuple's second element works.
Cleaner: (f['name'], {'if': f['if']})
Quoted 45 lines
scripts/qapi/introspect.py +1
-0+ self._gen_qlit(name, 'object', obj, ifcond) def visit_alternate_type(self, name, info, ifcond, variants):scripts/qapi/types.py +2
-1@@ -227,7 +227,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): # Nothing to do for the special empty builtin if name == 'q_empty': returnscripts/qapi/visit.py +2
-1@@ -326,7 +326,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): # Nothing to do for the special empty builtin if name == 'q_empty': returntests/qapi-schema/double-type.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' -Valid keys are 'base', 'data', 'if', 'struct'. +Valid keys are 'base', 'data', 'features', 'if', 'struct'.tests/qapi-schema/test-qapi.py +0
-0
tests/qapi-schema/test-qapi.py class QAPISchemaTestVisitor(QAPISchemaVisitor): · line 45
Quoted 9 lines
tests/qapi-schema/test-qapi.py +2
-1@@ -38,7 +38,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('array %s %s' % (name, element_type.name)) self._print_if(ifcond) - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): print('object %s' % name) if base: print(' base %s' % base.name)
Print the features, please. Steal the code from visit_enum_type().
tests/qapi-schema/unknown-expr-key.err line 2
Quoted 8 lines
tests/qapi-schema/unknown-expr-key.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/unknown-expr-key.json:2: Unknown keys 'bogus', 'phony' in struct 'bar' -Valid keys are 'base', 'data', 'if', 'struct'. +Valid keys are 'base', 'data', 'features', 'if', 'struct'.
Missing tests. Ah, I see these are in the next patches, nevermind.
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
Am 18.04.2019 um 22:03 hat Markus Armbruster geschrieben:
Quoted 10 lines
Quoted 7 lines · Kevin Wolf
Sometimes, the behaviour of QEMU changes compatibly, but without a change in the QMP syntax (usually by allowing values or operations that previously resulted in an error). QMP clients may still need to know whether the extension is available.
This allows to add a list of features to struct definitions that will be made visible to QMP clients through schema introspection.
Quoted 7 lines
Only a first step, but that's okay. I think we want to be able to tack features to all user-defined types, commands, and events. Ideally even to members of enum and object types.
Use case: feature 'deprecated'. We talked about ways to communicate deprecation to management applications. Introspection was proposed. Feature 'deprecated' delivers it.
How does introspection solve the problem? It requires the client to actively look for a deprecation instead of notifying it that it is using something deprecated.
Do you expect libvirt to check a full list of all QMP commands, types, etc. it ever uses against the schema after starting a VM or something like that?
Quoted 46 lines
Quoted 39 lines
def
check_exprs(exprs):
globalall_namesscripts/qapi/common.py +8
-4@@ -986,8 +1007,10 @@ def check_exprs(exprs): normalize_members(expr['data']) elif 'struct' in expr: meta = 'struct' - check_keys(expr_elem, 'struct', ['data'], ['base', 'if']) + check_keys(expr_elem, 'struct', ['data'], + ['base', 'if', 'features']) normalize_members(expr['data']) + normalize_features(expr.get('features')) struct_types[expr[meta]] = expr elif 'command' in expr: meta = 'command'@@ -1126,10 +1149,12 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, ifcond, element_type): pass - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): pass - def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): pass def visit_alternate_type(self, name, info, ifcond, variants):@@ -1290,7 +1315,7 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, doc, ifcond, - base, local_members, variants): + base, local_members, variants, features): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no basescripts/qapi/common.py class QAPISchemaObjectType(QAPISchemaType): · line 1335
Quoted 4 lines
scripts/qapi/common.py +1
-0@@ -1307,6 +1332,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.local_members = local_members self.variants = variants self.members = None + self.features = featuresI think this should be
Quoted 1 line
self.features =
listify_cond(features)
Not quite, listify_cond() takes the condition it, not the entity that contains it. But I can do this:
self.features = features
for f in self.features or []:
f['if'] = listify_cond(f.get('if'))Quoted 20 lines
scripts/qapi/common.py class QAPISchema(object): · line 1786
Quoted 9 lines
scripts/qapi/common.py +2
-1@@ -1752,9 +1780,10 @@ class QAPISchema(object): base = expr.get('base') data = expr['data'] ifcond = expr.get('if') + features = expr.get('features') self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, base, self._make_members(data, info), - None)) + None, features))This is struct. Okay.
For enum, we do:
self._def_entity(QAPISchemaEnumType(
name, info, doc, ifcond,self._make_enum_members(data), prefix))where
Quoted 8 lines
def
_make_enum_members(self, values):
return [QAPISchemaMember(v['name'], v.get('if'))for v in values]i.e. we represent the enum members as a list of QAPISchemaMember.
Features remain a list of dicts.
Any particular reason for not making them QAPISchemaMember?
I don't know what QAPISchemaMember is, and the documentation doesn't tell me either. Its code looks related to generated C code, but features don't generate C code.
I guess I could use it anyway and just never call any of its methods but just use it to store things in attributes rather than dict entries, but somehow creating an object and not making use of anything the class provides feels like abuse.
Maybe I could be convinced otherwise if you suggest a docstring to add to the QAPISchemaMember class that explains for which cases it is meant.
Quoted 26 lines
Quoted 7 lines
scripts/qapi/introspect.py +0
-0@@ -188,11 +188,15 @@ const QLitObject %(c_name)s = %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, ifcond)scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 198
Quoted 10 lines
scripts/qapi/introspect.py +4
-1- def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): obj = {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) + if features: + obj['features'] = [ (f['name'], f) for f in features ]Compare:
def visit_enum_type(self, name, info, ifcond, members, prefix): self._gen_qlit(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, ifcond)
Quoted 4 lines
Since f is a dict, not an object, we need to use f['name'].
Since f is a dict, abusing it as the tuple's second element works.
Cleaner: (f['name'], {'if': f['if']})
to_qlit() doesn't document what it expects for obj. From the code, if it's a tuple, the first item is the content to generate and the second item is a dict 'extra' that contains additional information. The 'if' and 'comment' keys in it are used, the rest is silently ignored.
f is already a dict that satisfies the expectations of the to_qlit() interface, so it feels unnecessary to duplicate it. But if we really do want to duplicate it, it would look like this:
if features:
obj['features'] = [ (f['name'],
{'if': f['if']} if 'if' in f else {})
for f in features ]Or we could pull the condition one level up:
if features:
obj['features'] = [ (f['name'], {'if': f['if']})
if 'if' in f else f['name'] for f in features ]
I don't consider either way very readable compared to what I currently have, but I'll make the change if you insist on it.
Kevin
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
Quoted 15 lines · Kevin Wolf
Am 18.04.2019 um 22:03 hat Markus Armbruster geschrieben:
Quoted 14 lines
Quoted 7 lines · Kevin Wolf
Sometimes, the behaviour of QEMU changes compatibly, but without a change in the QMP syntax (usually by allowing values or operations that previously resulted in an error). QMP clients may still need to know whether the extension is available.
This allows to add a list of features to struct definitions that will be made visible to QMP clients through schema introspection.
Only a first step, but that's okay. I think we want to be able to tack features to all user-defined types, commands, and events. Ideally even to members of enum and object types.
Quoted 7 lines
Quoted 3 lines
Use case: feature 'deprecated'. We talked about ways to communicate deprecation to management applications. Introspection was proposed. Feature 'deprecated' delivers it.
How does introspection solve the problem? It requires the client to actively look for a deprecation instead of notifying it that it is using something deprecated.
Well, we can actively poll ..
Quoted 3 lines
Do you expect libvirt to check a full list of all QMP commands, types, etc. it ever uses against the schema after starting a VM or something like that?
.. similarly to how we asked to be put on the reviewer list for the deprecated.
We an use our test data which we gather from qemu periodically which include the QMP schema to extract the list of deprecated features and store them in git. If we bump the test data and a new deprecated entry appears the developers will need to asses whether it's used or not and take the appropriate action.
The appropriate action may also include deriving a capability information from it and use it to alter libvirt's behaviour which would then be queried at startup of the VM, but mostly we want to use the new approach which will replace given deprecated feature as soon as it's available.
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
In reply to Kevin WolfQuoted 19 lines · Kevin Wolf
Am 18.04.2019 um 22:03 hat Markus Armbruster geschrieben:
Quoted 10 lines
Quoted 7 lines · Kevin Wolf
Sometimes, the behaviour of QEMU changes compatibly, but without a change in the QMP syntax (usually by allowing values or operations that previously resulted in an error). QMP clients may still need to know whether the extension is available.
This allows to add a list of features to struct definitions that will be made visible to QMP clients through schema introspection.
Quoted 7 lines
Only a first step, but that's okay. I think we want to be able to tack features to all user-defined types, commands, and events. Ideally even to members of enum and object types.
Use case: feature 'deprecated'. We talked about ways to communicate deprecation to management applications. Introspection was proposed. Feature 'deprecated' delivers it.
Quoted 7 lines
How does introspection solve the problem? It requires the client to actively look for a deprecation instead of notifying it that it is using something deprecated.
Do you expect libvirt to check a full list of all QMP commands, types, etc. it ever uses against the schema after starting a VM or something like that?
I'm merely responding to demand.
Subject: Minutes of KVM Forum BoF on deprecating stuff
Message-ID: <[email protected]>
* We need to communicate "you're using something that is deprecated". How? Right now, we print a deprecation message. Okay when humans use QEMU directly in a shell. However, when QEMU sits at the bottom of a software stack, the message will likely end up in a log file that is effectively write-only.
- The one way to get people read log files is crashing their application. A command line option --future could make QEMU crash right after printing a deprecation message. This could help with finding use of deprecated features in a testing environment.
- A less destructive way to grab people's attention is to make things run really, really slow: have QEMU go to sleep for a while after printing a deprecation message.
- We can also pass the buck to the next layer up: emit a QMP event.
Sadly, by the time the next layer connects to QMP, plenty of stuff already happened. We'd have to buffer deprecation events somehow.
What would libvirt do with such an event? Log it, taint the domain, emit a (libvirt) event to pass it on to the next layer up.
- A completely different idea is to have a configuratin linter. To support doing this at the libvirt level, QEMU could expose "is deprecated" in interface introspection. Feels feasible for QMP, where we already have sufficiently expressive introspection. For CLI, we'd first have to provide that (but we want that anyway).
- We might also want to dispay deprecation messages in QEMU's GUI somehow, or on serial consoles.
Second to last item.
Quoted 80 lines
Quoted 46 lines
Quoted 39 lines
def
check_exprs(exprs):
globalall_namesscripts/qapi/common.py +8
-4@@ -986,8 +1007,10 @@ def check_exprs(exprs): normalize_members(expr['data']) elif 'struct' in expr: meta = 'struct' - check_keys(expr_elem, 'struct', ['data'], ['base', 'if']) + check_keys(expr_elem, 'struct', ['data'], + ['base', 'if', 'features']) normalize_members(expr['data']) + normalize_features(expr.get('features')) struct_types[expr[meta]] = expr elif 'command' in expr: meta = 'command'@@ -1126,10 +1149,12 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, ifcond, element_type): pass - def visit_object_type(self, name, info, ifcond, base, members, variants): + def visit_object_type(self, name, info, ifcond, base, members, variants, + features): pass - def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): pass def visit_alternate_type(self, name, info, ifcond, variants):@@ -1290,7 +1315,7 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, doc, ifcond, - base, local_members, variants): + base, local_members, variants, features): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no basescripts/qapi/common.py class QAPISchemaObjectType(QAPISchemaType): · line 1335
Quoted 4 lines
scripts/qapi/common.py +1
-0@@ -1307,6 +1332,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.local_members = local_members self.variants = variants self.members = None + self.features = featuresI think this should be
Quoted 1 line
self.features =
listify_cond(features)Not quite,
listify_cond()takes the condition it, not the entity that contains it. But I can do this:self.features = features for f in self.features or []: f['if'] = listify_cond(f.get('if'))Quoted 25 lines
scripts/qapi/common.py class QAPISchema(object): · line 1786
Quoted 9 lines
scripts/qapi/common.py +2
-1@@ -1752,9 +1780,10 @@ class QAPISchema(object): base = expr.get('base') data = expr['data'] ifcond = expr.get('if') + features = expr.get('features') self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, base, self._make_members(data, info), - None)) + None, features))This is struct. Okay.
For enum, we do:
self._def_entity(QAPISchemaEnumType(
name, info, doc, ifcond,self._make_enum_members(data), prefix))where
def
_make_enum_members(self, values):
return [QAPISchemaMember(v['name'], v.get('if'))for v in values]i.e. we represent the enum members as a list of QAPISchemaMember.
Quoted 7 lines
Quoted 3 lines
Features remain a list of dicts.
Any particular reason for not making them QAPISchemaMember?
I don't know what QAPISchemaMember is, and the documentation doesn't tell me either. Its code looks related to generated C code, but features don't generate C code.
QAPISchemaMember (and all of the QAPISchemaFOO) are not about generating C code.
QAPISchema is the intermediate representation. It uses the QAPISchemaFOO to represent schema entities.
QAPISchemaMember is what enum members and object members have in common. For Enum members, the common stuff is all there is, and that's why they're represented as QAPISchemaMember. Object members are more complex, and that's why they're represented as QAPISchemaObjectTypeMember, subtype of QAPISchemaMember.
QAPISchema provides three services:
* Looking up schema identities by name (public methods .lookup_entity(), .lookup_type()).
* Semantic checker (public method .check()). Delegates checking the parts to the QAPISchemaFOO. QAPISchemaMember.check_clash() is part of this.
* Walking the IR (public method .visit()). Delegates walking parts to the QAPISchemaFOO. QAPISchemaMember has no code for this purpose, because it has no parts to walk.
QAPISchema is related to generating C only by .visit() getting used by the code generating C.
Some QAPISchemaFOO are additionally related by providing it helpers such as QAPISchemaType.c_type(). QAPISchemaMember provides no such helper.
So, QAPISchemaMember serves just two purposes:
* Represent an enum member or (the common part of) an object type member
Method __init__().
* Check this enum member or (the common part of) this object type member
All the other code.
What is checked? Naming rules and name clashes with sibling members.
The simplest case is actually the one closest to features: rejecting duplicate enum members (as in tests/qapi-schema/enum-clash-member.json). See use of QAPISchemaMember.check_clash() in QAPISchemaEnumType.check().
By the way, that case is missing from your tests :)
Quoted 4 lines
I guess I could use it anyway and just never call any of its methods but just use it to store things in attributes rather than dict entries, but somehow creating an object and not making use of anything the class provides feels like abuse.
Add the test case, and you'll likely want to use its .check_clash() method :)
Quoted 2 lines
Maybe I could be convinced otherwise if you suggest a docstring to add to the QAPISchemaMember class that explains for which cases it is meant.
Yes, scripts/qapi/ is under-documented. Technical debt. We all try to pay it back when we can, and avoid incurring more, but we don't always succeed.
Quoted 28 lines
Quoted 28 lines
Quoted 7 lines
scripts/qapi/introspect.py +0
-0@@ -188,11 +188,15 @@ const QLitObject %(c_name)s = %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, ifcond)scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 198
Quoted 10 lines
scripts/qapi/introspect.py +4
-1- def visit_object_type_flat(self, name, info, ifcond, members, variants): + def visit_object_type_flat(self, name, info, ifcond, members, variants, + features): obj = {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) + if features: + obj['features'] = [ (f['name'], f) for f in features ]Compare:
def visit_enum_type(self, name, info, ifcond, members, prefix): self._gen_qlit(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, ifcond)Since f is a dict, not an object, we need to use f['name'].
Quoted 7 lines
Quoted 2 lines
Since f is a dict, abusing it as the tuple's second element works.
Cleaner: (f['name'], {'if': f['if']})
to_qlit()doesn't document what it expects for obj. From the code, if it's a tuple, the first item is the content to generate and the second item is a dict 'extra' that contains additional information. The 'if' and 'comment' keys in it are used, the rest is silently ignored.
to_qlit()'s tuple case was added in commit d626b6c1ae7 to make it generate #if.
qapi-introspect: add preprocessor conditions to generated QLit
This commit adds 'ifcond' conditions to top-level QLit objects. Future work will add them to object and enum type members, i.e. within QLit objects.
Extend the QLit generator to_qlit() to accept (@obj, @cond) tuples in addition to just @obj. The tuple causes the QLit generated for objects for @obj with #if/#endif conditions for @cond.
Simple, but ugly. The tuple's second element was the if condition then.
Commit 8c643361eeb turned the tuple's second element into a dict with keys 'if' and 'comment', for generating comments. No other dict keys occur. Still simple, and still ugly.
Your patch adds other dict keys. I'd prefer not to do that.
Your tacit criticism that code that's this ugly should at least explain itself in comments is valid.
Quoted 11 lines
f is already a dict that satisfies the expectations of the
to_qlit()interface, so it feels unnecessary to duplicate it. But if we really do want to duplicate it, it would look like this:if features: obj['features'] = [ (f['name'], {'if': f['if']} if 'if' in f else {}) for f in features ]Or we could pull the condition one level up:
Quoted 7 lines
if features:
obj['features'] = [ (f['name'], {'if': f['if']})
if 'if' in f else f['name'] for f in features ]I don't consider either way very readable compared to what I currently have, but I'll make the change if you insist on it.
Since to_qlit() treats
(obj, {'if': None})
(obj, {})
objthe same, the following should work:
obj['features'] = [(f['name'], {'if': f.get('if')})
for f in features]
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
Quoted 3 lines · Markus Armbruster
Quoted 2 lines · Kevin Wolf
Am 18.04.2019 um 22:03 hat Markus Armbruster geschrieben:
Quoted 1 line
Kevin Wolf <[email protected]> writes:
[...]
Quoted 29 lines
Quoted 3 lines
Do you expect libvirt to check a full list of all QMP commands, types, etc. it ever uses against the schema after starting a VM or something like that?
I'm merely responding to demand.
Subject: Minutes of KVM Forum BoF on deprecating stuff
Message-ID: <[email protected]>* We need to communicate "you're using something that is deprecated". How? Right now, we print a deprecation message. Okay when humans use QEMU directly in a shell. However, when QEMU sits at the bottom of a software stack, the message will likely end up in a log file that is effectively write-only.
- The one way to get people read log files is crashing their application. A command line option --future could make QEMU crash right after printing a deprecation message. This could help with finding use of deprecated features in a testing environment.
- A less destructive way to grab people's attention is to make things run really, really slow: have QEMU go to sleep for a while after printing a deprecation message.
- We can also pass the buck to the next layer up: emit a QMP event.
Sadly, by the time the next layer connects to QMP, plenty of stuff already happened. We'd have to buffer deprecation events somehow.
Quoted 8 lines
What would libvirt do with such an event? Log it, taint the domain, emit a (libvirt) event to pass it on to the next layer up.
- A completely different idea is to have a configuratin linter. To support doing this at the libvirt level, QEMU could expose "is deprecated" in interface introspection. Feels feasible for QMP, where we already have sufficiently expressive introspection. For CLI, we'd first have to provide that (but we want that anyway).
From all of the above, the most important bit is still that the libvirt developers at first identify sooner rather than later that something is deprecated. That way we can either make sure to not use it any longer if there's a compatible replacement or perhaps add the aforementioned linter to print a warning that the config may not be supported in some time.
The linter will still require us seeing what is deprecated, so marking that in the schema is useful. There are two dimensions to this though. QMP is the first, where introspection is awesome. Then there is command line and it's various commands which don't have QMP counterparts and that doesn't work that well there.
In normal operation there's not much we can do here as refusing to use deprecated attributes or commands would cause regressions. In the test suite we are already validating the output of some of our tests against the QMP schema so making those fail when they are deprecated is certainly possible but not very likely to ever catch something as our QMP tests are exremely basic.
It would be much more potent to have something like this to allow validating the command line automatically, but this would require using some structured format first. Without that it's really up to us implementing a check for every unsupported feature as we figure out it's deprecated rather than having it done automatically.
Things got way better after we got CC'd on the deprecation document, since we can make sure that we don't use the particular removed thing.
There are still a few things that are not addressed which were present before this was happening. E.g. we don't specify the full NUMA topology on the commandline and get an angry message back on the command line. This is going on for almost a year now and nobody complained. Stderr messages are ineffective.
Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs
Quoted 45 lines · Peter Krempa
Quoted 3 lines · Markus Armbruster
Quoted 2 lines · Kevin Wolf
Am 18.04.2019 um 22:03 hat Markus Armbruster geschrieben:
Quoted 1 line
Kevin Wolf <[email protected]> writes:
[...]
Quoted 29 lines
Quoted 3 lines
Do you expect libvirt to check a full list of all QMP commands, types, etc. it ever uses against the schema after starting a VM or something like that?
I'm merely responding to demand.
Subject: Minutes of KVM Forum BoF on deprecating stuff
Message-ID: <[email protected]>* We need to communicate "you're using something that is deprecated". How? Right now, we print a deprecation message. Okay when humans use QEMU directly in a shell. However, when QEMU sits at the bottom of a software stack, the message will likely end up in a log file that is effectively write-only.
- The one way to get people read log files is crashing their application. A command line option --future could make QEMU crash right after printing a deprecation message. This could help with finding use of deprecated features in a testing environment.
- A less destructive way to grab people's attention is to make things run really, really slow: have QEMU go to sleep for a while after printing a deprecation message.
- We can also pass the buck to the next layer up: emit a QMP event.
Sadly, by the time the next layer connects to QMP, plenty of stuff already happened. We'd have to buffer deprecation events somehow.
Quoted 8 lines
What would libvirt do with such an event? Log it, taint the domain, emit a (libvirt) event to pass it on to the next layer up.
- A completely different idea is to have a configuratin linter. To support doing this at the libvirt level, QEMU could expose "is deprecated" in interface introspection. Feels feasible for QMP, where we already have sufficiently expressive introspection. For CLI, we'd first have to provide that (but we want that anyway).
Quoted 3 lines
From all of the above, the most important bit is still that the libvirt developers at first identify sooner rather than later that something is deprecated.
Yes, that's the goal. The above lists the ideas we had on how to get closer to the goal.
Quoted 18 lines
That way we can either make sure to not use it any longer if
there's a compatible replacement or perhaps add the aforementioned linter to print a warning that the config may not be supported in some time.The linter will still require us seeing what is deprecated, so marking that in the schema is useful. There are two dimensions to this though. QMP is the first, where introspection is awesome. Then there is command line and it's various commands which don't have QMP counterparts and that doesn't work that well there.
In normal operation there's not much we can do here as refusing to use deprecated attributes or commands would cause regressions. In the test suite we are already validating the output of some of our tests against the QMP schema so making those fail when they are deprecated is certainly possible but not very likely to ever catch something as our QMP tests are exremely basic.
Quoted 3 lines
It would be much more potent to have something like this to allow validating the command line automatically, but this would require using some structured format first.
You're asking for command line QAPIfication.
Quoted 4 lines
Without that it's really up to us
implementing a check for every unsupported feature as we figure out it's deprecated rather than having it done automatically.
Quoted 8 lines
Things got way better after we got CC'd on the deprecation document, since we can make sure that we don't use the particular removed thing.
There are still a few things that are not addressed which were present before this was happening. E.g. we don't specify the full NUMA topology on the commandline and get an angry message back on the command line. This is going on for almost a year now and nobody complained. Stderr messages are ineffective.
I figure they work as well as anything when a human runs QEMU directly.
They're ineffective when a management application runs QEMU. It won't be able to make sense of deprecation messages it doesn't already know (and therefore doesn't actually need), so all it can do is bury them in logs nobody reads until after things have gone south.
Exposing deprecation in introspection is just one idea of several. It might be the least immediately useful one. We'll likely want to do more.
PATCH 2/4 tests/qapi-schema: Test for good feature lists in structs
In reply to Kevin Wolf--- tests/qapi-schema/qapi-schema-test.json | 27 +++++++++++++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 26 ++++++++++++++++++++++++ tests/qapi-schema/test-qapi.py | 4 ++++ 3 files changed, 57 insertions(+)
tests/qapi-schema/qapi-schema-test.json +27 -0
@@ -242,3 +242,30 @@ { 'foo': 'TestIfStruct', 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } + +# test 'features' for structs + +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': [] } +{ 'struct': 'FeatureStruct1', + 'data': { 'foo': 'int' }, + 'features': [ 'feature1' ] } +{ 'struct': 'FeatureStruct2', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1' } ] } +{ 'struct': 'FeatureStruct3', + 'data': { 'foo': 'int' }, + 'features': [ 'feature1', 'feature2' ] } + +{ 'struct': 'CondFeatureStruct1', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} ] } +{ 'struct': 'CondFeatureStruct2', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'}, + { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} ] } +{ 'struct': 'CondFeatureStruct3', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', + 'defined(TEST_IF_COND_2)'] } ] }
tests/qapi-schema/qapi-schema-test.out +26 -0
@@ -354,3 +354,29 @@ object q_obj_TestIfEvent-arg event TestIfEvent q_obj_TestIfEvent-arg boxed=False if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] +object FeatureStruct0 + member foo: int optional=False +object FeatureStruct1 + member foo: int optional=False + feature feature1 +object FeatureStruct2 + member foo: int optional=False + feature feature1 +object FeatureStruct3 + member foo: int optional=False + feature feature1 + feature feature2 +object CondFeatureStruct1 + member foo: int optional=False + feature feature1 + if ['defined(TEST_IF_FEATURE_1)'] +object CondFeatureStruct2 + member foo: int optional=False + feature feature1 + if ['defined(TEST_IF_FEATURE_1)'] + feature feature2 + if ['defined(TEST_IF_FEATURE_2)'] +object CondFeatureStruct3 + member foo: int optional=False + feature feature1 + if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']
tests/qapi-schema/test-qapi.py +4 -0
@@ -49,6 +49,10 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(m.ifcond, 8) self._print_variants(variants) self._print_if(ifcond) + if features: + for f in features: + print(' feature %s' % f['name']) + self._print_if(f.get('if'), 8) def visit_alternate_type(self, name, info, ifcond, variants): print('alternate %s' % name)
Signature · 1 line
2.20.1
PATCH 3/4 tests/qapi-schema: Error case tests for features in structs
In reply to Kevin Wolf--- tests/qapi-schema/features-bad-type.json | 3 +++ tests/qapi-schema/features-missing-name.json | 3 +++ tests/qapi-schema/features-name-bad-type.json | 3 +++ tests/qapi-schema/features-no-list.json | 3 +++ tests/qapi-schema/features-unknown-key.json | 3 +++ tests/Makefile.include | 5 +++++ tests/qapi-schema/features-bad-type.err | 1 + tests/qapi-schema/features-bad-type.exit | 1 + tests/qapi-schema/features-bad-type.out | 0 tests/qapi-schema/features-missing-name.err | 1 + tests/qapi-schema/features-missing-name.exit | 1 + tests/qapi-schema/features-missing-name.out | 0 tests/qapi-schema/features-name-bad-type.err | 1 + tests/qapi-schema/features-name-bad-type.exit | 1 + tests/qapi-schema/features-name-bad-type.out | 0 tests/qapi-schema/features-no-list.err | 1 + tests/qapi-schema/features-no-list.exit | 1 + tests/qapi-schema/features-no-list.out | 0 tests/qapi-schema/features-unknown-key.err | 2 ++ tests/qapi-schema/features-unknown-key.exit | 1 + tests/qapi-schema/features-unknown-key.out | 0 21 files changed, 31 insertions(+) create mode 100644 tests/qapi-schema/features-bad-type.json create mode 100644 tests/qapi-schema/features-missing-name.json create mode 100644 tests/qapi-schema/features-name-bad-type.json create mode 100644 tests/qapi-schema/features-no-list.json create mode 100644 tests/qapi-schema/features-unknown-key.json create mode 100644 tests/qapi-schema/features-bad-type.err create mode 100644 tests/qapi-schema/features-bad-type.exit create mode 100644 tests/qapi-schema/features-bad-type.out create mode 100644 tests/qapi-schema/features-missing-name.err create mode 100644 tests/qapi-schema/features-missing-name.exit create mode 100644 tests/qapi-schema/features-missing-name.out create mode 100644 tests/qapi-schema/features-name-bad-type.err create mode 100644 tests/qapi-schema/features-name-bad-type.exit create mode 100644 tests/qapi-schema/features-name-bad-type.out create mode 100644 tests/qapi-schema/features-no-list.err create mode 100644 tests/qapi-schema/features-no-list.exit create mode 100644 tests/qapi-schema/features-no-list.out create mode 100644 tests/qapi-schema/features-unknown-key.err create mode 100644 tests/qapi-schema/features-unknown-key.exit create mode 100644 tests/qapi-schema/features-unknown-key.out
tests/qapi-schema/features-bad-type.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': [ [ 'a feature cannot be an array' ] ] }
tests/qapi-schema/features-missing-name.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': [ { 'if': 'defined(NAMELESS_FEATURES)' } ] }
tests/qapi-schema/features-name-bad-type.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': { 'feature-type': 'object' } } ] }
tests/qapi-schema/features-no-list.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': 'bar' }
tests/qapi-schema/features-unknown-key.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'struct': 'FeatureStruct0', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'bar', 'colour': 'red' } ] }
tests/Makefile.include +5 -0
@@ -377,6 +377,11 @@ qapi-schema += event-boxed-empty.json qapi-schema += event-case.json qapi-schema += event-member-invalid-dict.json qapi-schema += event-nest-struct.json +qapi-schema += features-bad-type.json +qapi-schema += features-missing-name.json +qapi-schema += features-name-bad-type.json +qapi-schema += features-no-list.json +qapi-schema += features-unknown-key.json qapi-schema += flat-union-array-branch.json qapi-schema += flat-union-bad-base.json qapi-schema += flat-union-bad-discriminator.json
tests/qapi-schema/features-bad-type.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/features-bad-type.json:1: Feature names for struct 'FeatureStruct0' must be strings
tests/qapi-schema/features-bad-type.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/features-bad-type.out new file +0 -0
tests/qapi-schema/features-missing-name.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/features-missing-name.json:1: Key 'name' is missing from feature of struct FeatureStruct0
tests/qapi-schema/features-missing-name.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/features-missing-name.out new file +0 -0
tests/qapi-schema/features-name-bad-type.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/features-name-bad-type.json:1: Feature names for struct 'FeatureStruct0' must be strings
tests/qapi-schema/features-name-bad-type.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/features-name-bad-type.out new file +0 -0
tests/qapi-schema/features-no-list.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/features-no-list.json:1: Struct 'FeatureStruct0' requires an array for 'features'
tests/qapi-schema/features-no-list.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/features-no-list.out new file +0 -0
tests/qapi-schema/features-unknown-key.err new file +2 -0
@@ -0,0 +1,2 @@ +tests/qapi-schema/features-unknown-key.json:1: Unknown key 'colour' in feature of struct FeatureStruct0 +Valid keys are 'if', 'name'.
tests/qapi-schema/features-unknown-key.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/features-unknown-key.out new file +0 -0
Signature · 1 line
2.20.1
PATCH 4/4 file-posix: Add dynamic-auto-read-only QAPI feature
In reply to Kevin WolfIn commit 23dece19da4 ('file-posix: Make auto-read-only dynamic') , auto-read-only=on changed its behaviour in file-posix for the 4.0 release. This change cannot be detected through the usual mechanisms like schema introspection. Add a new feature flag to the schema to allow libvirt to detect the presence of the new behaviour.
--- qapi/block-core.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
qapi/block-core.json +10 -1
@@ -2843,6 +2843,13 @@ # file is large, do not use in production. # (default: off) (since: 3.0) # +# If the feature 'dynamic-auto-read-only' is present, enabled auto-read-only +# means that the driver will open the image read-only at first, dynamically +# reopen the image file read-write when the first writer is attached to the +# node and reopen read-only when the last writer is detached. This allows to +# give QEMU write permissions only on demand when an operation actually needs +# write access. +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsFile',
@@ -2852,7 +2859,9 @@ '*aio': 'BlockdevAioOptions', '*drop-cache': {'type': 'bool', 'if': 'defined(CONFIG_LINUX)'}, - '*x-check-cache-dropped': 'bool' } } + '*x-check-cache-dropped': 'bool' }, + 'features': [ { 'name': 'dynamic-auto-read-only', + 'if': 'defined(CONFIG_POSIX)' } ] } ## # @BlockdevOptionsNull:
Signature · 1 line
2.20.1
qapi/block-core.json
Quoted 16 lines · Kevin Wolf
In commit
23dece19da4('file-posix: Make auto-read-only dynamic') , auto-read-only=on changed its behaviour in file-posix for the 4.0 release. This change cannot be detected through the usual mechanisms like schema introspection. Add a new feature flag to the schema to allow libvirt to detect the presence of the new behaviour.Signed-off-by Kevin Wolf <[email protected]>--- qapi/block-core.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)qapi/block-core.json +0
-0@@ -2843,6 +2843,13 @@
##
# @BlockdevOptionsFile:
#
# Driver specific block device options for the file backend. #
# @filename: path to the image file # @pr-manager: the id for the object that will handle persistent reservations # for this device (default: none, forward the commands via SG_IO; # since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) # @locking: whether to enable file locking. If set to 'auto', only enable # when Open File Descriptor (OFD) locking API is available # (default: auto, since 2.10) # @drop-cache: invalidate page cache during live migration. This prevents # stale data on the migration destination with cache.direct=off. # Currently only supported on Linux hosts. # (default: on, since: 4.0) # @x-check-cache-dropped: whether to check that page cache was dropped on live # migration. May cause noticeable delays if the image > # file is large, do not use in production. > # (default: off) (since: 3.0)
Quoted 12 lines
qapi/block-core.json +7
-0# +# If the feature 'dynamic-auto-read-only' is present, enabled auto-read-only +# means that the driver will open the image read-only at first, dynamically +# reopen the image file read-write when the first writer is attached to the +# node and reopen read-only when the last writer is detached. This allows to +# give QEMU write permissions only on demand when an operation actually needs +# write access. +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsFile',
qapi/block-core.json line 2867
Quoted 10 lines
qapi/block-core.json +3
-1@@ -2852,7 +2859,9 @@ '*aio': 'BlockdevAioOptions', '*drop-cache': {'type': 'bool', 'if': 'defined(CONFIG_LINUX)'}, - '*x-check-cache-dropped': 'bool' } } + '*x-check-cache-dropped': 'bool' }, + 'features': [ { 'name': 'dynamic-auto-read-only', + 'if': 'defined(CONFIG_POSIX)' } ] } ## # @BlockdevOptionsNull:
This uses free-form text to document features. That means the doc generator can't flag missing documentation, like it could for members (it doesn't only because we still got doc work to do there).
A more structured approach could look like this:
##
# @BlockdevOptionsFile:
#
# Driver specific block device options for the file backend. #
# @filename: path to the image file
[More members...]
#
# Features:
# @dynamic-read-only: if present, enabled auto-read-only ... #
# Since: 2.9
##
Quoted 9 lines · Kevin Wolf
This series adds optional feature lists to struct definitions in the QAPI schema and makes use of them to advertise the new behaviour of auto-read-only=on in file-posix.
Kevin Wolf (4):
qapi: Support features for structs tests/qapi-schema: Test for good feature lists in structs tests/qapi-schema: Error case tests for features in structs
file-posix: Add dynamic-auto-read-only QAPI feature
I was able to implement this in libvirt fairly easy. My work-in-progress (needs some docs and polishing) patches can be found at:
https://github.com/pipo/libvirt/commits/qapi-features-introspect
Am 08.04.2019 um 16:35 hat Kevin Wolf geschrieben:
Quoted 3 lines
This series adds optional feature lists to struct definitions in the QAPI schema and makes use of them to advertise the new behaviour of auto-read-only=on in file-posix.
Ping?
Quoted 3 lines · Kevin Wolf
This series adds optional feature lists to struct definitions in the QAPI schema and makes use of them to advertise the new behaviour of auto-read-only=on in file-posix.
General approach looks good to me. It's just a first step, however. One that is already useful.