Configurable policy for handling deprecated interfaces
v2 cover Configurable policy for handling deprecated interfaces
Based-on: <[email protected]>
This series extends QMP introspection to cover deprecation. Additionally, new option -compat lets you configure what to do when deprecated interfaces get used. This is intended for testing users of the management interfaces. It is experimental.
-compat deprecated-input=<in-policy> configures what to do when deprecated input is received. Available policies:
* accept: Accept deprecated commands and arguments (default)
* reject: Reject them
* crash: Crash
-compat deprecated-output=<out-policy> configures what to do when deprecated output is sent. Available output policies:
* accept: Emit deprecated command results and events (default)
* hide: Suppress them
For now, -compat covers only deprecated syntactic aspects of QMP. We may want to extend it to cover semantic aspects, CLI, and experimental features.
PATCH 01-04: Documentation fixes
PATCH 05-10: Test improvements
PATCH 11-24: Add feature flags to remaining user-defined types and to
struct members
PATCH 25-26: New special feature 'deprecated', visible in
introspection
PATCH 27-30: New -compat to set policy for handling stuff marked with
feature 'deprecated'
Comparison to RFC (24 Oct 2019):
* Cover arguments and results in addition to commands and events
* Half-baked "[RFC PATCH 18/19] qapi: Include a warning in the response to a deprecated command" dropped
See also last item of
Subject: Minutes of KVM Forum BoF on deprecating stuff
Date: Fri, 26 Oct 2018 16:03:51 +0200
Message-ID: <[email protected]>
https://lists.nongnu.org/archive/html/qemu-devel/2018-10/msg05828.htmlMarkus Armbruster (30):
qemu-doc: Belatedly document QMP command arg & result deprecation
qapi: Belatedly update doc comment for @wait deprecation docs/devel/qapi-code-gen: Clarify allow-oob introspection docs/devel/qapi-code-gen: Document 'features' introspection tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers tests/test-qmp-cmds: Check responses more thoroughly tests/test-qmp-cmds: Simplify test data setup tests/test-qmp-event: Simplify test data setup tests/test-qmp-event: Use qobject_is_equal() tests/test-qmp-event: Check event is actually emitted qapi/schema: Clean up around QAPISchemaEntity.connect_doc()
qapi: Add feature flags to remaining definitions
qapi: Consistently put @features parameter right after @ifcond qapi/introspect: Rename *qlit* to reduce confusion qapi/introspect: Factor out _make_tree()
qapi/schema: Change _make_features() to a take feature list qapi/schema: Reorder classes so related ones are together qapi/schema: Rename QAPISchemaObjectType{Variant,Variants} qapi/schema: Call QAPIDoc.connect_member() in just one place
qapi: Add feature flags to struct members
qapi: Inline do_qmp_dispatch() into qmp_dispatch()
qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP
qapi: Simplify how qmp_dispatch() gets the request ID
qapi: Replace qmp_dispatch()'s TODO comment by an explanation
qapi: New special feature flag "deprecated"
qapi: Mark deprecated QMP parts with feature 'deprecated'
qemu-options: New -compat to set policy for deprecated interfaces
qapi: Implement -compat deprecated-output=hide
qapi: Implement -compat deprecated-input=reject
qapi: New -compat deprecated-input=crash
docs/devel/qapi-code-gen.txt | 79 ++- qemu-deprecated.texi | 38 +- tests/qapi-schema/doc-good.texi | 32 ++ qapi/block-core.json | 69 ++- qapi/block.json | 9 +- qapi/char.json | 1 + qapi/compat.json | 52 ++ qapi/control.json | 11 +- qapi/introspect.json | 26 +- qapi/machine.json | 34 +- qapi/migration.json | 36 +- qapi/misc.json | 13 +- qapi/qapi-schema.json | 1 + include/qapi/compat-policy.h | 20 + include/qapi/qmp/dispatch.h | 1 + include/qapi/qobject-input-visitor.h | 9 + include/qapi/qobject-output-visitor.h | 9 + include/qapi/visitor-impl.h | 3 + include/qapi/visitor.h | 9 + qapi/qapi-visit-core.c | 9 + qapi/qmp-dispatch.c | 137 ++--- qapi/qobject-input-visitor.c | 29 ++ qapi/qobject-output-visitor.c | 20 + softmmu/vl.c | 17 + tests/test-qmp-cmds.c | 249 +++++---- tests/test-qmp-event.c | 183 ++----- qapi/Makefile.objs | 8 +- qapi/trace-events | 1 + qemu-options.hx | 23 + scripts/qapi/commands.py | 20 +- scripts/qapi/doc.py | 16 +- scripts/qapi/events.py | 16 +- scripts/qapi/expr.py | 14 +- scripts/qapi/introspect.py | 104 ++-- scripts/qapi/schema.py | 488 ++++++++++-------- scripts/qapi/types.py | 8 +- scripts/qapi/visit.py | 28 +- tests/Makefile.include | 1 + tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/doc-good.json | 22 +- tests/qapi-schema/doc-good.out | 18 + .../qapi-schema/features-deprecated-type.err | 2 + .../qapi-schema/features-deprecated-type.json | 3 + .../qapi-schema/features-deprecated-type.out | 0 tests/qapi-schema/qapi-schema-test.json | 48 +- tests/qapi-schema/qapi-schema-test.out | 46 +- tests/qapi-schema/test-qapi.py | 26 +- 47 files changed, 1259 insertions(+), 731 deletions(-) create mode 100644 qapi/compat.json create mode 100644 include/qapi/compat-policy.h create mode 100644 tests/qapi-schema/features-deprecated-type.err create mode 100644 tests/qapi-schema/features-deprecated-type.json create mode 100644 tests/qapi-schema/features-deprecated-type.out
Signature · 1 line
2.21.1
PATCH v2 1/30 qemu-doc: Belatedly document QMP command arg & result deprecation
A number of deprecated QMP arguments and results were missed in commit eb22aeca65 "docs: document deprecation policy & deprecated features in appendix" (v2.10.0):
* Commit b33945cfff "block: Accept device model name for blockdev-open/close-tray" (v2.8.0) deprecated blockdev-open-tray, blockdev-close-tray argument @device.
* Commit fbe2d8163e "block: Accept device model name for eject" (v2.8.0) deprecated eject argument @device.
* Commit 70e2cb3bd7 "block: Accept device model name for blockdev-change-medium" (v2.8.0) deprecated blockdev-change-medium argument @device.
* Commit 7a9877a026 "block: Accept device model name for block_set_io_throttle" (v2.8.0) deprecated block_set_io_throttle argument @device.
* Commit c01c214b69 "block: remove all encryption handling APIs" (v2.10.0) deprecated query-named-block-nodes result @encryption_key_missing and query-block result @inserted member @encryption_key_missing.
* Commit c42e8742f5 "block: Use JSON null instead of "" to disable backing file" (v2.10.0) deprecated blockdev-add empty string argument @backing.
Since then, we missed a few more:
* Commit 3c605f4074 "commit: Add top-node/base-node options" (v3.1.0) deprecated block-commit arguments @base and @top.
* Commit 4db6ceb0b5 "block/dirty-bitmap: add recording and busy properties" (v4.0.0) deprecated query-named-block-nodes result @dirty-bitmaps member @status, not just query-block.
Make up for all that.
--- qemu-deprecated.texi | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
qemu-deprecated.texi +35 -3
@@ -150,19 +150,51 @@ Use @option{-display sdl,show-cursor=on} or Use ``blockdev-change-medium'' or ``change-vnc-password'' instead. +@subsection blockdev-open-tray, blockdev-close-tray argument device (since 2.8.0) + +Use argument ``id'' instead. + +@subsection eject argument device (since 2.8.0) + +Use argument ``id'' instead. + +@subsection blockdev-change-medium argument device (since 2.8.0) + +Use argument ``id'' instead. + +@subsection block_set_io_throttle argument device (since 2.8.0) + +Use argument ``id'' instead. + @subsection migrate_set_downtime and migrate_set_speed (since 2.8.0) Use ``migrate-set-parameters'' instead. +@subsection query-named-block-nodes result encryption_key_missing (since 2.10.0) + +Always false. + +@subsection query-block result inserted.encryption_key_missing (since 2.10.0) + +Always false. + +@subsection blockdev-add empty string argument backing (since 2.10.0) + +Use argument ``null'' instead. + @subsection migrate-set-cache-size and query-migrate-cache-size (since 2.11.0) Use ``migrate-set-parameters'' and ``query-migrate-parameters'' instead. -@subsection query-block result field dirty-bitmaps[i].status (since 4.0) +@subsection block-commit arguments base and top (since 3.1.0) + +Use arguments ``base-node'' and ``top-node'' instead. + +@subsection query-named-block-nodes and query-block result dirty-bitmaps[i].status (since 4.0) The ``status'' field of the ``BlockDirtyInfo'' structure, returned by -the query-block command is deprecated. Two new boolean fields, -``recording'' and ``busy'' effectively replace it. +these commands is deprecated. Two new boolean fields, ``recording'' and +``busy'' effectively replace it. @subsection query-block result field dirty-bitmaps (Since 4.2)
Signature · 1 line
2.21.1
PATCH v2 2/30 qapi: Belatedly update doc comment for @wait deprecation
In reply to Markus ArmbrusterCommit a9b305ba29 "socket: allow wait=false for client socket" deprecated use of @wait for client socket chardevs, but neglected to update char.json's doc comment. Make up for that.
--- qapi/char.json | 1 + 1 file changed, 1 insertion(+)
qapi/char.json +1 -0
@@ -258,6 +258,7 @@ # @server: create server socket (default: true) # @wait: wait for incoming connection on server # sockets (default: false). +# Silently ignored with server: false. This use is deprecated. # @nodelay: set TCP_NODELAY socket option (default: false) # @telnet: enable telnet protocol on server # sockets (default: false)
Signature · 1 line
2.21.1
PATCH v2 3/30 docs/devel/qapi-code-gen: Clarify allow-oob introspection
In reply to Markus ArmbrusterMention SchemaInfo variant member "allow-oob" defaults to false.
--- docs/devel/qapi-code-gen.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
docs/devel/qapi-code-gen.txt +3 -3
@@ -988,9 +988,9 @@ The SchemaInfo for a command has meta-type "command", and variant members "arg-type", "ret-type" and "allow-oob". On the wire, the "arguments" member of a client's "execute" command must conform to the object type named by "arg-type". The "return" member that the server -passes in a success response conforms to the type named by -"ret-type". When "allow-oob" is set, it means the command supports -out-of-band execution. +passes in a success response conforms to the type named by "ret-type". +When "allow-oob" is true, it means the command supports out-of-band +execution. It defaults to false. If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type"
Signature · 1 line
2.21.1
PATCH v2 4/30 docs/devel/qapi-code-gen: Document 'features' introspection
In reply to Markus ArmbrusterCommit 6a8c0b5102 "qapi: Add feature flags to struct types" neglected to update section "Client JSON Protocol introspection", and commit 23394b4c39 "qapi: Add feature flags to commands" didn't either. Make up for that.
--- docs/devel/qapi-code-gen.txt | 43 +++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-)
docs/devel/qapi-code-gen.txt +28 -15
@@ -642,13 +642,8 @@ 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 command or -struct type. This is exposed to the client as a list of strings, -where each string signals that this build of QEMU shows a certain -behaviour. - -Each member of the 'features' array defines a feature. It can either -be { 'name': STRING, '*if': COND }, or STRING, which is shorthand for -{ 'name': STRING }. +struct type. Each list member can either be { 'name': STRING, '*if': +COND }, or STRING, which is shorthand for { 'name': STRING }. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this.
@@ -659,6 +654,12 @@ Example: 'data': { 'number': 'int' }, 'features': [ 'allow-negative-numbers' ] } +The feature strings are exposed to clients in introspection, as +explained in section "Client JSON Protocol introspection". + +Intended use is to have each feature string signal that this build of +QEMU shows a certain behaviour. + === Naming rules and reserved names ===
@@ -965,7 +966,7 @@ schema, along with the SchemaInfo type. This text attempts to give an overview how things work. For details you need to consult the QAPI schema. -SchemaInfo objects have common members "name" and "meta-type", and +SchemaInfo objects have common members "name", "meta-type", and additional variant members depending on the value of meta-type. Each SchemaInfo object describes a wire ABI entity of a certain
@@ -985,12 +986,13 @@ references by name. QAPI schema definitions not reachable that way are omitted. The SchemaInfo for a command has meta-type "command", and variant -members "arg-type", "ret-type" and "allow-oob". On the wire, the -"arguments" member of a client's "execute" command must conform to the -object type named by "arg-type". The "return" member that the server -passes in a success response conforms to the type named by "ret-type". -When "allow-oob" is true, it means the command supports out-of-band -execution. It defaults to false. +members "arg-type", "ret-type", "allow-oob", and "features". On the +wire, the "arguments" member of a client's "execute" command must +conform to the object type named by "arg-type". The "return" member +that the server passes in a success response conforms to the type +named by "ret-type". When "allow-oob" is true, it means the command +supports out-of-band execution. It defaults to false. "features" +exposes the command's feature strings as a JSON array of strings. If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type"
@@ -1025,7 +1027,8 @@ Example: the SchemaInfo for EVENT_C from section Events The SchemaInfo for struct and union types has meta-type "object". -The SchemaInfo for a struct type has variant member "members". +The SchemaInfo for a struct type has variant members "members" and +"features". The SchemaInfo for a union type additionally has variant members "tag" and "variants".
@@ -1047,6 +1050,16 @@ Example: the SchemaInfo for MyType from section Struct types { "name": "member2", "type": "int" }, { "name": "member3", "type": "str", "default": null } ] } +"features" exposes the command's feature strings as a JSON array of +strings. + +Example: the SchemaInfo for TestType from section Features: + + { "name": "TestType", "meta-type": "object", + "members": [ + { "name": "number", "type": "int" } ], + "features": ["allow-negative-numbers"] } + "tag" is the name of the common member serving as type tag. "variants" is a JSON array describing the object's variant members. Each element is a JSON object with members "case" (the value of type
Signature · 1 line
2.21.1
PATCH v2 5/30 tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers
In reply to Markus ArmbrusterChecking the value of qmp_dispatch() is repetitive. Factor out helpers do_qmp_dispatch() and do_qmp_dispatch_error(). Without this, the next commit would make things even more repetitive.
--- tests/test-qmp-cmds.c | 72 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 37 deletions(-)
tests/test-qmp-cmds.c +35 -37
@@ -145,34 +145,55 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, } +static QObject *do_qmp_dispatch (QDict *req,bool allow_oob) +{ +QDict *resp; +QObject *ret; + + resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob); +g_assert (resp && !qdict_haskey (resp,"error" )); + ret =qdict_get (resp,"return" ); +g_assert (ret); + +qobject_ref (ret); +qobject_unref (resp); +return ret; +} + +static void do_qmp_dispatch_error (QDict *req,bool allow_oob,ErrorClass cls) +{ +QDict *resp; + + resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob); +g_assert (resp &&qdict_haskey (resp,"error" )); + +qobject_unref (resp); +} +/* test commands with no input and no return value */ static void test_dispatch_cmd (void ) {QDict *req =qdict_new (); -QDict *resp; +QObject *ret;qdict_put_str (req,"execute" ,"user_def_cmd" ); - resp =qmp_dispatch (&qmp_commands,QOBJECT (req), false); -assert (resp !=NULL ); -assert (!qdict_haskey (resp,"error" )); + ret =do_qmp_dispatch (req, false); -qobject_unref (resp); +qobject_unref (ret);qobject_unref (req); }static void test_dispatch_cmd_oob (void ) {QDict *req =qdict_new (); -QDict *resp; +QObject *ret;qdict_put_str (req,"exec-oob" ,"test-flags-command" ); - resp =qmp_dispatch (&qmp_commands,QOBJECT (req), true); -assert (resp !=NULL ); -assert (!qdict_haskey (resp,"error" )); + ret =do_qmp_dispatch (req, true); -qobject_unref (resp); +qobject_unref (ret);qobject_unref (req); }
@@ -181,15 +202,11 @@ static void test_dispatch_cmd_failure(void) {QDict *req =qdict_new ();QDict *args =qdict_new (); -QDict *resp;qdict_put_str (req,"execute" ,"user_def_cmd2" ); - resp =qmp_dispatch (&qmp_commands,QOBJECT (req), false); -assert (resp !=NULL ); -assert (qdict_haskey (resp,"error" )); +do_qmp_dispatch_error (req, false,ERROR_CLASS_GENERIC_ERROR ); -qobject_unref (resp);qobject_unref (req);/* check that with extra arguments it throws an error */
@@ -199,11 +216,8 @@ static void test_dispatch_cmd_failure(void)qdict_put_str (req,"execute" ,"user_def_cmd" ); - resp =qmp_dispatch (&qmp_commands,QOBJECT (req), false); -assert (resp !=NULL ); -assert (qdict_haskey (resp,"error" )); +do_qmp_dispatch_error (req, false,ERROR_CLASS_GENERIC_ERROR ); -qobject_unref (resp);qobject_unref (req); }
@@ -218,20 +232,6 @@ static void test_dispatch_cmd_success_response(void)qobject_unref (req); } -static QObject *test_qmp_dispatch (QDict *req) -{ -QDict *resp; -QObject *ret; - - resp =qmp_dispatch (&qmp_commands,QOBJECT (req), false); -assert (resp && !qdict_haskey (resp,"error" )); - ret =qdict_get (resp,"return" ); -assert (ret); -qobject_ref (ret); -qobject_unref (resp); -return ret; -} -/* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io (void ) {
@@ -254,7 +254,7 @@ static void test_dispatch_cmd_io(void)qdict_put (req,"arguments" , args);qdict_put_str (req,"execute" ,"user_def_cmd2" ); - ret =qobject_to (QDict,test_qmp_dispatch (req)); + ret =qobject_to (QDict,do_qmp_dispatch (req, false));assert (!strcmp (qdict_get_str (ret,"string0" ),"blah1" )); ret_dict =qdict_get_qdict (ret,"dict1" );
@@ -275,12 +275,10 @@ static void test_dispatch_cmd_io(void)qdict_put (req,"arguments" , args3);qdict_put_str (req,"execute" ,"guest-get-time" ); - ret3 =qobject_to (QNum,test_qmp_dispatch (req)); + ret3 =qobject_to (QNum,do_qmp_dispatch (req, false));g_assert (qnum_get_try_int (ret3, &val)); g_assert_cmpint(val, ==, 66);qobject_unref (ret3); - -qobject_unref (req); }/* test generated dealloc functions for generated types */
Signature · 1 line
2.21.1
PATCH v2 6/30 tests/test-qmp-cmds: Check responses more thoroughly
In reply to Markus Armbruster--- tests/test-qmp-cmds.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
tests/test-qmp-cmds.c +17 -6
@@ -151,9 +151,10 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow_oob)QObject *ret; resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob); -g_assert (resp && !qdict_haskey (resp,"error" )); +g_assert (resp); ret =qdict_get (resp,"return" );g_assert (ret); +g_assert (qdict_size (resp) ==1 );qobject_ref (ret);qobject_unref (resp);
@@ -163,9 +164,17 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow_oob)static void do_qmp_dispatch_error (QDict *req,bool allow_oob,ErrorClass cls) {QDict *resp; +QDict *error; resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob); -g_assert (resp &&qdict_haskey (resp,"error" )); +g_assert (resp); + error =qdict_get_qdict (resp,"error" ); +g_assert (error); +g_assert_cmpstr (qdict_get_try_str (error,"class" ), + ==, QapiErrorClass_str(cls)); +g_assert (qdict_get_try_str (error,"desc" )); +g_assert (qdict_size (error) ==2 ); +g_assert (qdict_size (resp) ==1 );qobject_unref (resp); }
@@ -174,11 +183,12 @@ static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass cls)static void test_dispatch_cmd (void ) {QDict *req =qdict_new (); -QObject *ret; +QDict *ret;qdict_put_str (req,"execute" ,"user_def_cmd" ); - ret =do_qmp_dispatch (req, false); + ret =qobject_to (QDict,do_qmp_dispatch (req, false)); +assert (ret &&qdict_size (ret) ==0 );qobject_unref (ret);qobject_unref (req);
@@ -187,11 +197,12 @@ static void test_dispatch_cmd(void)static void test_dispatch_cmd_oob (void ) {QDict *req =qdict_new (); -QObject *ret; +QDict *ret;qdict_put_str (req,"exec-oob" ,"test-flags-command" ); - ret =do_qmp_dispatch (req, true); + ret =qobject_to (QDict,do_qmp_dispatch (req, true)); +assert (ret &&qdict_size (ret) ==0 );qobject_unref (ret);qobject_unref (req);
Signature · 1 line
2.21.1
PATCH v2 7/30 tests/test-qmp-cmds: Simplify test data setup
In reply to Markus ArmbrusterBuilding requests with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_vjsonf_nofail() instead.
--- tests/test-qmp-cmds.c | 93 ++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 55 deletions(-)
tests/test-qmp-cmds.c +38 -55
@@ -1,5 +1,6 @@#include "qemu/osdep.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/error.h"
@@ -145,11 +146,16 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, } -static QObject *do_qmp_dispatch (QDict *req,bool allow_oob) +static QObject *do_qmp_dispatch (bool allow_oob,const char *template, ...) { -QDict *resp; +va_list ap; +QDict *req, *resp;QObject *ret; +va_start (ap, template); + req =qdict_from_vjsonf_nofail (template, ap); +va_end (ap); + resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob);g_assert (resp); ret =qdict_get (resp,"return" );
@@ -158,14 +164,21 @@ static QObject *do_qmp_dispatch(QDict *req, bool allow_oob)qobject_ref (ret);qobject_unref (resp); +qobject_unref (req);return ret; } -static void do_qmp_dispatch_error (QDict *req,bool allow_oob,ErrorClass cls) +static void do_qmp_dispatch_error (bool allow_oob,ErrorClass cls, +const char *template, ...) { -QDict *resp; +va_list ap; +QDict *req, *resp;QDict *error; +va_start (ap, template); + req =qdict_from_vjsonf_nofail (template, ap); +va_end (ap); + resp =qmp_dispatch (&qmp_commands,QOBJECT (req), allow_oob);g_assert (resp); error =qdict_get_qdict (resp,"error" );
@@ -177,59 +190,43 @@ static void do_qmp_dispatch_error(QDict *req, bool allow_oob, ErrorClass cls)g_assert (qdict_size (resp) ==1 );qobject_unref (resp); +qobject_unref (req); }/* test commands with no input and no return value */ static void test_dispatch_cmd (void ) { -QDict *req =qdict_new ();QDict *ret; -qdict_put_str (req,"execute" ,"user_def_cmd" ); - - ret =qobject_to (QDict,do_qmp_dispatch (req, false)); + ret =qobject_to (QDict, +do_qmp_dispatch (false, +"{ 'execute': 'user_def_cmd' }" ));assert (ret &&qdict_size (ret) ==0 ); -qobject_unref (ret); -qobject_unref (req); }static void test_dispatch_cmd_oob (void ) { -QDict *req =qdict_new ();QDict *ret; -qdict_put_str (req,"exec-oob" ,"test-flags-command" ); - - ret =qobject_to (QDict,do_qmp_dispatch (req, true)); + ret =qobject_to (QDict, +do_qmp_dispatch (true, +"{ 'exec-oob': 'test-flags-command' }" ));assert (ret &&qdict_size (ret) ==0 ); -qobject_unref (ret); -qobject_unref (req); }/* test commands that return an error due to invalid parameters */ static void test_dispatch_cmd_failure (void ) { -QDict *req =qdict_new (); -QDict *args =qdict_new (); - -qdict_put_str (req,"execute" ,"user_def_cmd2" ); - -do_qmp_dispatch_error (req, false,ERROR_CLASS_GENERIC_ERROR ); - -qobject_unref (req); - -/* check that with extra arguments it throws an error */ - req =qdict_new (); -qdict_put_int (args,"a" ,66 ); -qdict_put (req,"arguments" , args); - -qdict_put_str (req,"execute" ,"user_def_cmd" ); - -do_qmp_dispatch_error (req, false,ERROR_CLASS_GENERIC_ERROR ); - -qobject_unref (req); +/* missing arguments */ +do_qmp_dispatch_error (false,ERROR_CLASS_GENERIC_ERROR , +"{ 'execute': 'user_def_cmd2' }" ); + +/* extra arguments */ +do_qmp_dispatch_error (false,ERROR_CLASS_GENERIC_ERROR , +"{ 'execute': 'user_def_cmd'," +" 'arguments': { 'a': 66 } }" ); }static void test_dispatch_cmd_success_response (void )
@@ -246,26 +243,15 @@ static void test_dispatch_cmd_success_response(void)/* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io (void ) { -QDict *req =qdict_new (); -QDict *args =qdict_new (); -QDict *args3 =qdict_new (); -QDict *ud1a =qdict_new (); -QDict *ud1b =qdict_new ();QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef;QDict *ret_dict_dict2, *ret_dict_dict2_userdef;QNum *ret3;int64_t val; -qdict_put_int (ud1a,"integer" ,42 ); -qdict_put_str (ud1a,"string" ,"hello" ); -qdict_put_int (ud1b,"integer" ,422 ); -qdict_put_str (ud1b,"string" ,"hello2" ); -qdict_put (args,"ud1a" , ud1a); -qdict_put (args,"ud1b" , ud1b); -qdict_put (req,"arguments" , args); -qdict_put_str (req,"execute" ,"user_def_cmd2" ); - - ret =qobject_to (QDict,do_qmp_dispatch (req, false)); + ret =qobject_to (QDict,do_qmp_dispatch (false, +"{ 'execute': 'user_def_cmd2', 'arguments': {" +" 'ud1a': { 'integer': 42, 'string': 'hello' }," +" 'ud1b': { 'integer': 422, 'string': 'hello2' } } }" ));assert (!strcmp (qdict_get_str (ret,"string0" ),"blah1" )); ret_dict =qdict_get_qdict (ret,"dict1" );
@@ -282,11 +268,8 @@ static void test_dispatch_cmd_io(void)assert (!strcmp (qdict_get_str (ret_dict_dict2,"string" ),"blah4" ));qobject_unref (ret); -qdict_put_int (args3,"a" ,66 ); -qdict_put (req,"arguments" , args3); -qdict_put_str (req,"execute" ,"guest-get-time" ); - - ret3 =qobject_to (QNum,do_qmp_dispatch (req, false)); + ret3 =qobject_to (QNum,do_qmp_dispatch (false, +"{ 'execute': 'guest-get-time', 'arguments': { 'a': 66 } }" ));g_assert (qnum_get_try_int (ret3, &val)); g_assert_cmpint(val, ==, 66);qobject_unref (ret3);
Signature · 1 line
2.21.1
PATCH v2 8/30 tests/test-qmp-event: Simplify test data setup
In reply to Markus ArmbrusterBuilding expected data with qdict_put() & friends is tedious to write and hard to read. Parse them from string literals with qdict_from_jsonf_nofail() instead.
While there, use initializers instead of assignments for initializing aggregate event arguments.
--- tests/test-qmp-event.c | 93 ++++++++++++------------------------------ 1 file changed, 27 insertions(+), 66 deletions(-)
tests/test-qmp-event.c +27 -66
@@ -17,6 +17,7 @@#include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp-event.h"
@@ -124,17 +125,13 @@ static void event_prepare(TestEventData *data,/* Global variable test_event_data was used to pass the expectation, so test cases can't be executed at same time. */ g_mutex_lock (&test_event_lock); - - data->expect =qdict_new (); test_event_data = data; }static void event_teardown (TestEventData *data,const void *unused) { -qobject_unref (data->expect); test_event_data =NULL ; -g_mutex_unlock (&test_event_lock); }
@@ -152,90 +149,54 @@ static void event_test_add(const char *testpath,static void test_event_a (TestEventData *data,const void *unused) { -QDict *d; - d = data->expect; -qdict_put_str (d,"event" ,"EVENT_A" ); + data->expect =qdict_from_jsonf_nofail ("{ 'event': 'EVENT_A' }" );qapi_event_send_event_a (); +qobject_unref (data->expect); }static void test_event_b (TestEventData *data,const void *unused) { -QDict *d; - d = data->expect; -qdict_put_str (d,"event" ,"EVENT_B" ); + data->expect =qdict_from_jsonf_nofail ("{ 'event': 'EVENT_B' }" );qapi_event_send_event_b (); +qobject_unref (data->expect); }static void test_event_c (TestEventData *data,const void *unused) { -QDict *d, *d_data, *d_b; - -UserDefOne b; - b.integer =2 ; - b.string =g_strdup ("test1" ); - b.has_enum1 = false; - - d_b =qdict_new (); -qdict_put_int (d_b,"integer" ,2 ); -qdict_put_str (d_b,"string" ,"test1" ); - - d_data =qdict_new (); -qdict_put_int (d_data,"a" ,1 ); -qdict_put (d_data,"b" , d_b); -qdict_put_str (d_data,"c" ,"test2" ); - - d = data->expect; -qdict_put_str (d,"event" ,"EVENT_C" ); -qdict_put (d,"data" , d_data); +UserDefOne b = { .integer =2 , .string = (char *)"test1" }; + data->expect =qdict_from_jsonf_nofail ( +"{ 'event': 'EVENT_C', 'data': {" +" 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' } }" );qapi_event_send_event_c (true,1 , true, &b,"test2" ); - -g_free (b.string); +qobject_unref (data->expect); }/* Complex type */ static void test_event_d (TestEventData *data,const void *unused) { -UserDefOne struct1; -EventStructOne a; -QDict *d, *d_data, *d_a, *d_struct1; - - struct1.integer =2 ; - struct1.string =g_strdup ("test1" ); - struct1.has_enum1 = true; - struct1.enum1 =ENUM_ONE_VALUE1 ; - - a.struct1 = &struct1; - a.string =g_strdup ("test2" ); - a.has_enum2 = true; - a.enum2 =ENUM_ONE_VALUE2 ; - - d_struct1 =qdict_new (); -qdict_put_int (d_struct1,"integer" ,2 ); -qdict_put_str (d_struct1,"string" ,"test1" ); -qdict_put_str (d_struct1,"enum1" ,"value1" ); - - d_a =qdict_new (); -qdict_put (d_a,"struct1" , d_struct1); -qdict_put_str (d_a,"string" ,"test2" ); -qdict_put_str (d_a,"enum2" ,"value2" ); - - d_data =qdict_new (); -qdict_put (d_data,"a" , d_a); -qdict_put_str (d_data,"b" ,"test3" ); -qdict_put_str (d_data,"enum3" ,"value3" ); - - d = data->expect; -qdict_put_str (d,"event" ,"EVENT_D" ); -qdict_put (d,"data" , d_data); +UserDefOne struct1 = { + .integer =2 , .string = (char *)"test1" , + .has_enum1 = true, .enum1 =ENUM_ONE_VALUE1 , + }; +EventStructOne a = { + .struct1 = &struct1, + .string = (char *)"test2" , + .has_enum2 = true, + .enum2 =ENUM_ONE_VALUE2 , + }; + data->expect =qdict_from_jsonf_nofail ( +"{ 'event': 'EVENT_D', 'data': {" +" 'a': {" +" 'struct1': { 'integer': 2, 'string': 'test1', 'enum1': 'value1' }," +" 'string': 'test2', 'enum2': 'value2' }," +" 'b': 'test3', 'enum3': 'value3' } }" );qapi_event_send_event_d (&a,"test3" , false,NULL , true,ENUM_ONE_VALUE3 ); - -g_free (struct1.string); -g_free (a.string); +qobject_unref (data->expect); }int main (int argc,char **argv)
Signature · 1 line
2.21.1
PATCH v2 9/30 tests/test-qmp-event: Use qobject_is_equal()
In reply to Markus ArmbrusterLocally defined helper qdict_cmp_simple() implements just enough of a comparison to serve here. Replace it by qobject_is_equal(), which implements all of it.
--- tests/test-qmp-event.c | 66 +----------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-)
tests/test-qmp-event.c +1 -65
@@ -28,73 +28,9 @@ typedef struct TestEventData {QDict *expect; } TestEventData; -typedef struct QDictCmpData { -QDict *expect; -bool result; -}QDictCmpData ; -TestEventData *test_event_data;static GMutex test_event_lock; -/* Only compares bool, int, string */ -static -void qdict_cmp_do_simple (const char *key,QObject *obj1,void *opaque) - -{ -QObject *obj2; -QDictCmpData d_new, *d = opaque; -int64_t val1, val2; - -if (!d->result) { -return ; - } - - obj2 =qdict_get (d->expect, key); -if (!obj2) { - d->result = false; -return ; - } - -if (qobject_type (obj1) !=qobject_type (obj2)) { - d->result = false; -return ; - } - -switch (qobject_type (obj1)) { -case QTYPE_QBOOL : - d->result = (qbool_get_bool (qobject_to (QBool, obj1)) == -qbool_get_bool (qobject_to (QBool, obj2))); -return ; -case QTYPE_QNUM : -g_assert (qnum_get_try_int (qobject_to (QNum, obj1), &val1)); -g_assert (qnum_get_try_int (qobject_to (QNum, obj2), &val2)); - d->result = val1 == val2; -return ; -case QTYPE_QSTRING : - d->result =g_strcmp0 (qstring_get_str (qobject_to (QString, obj1)), -qstring_get_str (qobject_to (QString, obj2))) ==0 ; -return ; -case QTYPE_QDICT : - d_new.expect =qobject_to (QDict, obj2); - d_new.result = true; -qdict_iter (qobject_to (QDict, obj1), qdict_cmp_do_simple, &d_new); - d->result = d_new.result; -return ; -default : -abort (); - } -} - -static bool qdict_cmp_simple (QDict *a,QDict *b) -{ -QDictCmpData d; - - d.expect = b; - d.result = true; -qdict_iter (a, qdict_cmp_do_simple, &d); -return d.result; -} -void test_qapi_event_emit (test_QAPIEvent event,QDict *d) {QDict *t;
@@ -115,7 +51,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d)qdict_del (d,"timestamp" ); -g_assert (qdict_cmp_simple (d, test_event_data->expect)); +g_assert (qobject_is_equal (QOBJECT (d),QOBJECT (test_event_data->expect))); }
Signature · 1 line
2.21.1
PATCH v2 10/30 tests/test-qmp-event: Check event is actually emitted
In reply to Markus Armbruster--- tests/test-qmp-event.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tests/test-qmp-event.c +6 -1
@@ -26,6 +26,7 @@typedef struct TestEventData {QDict *expect; +bool emitted; }TestEventData ;TestEventData *test_event_data;
@@ -52,7 +53,7 @@ void test_qapi_event_emit(test_QAPIEvent event, QDict *d)qdict_del (d,"timestamp" );g_assert (qobject_is_equal (QOBJECT (d),QOBJECT (test_event_data->expect))); - + test_event_data->emitted = true; } static void event_prepare(TestEventData *data,
@@ -87,6 +88,7 @@ static void test_event_a(TestEventData *data, { data->expect =qdict_from_jsonf_nofail ("{ 'event': 'EVENT_A' }" );qapi_event_send_event_a (); +g_assert (data->emitted);qobject_unref (data->expect); }
@@ -95,6 +97,7 @@ static void test_event_b(TestEventData *data, { data->expect =qdict_from_jsonf_nofail ("{ 'event': 'EVENT_B' }" );qapi_event_send_event_b (); +g_assert (data->emitted);qobject_unref (data->expect); }
@@ -107,6 +110,7 @@ static void test_event_c(TestEventData *data,"{ 'event': 'EVENT_C', 'data': {" " 'a': 1, 'b': { 'integer': 2, 'string': 'test1' }, 'c': 'test2' } }");qapi_event_send_event_c (true,1 , true, &b,"test2" ); +g_assert (data->emitted);qobject_unref (data->expect); }
@@ -132,6 +136,7 @@ static void test_event_d(TestEventData *data," 'string': 'test2', 'enum2': 'value2' }," " 'b': 'test3', 'enum3': 'value3' } }");qapi_event_send_event_d (&a,"test3" , false,NULL , true,ENUM_ONE_VALUE3 ); +g_assert (data->emitted);qobject_unref (data->expect); }
Signature · 1 line
2.21.1
PATCH v2 11/30 qapi/schema: Clean up around QAPISchemaEntity.connect_doc()
In reply to Markus ArmbrusterQAPISchemaEntity calls doc.connect_feature() in .check(). Improper since commit ee1e6a1f6c8 split .connect_doc() off .check(). Move the call. Requires making the children call super().connect_doc() as they should.
--- scripts/qapi/schema.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
scripts/qapi/schema.py +9 -4
@@ -53,13 +53,13 @@ class QAPISchemaEntity: seen = {} for f in self.features: f.check_clash(self.info, seen) - if self.doc: - self.doc.connect_feature(f) - self._checked = True def connect_doc(self, doc=None): - pass + doc = doc or self.doc + if doc: + for f in self.features: + doc.connect_feature(f) def check_doc(self): if self.doc:
@@ -250,6 +250,7 @@ class QAPISchemaEnumType(QAPISchemaType): m.check_clash(self.info, seen) def connect_doc(self, doc=None): + super().connect_doc(doc) doc = doc or self.doc if doc: for m in self.members:
@@ -392,6 +393,7 @@ class QAPISchemaObjectType(QAPISchemaType): m.check_clash(info, seen) def connect_doc(self, doc=None): + super().connect_doc(doc) doc = doc or self.doc if doc: if self.base and self.base.is_implicit():
@@ -668,6 +670,7 @@ class QAPISchemaAlternateType(QAPISchemaType): types_seen[qt] = v.name def connect_doc(self, doc=None): + super().connect_doc(doc) doc = doc or self.doc if doc: for v in self.variants.variants:
@@ -734,6 +737,7 @@ class QAPISchemaCommand(QAPISchemaEntity): % self.ret_type.describe()) def connect_doc(self, doc=None): + super().connect_doc(doc) doc = doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit():
@@ -776,6 +780,7 @@ class QAPISchemaEvent(QAPISchemaEntity): % self.arg_type.describe()) def connect_doc(self, doc=None): + super().connect_doc(doc) doc = doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit():
Signature · 1 line
2.21.1
PATCH v2 12/30 qapi: Add feature flags to remaining definitions
In reply to Markus ArmbrusterIn v4.1.0, we added feature flags just to struct types (commit 6a8c0b5102^..f3ed93d545), to satisfy an immediate need (commit c9d4070991 "file-posix: Add dynamic-auto-read-only QAPI feature"). In v4.2.0, we added them to commands (commit 23394b4c39 "qapi: Add feature flags to commands") to satisfy another immediate need (commit d76744e65e "qapi: Allow introspecting fix for savevm's cooperation with blockdev").
Add them to the remaining definitions: enumeration types, union types, alternate types, and events.
--- docs/devel/qapi-code-gen.txt | 54 +++++++++----- tests/qapi-schema/doc-good.texi | 30 ++++++++ qapi/introspect.json | 20 +++--- tests/test-qmp-cmds.c | 6 +- scripts/qapi/doc.py | 6 +- scripts/qapi/events.py | 2 +- scripts/qapi/expr.py | 11 ++- scripts/qapi/introspect.py | 31 ++++---- scripts/qapi/schema.py | 96 ++++++++++++++----------- scripts/qapi/types.py | 4 +- scripts/qapi/visit.py | 4 +- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/doc-good.json | 17 +++++ tests/qapi-schema/doc-good.out | 15 ++++ tests/qapi-schema/qapi-schema-test.json | 29 ++++++-- tests/qapi-schema/qapi-schema-test.out | 27 +++++-- tests/qapi-schema/test-qapi.py | 9 ++- 17 files changed, 242 insertions(+), 121 deletions(-)
docs/devel/qapi-code-gen.txt +38 -16
@@ -172,7 +172,8 @@ Syntax: ENUM = { 'enum': STRING, 'data': [ ENUM-VALUE, ... ], '*prefix': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } ENUM-VALUE = STRING | { 'name': STRING, '*if': COND }
@@ -207,6 +208,9 @@ the job satisfactorily. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. +The optional 'features' member specifies features. See "Features" +below for more on this. + === Type references and array types ===
@@ -279,12 +283,14 @@ below for more on this. Syntax: UNION = { 'union': STRING, 'data': BRANCHES, - '*if': COND } + '*if': COND, + '*features': FEATURES } | { 'union': STRING, 'data': BRANCHES, 'base': ( MEMBERS | STRING ), 'discriminator': STRING, - '*if': COND } + '*if': COND, + '*features': FEATURES } BRANCHES = { BRANCH, ... } BRANCH = STRING : TYPE-REF | STRING : { 'type': TYPE-REF, '*if': COND }
@@ -391,13 +397,17 @@ is identical on the wire to: The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. +The optional 'features' member specifies features. See "Features" +below for more on this. + === Alternate types === Syntax: ALTERNATE = { 'alternate': STRING, 'data': ALTERNATIVES, - '*if': COND } + '*if': COND, + '*features': FEATURES } ALTERNATIVES = { ALTERNATIVE, ... } ALTERNATIVE = STRING : TYPE-REF | STRING : { 'type': STRING, '*if': COND }
@@ -441,6 +451,9 @@ following example objects: The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. +The optional 'features' member specifies features. See "Features" +below for more on this. + === Commands ===
@@ -584,6 +597,9 @@ started with --preconfig. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. +The optional 'features' member specifies features. See "Features" +below for more on this. + === Events ===
@@ -595,7 +611,8 @@ Syntax: 'data': STRING, 'boxed': true, ) - '*if': COND } + '*if': COND, + '*features': FEATURES } Member 'event' names the event. This is the event name used in the Client JSON Protocol.
@@ -628,6 +645,9 @@ complex type. See section "Code generated for events" for examples. The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. +The optional 'features' member specifies features. See "Features" +below for more on this. + === Features ===
@@ -966,8 +986,9 @@ schema, along with the SchemaInfo type. This text attempts to give an overview how things work. For details you need to consult the QAPI schema. -SchemaInfo objects have common members "name", "meta-type", and -additional variant members depending on the value of meta-type. +SchemaInfo objects have common members "name", "meta-type", +"features", and additional variant members depending on the value of +meta-type. Each SchemaInfo object describes a wire ABI entity of a certain meta-type: a command, event or one of several kinds of type.
@@ -980,19 +1001,21 @@ not. Therefore, the SchemaInfo for types have auto-generated meaningless names. For readability, the examples in this section use meaningful type names instead. +Optional member "features" exposes the entity's feature strings as a +JSON array of strings. + To examine a type, start with a command or event using it, then follow references by name. QAPI schema definitions not reachable that way are omitted. The SchemaInfo for a command has meta-type "command", and variant -members "arg-type", "ret-type", "allow-oob", and "features". On the -wire, the "arguments" member of a client's "execute" command must -conform to the object type named by "arg-type". The "return" member -that the server passes in a success response conforms to the type -named by "ret-type". When "allow-oob" is true, it means the command -supports out-of-band execution. It defaults to false. "features" -exposes the command's feature strings as a JSON array of strings. +members "arg-type", "ret-type" and "allow-oob". On the wire, the +"arguments" member of a client's "execute" command must conform to the +object type named by "arg-type". The "return" member that the server +passes in a success response conforms to the type named by "ret-type". +When "allow-oob" is true, it means the command supports out-of-band +execution. It defaults to false. If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type"
@@ -1027,8 +1050,7 @@ Example: the SchemaInfo for EVENT_C from section Events The SchemaInfo for struct and union types has meta-type "object". -The SchemaInfo for a struct type has variant members "members" and -"features". +The SchemaInfo for a struct type has variant member "members". The SchemaInfo for a union type additionally has variant members "tag" and "variants".
tests/qapi-schema/doc-good.texi +30 -0
@@ -88,6 +88,12 @@ The @emph{one} @{and only@} @item @code{two} Not documented @end table + +@b{Features:} +@table @asis +@item @code{enum-feat} +Also @emph{one} @{and only@} +@end table @code{two} is undocumented @b{If:} @code{defined(IFCOND)}
@@ -151,6 +157,12 @@ a feature @item The members of @code{Variant2} when @code{base1} is @t{"two"} (@b{If:} @code{IFTWO}) @end table +@b{Features:} +@table @asis +@item @code{union-feat1} +a feature +@end table + @end deftp
@@ -167,6 +179,12 @@ One of @t{"one"}, @t{"two"} @item @code{data: Variant2} when @code{type} is @t{"two"} (@b{If:} @code{IFTWO}) @end table +@b{Features:} +@table @asis +@item @code{union-feat2} +a feature +@end table + @end deftp
@@ -184,6 +202,12 @@ an integer Not documented @end table +@b{Features:} +@table @asis +@item @code{alt-feat} +a feature +@end table + @end deftp
@@ -283,5 +307,11 @@ another feature @b{Arguments:} the members of @code{Object} +@b{Features:} +@table @asis +@item @code{feat3} +a feature +@end table + @end deftypefn
qapi/introspect.json +9 -11
@@ -89,12 +89,18 @@ # # @meta-type: the entity's meta type, inherited from @base. # +# @features: names of features associated with the entity, in no +# particular order. +# (since 4.1 for object types, 4.2 for commands, 5.0 for +# the rest) +# # Additional members depend on the value of @meta-type. # # Since: 2.5 ## { 'union': 'SchemaInfo', - 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType' }, + 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType', + '*features': [ 'str' ] }, 'discriminator': 'meta-type', 'data': { 'builtin': 'SchemaInfoBuiltin',
@@ -174,9 +180,6 @@ # and may even differ from the order of the values of the # enum type of the @tag. # -# @features: names of features associated with the type, in no particular -# order. (since: 4.1) -# # Values of this type are JSON object on the wire. # # Since: 2.5
@@ -184,8 +187,7 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ], - '*features': [ 'str' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ] } } ## # @SchemaInfoObjectMember:
@@ -266,17 +268,13 @@ # @allow-oob: whether the command allows out-of-band execution, # defaults to false (Since: 2.12) # -# @features: names of features associated with the command, in no particular -# order. (since 4.2) -# # TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ## { 'struct': 'SchemaInfoCommand', 'data': { 'arg-type': 'str', 'ret-type': 'str', - '*allow-oob': 'bool', - '*features': [ 'str' ] } } + '*allow-oob': 'bool' } } ## # @SchemaInfoEvent:
tests/test-qmp-cmds.c +1 -5
@@ -45,7 +45,7 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp) { } -void qmp_test_features(FeatureStruct0 *fs0, FeatureStruct1 *fs1, +void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruct1 *fs1, FeatureStruct2 *fs2, FeatureStruct3 *fs3, FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1, CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3,
@@ -53,10 +53,6 @@ void qmp_test_features(FeatureStruct0 *fs0, FeatureStruct1 *fs1, { } -void qmp_test_command_features0 (Error **errp) -{ -} -void qmp_test_command_features1 (Error **errp) { }
scripts/qapi/doc.py +3 -3
@@ -243,7 +243,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): def write(self, output_dir): self._gen.write(output_dir) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): doc = self.cur_doc self._gen.add(texi_type('Enum', doc, ifcond, texi_members(doc, 'Values',
@@ -257,7 +257,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Object', doc, ifcond, texi_members(doc, 'Members', base, variants))) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): doc = self.cur_doc self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members')))
@@ -270,7 +270,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_arguments(doc, arg_type if boxed else None))) - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): doc = self.cur_doc self._gen.add(texi_msg('Event', doc, ifcond, texi_arguments(doc,
scripts/qapi/events.py +1 -1
@@ -189,7 +189,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); event_emit=self._event_emit_name, event_enum=self._event_enum_name)) - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) self._genc.add(gen_event_send(name, arg_type, boxed,
scripts/qapi/expr.py +5 -6
@@ -219,7 +219,6 @@ def check_struct(expr, info): check_type(members, info, "'data'", allow_dict=name) check_type(expr.get('base'), info, "'base'") - check_features(expr.get('features'), info) def check_union(expr, info):
@@ -267,7 +266,6 @@ def check_command(expr, info): raise QAPISemError(info, "'boxed': true requires 'data'") check_type(args, info, "'data'", allow_dict=not boxed) check_type(rets, info, "'returns'", allow_array=True) - check_features(expr.get('features'), info) def check_event(expr, info):
@@ -319,18 +317,18 @@ def check_exprs(exprs): if meta == 'enum': check_keys(expr, info, meta, - ['enum', 'data'], ['if', 'prefix']) + ['enum', 'data'], ['if', 'features', 'prefix']) check_enum(expr, info) elif meta == 'union': check_keys(expr, info, meta, ['union', 'data'], - ['base', 'discriminator', 'if']) + ['base', 'discriminator', 'if', 'features']) normalize_members(expr.get('base')) normalize_members(expr['data']) check_union(expr, info) elif meta == 'alternate': check_keys(expr, info, meta, - ['alternate', 'data'], ['if']) + ['alternate', 'data'], ['if', 'features']) normalize_members(expr['data']) check_alternate(expr, info) elif meta == 'struct':
@@ -348,13 +346,14 @@ def check_exprs(exprs): check_command(expr, info) elif meta == 'event': check_keys(expr, info, meta, - ['event'], ['data', 'boxed', 'if']) + ['event'], ['data', 'boxed', 'if', 'features']) normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' check_if(expr, info, meta) + check_features(expr.get('features'), info) check_flags(expr, info) return exprs
scripts/qapi/introspect.py +14 -17
@@ -144,7 +144,7 @@ const QLitObject %(c_name)s = %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) - def _gen_qlit(self, name, mtype, obj, ifcond): + def _gen_qlit(self, name, mtype, obj, ifcond, features): extra = {} if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask:
@@ -154,6 +154,8 @@ const QLitObject %(c_name)s = %(c_string)s; name = self._name(name) obj['name'] = name obj['meta-type'] = mtype + if features: + obj['features'] = [(f.name, {'if': f.ifcond}) for f in features] if ifcond: extra['if'] = ifcond if extra:
@@ -178,18 +180,18 @@ const QLitObject %(c_name)s = %(c_string)s; {'if': variant.ifcond}) def visit_builtin_type(self, name, info, json_type): - self._gen_qlit(name, 'builtin', {'json-type': json_type}, []) + self._gen_qlit(name, 'builtin', {'json-type': json_type}, [], None) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): self._gen_qlit(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, - ifcond) + ifcond, features) def visit_array_type(self, name, info, ifcond, element_type): element = self._use_type(element_type) self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, - ifcond) + ifcond, None) def visit_object_type_flat(self, name, info, ifcond, members, variants, features):
@@ -197,16 +199,15 @@ const QLitObject %(c_name)s = %(c_string)s; if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - if features: - obj['features'] = [(f.name, {'if': f.ifcond}) for f in features] - self._gen_qlit(name, 'object', obj, ifcond) + self._gen_qlit(name, 'object', obj, ifcond, features) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_qlit(name, 'alternate', {'members': [ ({'type': self._use_type(m.type)}, {'if': m.ifcond}) - for m in variants.variants]}, ifcond) + for m in variants.variants]}, + ifcond, features) def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig,
@@ -217,16 +218,12 @@ const QLitObject %(c_name)s = %(c_string)s; 'ret-type': self._use_type(ret_type)} if allow_oob: obj['allow-oob'] = allow_oob + self._gen_qlit(name, 'command', obj, ifcond, features) - if features: - obj['features'] = [(f.name, {'if': f.ifcond}) for f in features] - - self._gen_qlit(name, 'command', obj, ifcond) - - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): arg_type = arg_type or self._schema.the_empty_object_type self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)}, - ifcond) + ifcond, features) def gen_introspect(schema, output_dir, prefix, opt_unmask):
scripts/qapi/schema.py +53 -43
251 lines not on this page · raw message
scripts/qapi/types.py +2 -2
@@ -278,7 +278,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_enum(name, members, prefix)) self._genc.add(gen_enum_lookup(name, members, prefix))
@@ -306,7 +306,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, None,
scripts/qapi/visit.py +2 -2
@@ -316,7 +316,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): ''', types=types)) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=True)) self._genc.add(gen_visit_enum(name))
@@ -342,7 +342,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name, base, members, variants)) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants))
tests/qapi-schema/alternate-base.err +1 -1
@@ -1,3 +1,3 @@ alternate-base.json: In alternate 'Alt': alternate-base.json:4: alternate has unknown key 'base' -Valid keys are 'alternate', 'data', 'if'. +Valid keys are 'alternate', 'data', 'features', 'if'.
tests/qapi-schema/doc-good.json +17 -0
@@ -53,10 +53,14 @@ # @Enum: # @one: The _one_ {and only} # +# Features: +# @enum-feat: Also _one_ {and only} +# # @two is undocumented ## { 'enum': 'Enum', 'data': [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ], + 'features': [ 'enum-feat' ], 'if': 'defined(IFCOND)' } ##
@@ -86,24 +90,34 @@ ## # @Object: +# Features: +# @union-feat1: a feature ## { 'union': 'Object', + 'features': [ 'union-feat1' ], 'base': 'Base', 'discriminator': 'base1', 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } } ## # @SugaredUnion: +# Features: +# @union-feat2: a feature ## { 'union': 'SugaredUnion', + 'features': [ 'union-feat2' ], 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } } ## # @Alternate: # @i: an integer # @b is undocumented +# +# Features: +# @alt-feat: a feature ## { 'alternate': 'Alternate', + 'features': [ 'alt-feat' ], 'data': { 'i': 'int', 'b': 'bool' } } ##
@@ -160,6 +174,9 @@ ## # @EVT-BOXED: +# Features: +# @feat3: a feature ## { 'event': 'EVT-BOXED', 'boxed': true, + 'features': [ 'feat3' ], 'data': 'Object' }
tests/qapi-schema/doc-good.out +15 -0
@@ -15,6 +15,7 @@ enum Enum if ['defined(IFONE)'] member two if ['defined(IFCOND)'] + feature enum-feat object Base member base1: Enum optional=False object Variant1
@@ -28,6 +29,7 @@ object Object case one: Variant1 case two: Variant2 if ['IFTWO'] + feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=False object q_obj_Variant2-wrapper
@@ -42,10 +44,12 @@ object SugaredUnion case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper if ['IFTWO'] + feature union-feat2 alternate Alternate tag type case i: int case b: bool + feature alt-feat object q_obj_cmd-arg member arg1: int optional=False member arg2: str optional=True
@@ -60,6 +64,7 @@ command cmd-boxed Object -> None feature cmd-feat2 event EVT-BOXED Object boxed=True + feature feat3 doc freeform body= = Section
@@ -112,6 +117,8 @@ doc symbol=Enum The _one_ {and only} arg=two + feature=enum-feat +Also _one_ {and only} section=None @two is undocumented doc symbol=Base
@@ -134,11 +141,15 @@ doc symbol=Variant2 doc symbol=Object body= + feature=union-feat1 +a feature doc symbol=SugaredUnion body= arg=type + feature=union-feat2 +a feature doc symbol=Alternate body=
@@ -147,6 +158,8 @@ an integer @b is undocumented arg=b + feature=alt-feat +a feature doc freeform body= == Another subsection
@@ -197,3 +210,5 @@ another feature doc symbol=EVT-BOXED body= + feature=feat3 +a feature
tests/qapi-schema/qapi-schema-test.json +22 -7
@@ -252,7 +252,7 @@ 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } -# test 'features' for structs +# test 'features' { 'struct': 'FeatureStruct0', 'data': { 'foo': 'int' },
@@ -281,7 +281,22 @@ 'data': { 'foo': 'int' }, 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] } ] } -{ 'command': 'test-features', + +{ 'enum': 'FeatureEnum1', + 'data': [ 'eins', 'zwei', 'drei' ], + 'features': [ 'feature1' ] } + +{ 'union': 'FeatureUnion1', + 'base': { 'tag': 'FeatureEnum1' }, + 'discriminator': 'tag', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'alternate': 'FeatureAlternate1', + 'data': { 'eins': 'FeatureStruct1' }, + 'features': [ 'feature1' ] } + +{ 'command': 'test-features0', 'data': { 'fs0': 'FeatureStruct0', 'fs1': 'FeatureStruct1', 'fs2': 'FeatureStruct2',
@@ -289,12 +304,9 @@ 'fs4': 'FeatureStruct4', 'cfs1': 'CondFeatureStruct1', 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' } } - -# test 'features' for command - -{ 'command': 'test-command-features0', + 'cfs3': 'CondFeatureStruct3' }, 'features': [] } + { 'command': 'test-command-features1', 'features': [ 'feature1' ] } { 'command': 'test-command-features3',
@@ -308,3 +320,6 @@ { 'command': 'test-command-cond-features3', 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] } ] } + +{ 'event': 'TEST-EVENT-FEATURES1', + 'features': [ 'feature1' ] }
tests/qapi-schema/qapi-schema-test.out +23 -4
@@ -387,7 +387,25 @@ object CondFeatureStruct3 member foo: int optional=False feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] -object q_obj_test-features-arg +enum FeatureEnum1 + member eins + member zwei + member drei + feature feature1 +object q_obj_FeatureUnion1-base + member tag: FeatureEnum1 optional=False +object FeatureUnion1 + base q_obj_FeatureUnion1-base + tag tag + case eins: FeatureStruct1 + case zwei: q_empty + case drei: q_empty + feature feature1 +alternate FeatureAlternate1 + tag type + case eins: FeatureStruct1 + feature feature1 +object q_obj_test-features0-arg member fs0: FeatureStruct0 optional=False member fs1: FeatureStruct1 optional=False member fs2: FeatureStruct2 optional=False
@@ -396,9 +414,7 @@ object q_obj_test-features-arg member cfs1: CondFeatureStruct1 optional=False member cfs2: CondFeatureStruct2 optional=False member cfs3: CondFeatureStruct3 optional=False -command test-features q_obj_test-features-arg -> None - gen=True success_response=True boxed=False oob=False preconfig=False -command test-command-features0 None -> None +command test-features0 q_obj_test-features0-arg -> None gen=True success_response=True boxed=False oob=False preconfig=False command test-command-features1 None -> None gen=True success_response=True boxed=False oob=False preconfig=False
@@ -421,6 +437,9 @@ command test-command-cond-features3 None -> None gen=True success_response=True boxed=False oob=False preconfig=False feature feature1 if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] +event TEST-EVENT-FEATURES1 None + boxed=False + feature feature1 module include/sub-module.json include sub-sub-module.json object SecondArrayRef
tests/qapi-schema/test-qapi.py +6 -3
@@ -30,7 +30,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_include(self, name, info): print('include %s' % name) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): print('enum %s' % name) if prefix: print(' prefix %s' % prefix)
@@ -38,6 +38,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s' % m.name) self._print_if(m.ifcond, indent=8) self._print_if(ifcond) + self._print_features(features) def visit_array_type(self, name, info, ifcond, element_type): if not info:
@@ -58,10 +59,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): print('alternate %s' % name) self._print_variants(variants) self._print_if(ifcond) + self._print_features(features) def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig,
@@ -74,10 +76,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): print('event %s %s' % (name, arg_type and arg_type.name)) print(' boxed=%s' % boxed) self._print_if(ifcond) + self._print_features(features) @staticmethod def _print_variants(variants):
Signature · 1 line
2.21.1
PATCH v2 13/30 qapi: Consistently put @features parameter right after @ifcond
In reply to Markus Armbruster--- scripts/qapi/commands.py | 6 +++--- scripts/qapi/doc.py | 10 +++++----- scripts/qapi/introspect.py | 10 +++++----- scripts/qapi/schema.py | 36 ++++++++++++++++------------------ scripts/qapi/types.py | 4 ++-- scripts/qapi/visit.py | 4 ++-- tests/qapi-schema/test-qapi.py | 10 +++++----- 7 files changed, 39 insertions(+), 41 deletions(-)
scripts/qapi/commands.py +3 -3
@@ -283,9 +283,9 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); prefix=self._prefix)) self._genc.add(gen_registry(self._regy.get_content(), self._prefix)) - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): if not gen: return # FIXME: If T is a user-defined type, the user is responsible
scripts/qapi/doc.py +5 -5
@@ -249,8 +249,8 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_members(doc, 'Values', member_func=texi_enum_value))) - def visit_object_type(self, name, info, ifcond, base, members, variants, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): doc = self.cur_doc if base and base.is_implicit(): base = None
@@ -262,9 +262,9 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): doc = self.cur_doc self._gen.add(texi_msg('Command', doc, ifcond, texi_arguments(doc,
scripts/qapi/introspect.py +5 -5
@@ -193,8 +193,8 @@ const QLitObject %(c_name)s = %(c_string)s; self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, ifcond, None) - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, ifcond, features, + members, variants): obj = {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name,
@@ -209,9 +209,9 @@ const QLitObject %(c_name)s = %(c_string)s; for m in variants.variants]}, ifcond, features) - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): arg_type = arg_type or self._schema.the_empty_object_type ret_type = ret_type or self._schema.the_empty_object_type obj = {'arg-type': self._use_type(arg_type),
scripts/qapi/schema.py +17 -19
@@ -115,20 +115,20 @@ class QAPISchemaVisitor: def visit_array_type(self, name, info, ifcond, element_type): pass - def visit_object_type(self, name, info, ifcond, base, members, variants, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): pass - def visit_object_type_flat(self, name, info, ifcond, members, variants, - features): + def visit_object_type_flat(self, name, info, ifcond, features, + members, variants): pass def visit_alternate_type(self, name, info, ifcond, features, variants): pass - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): pass def visit_event(self, name, info, ifcond, features, arg_type, boxed):
@@ -436,12 +436,12 @@ class QAPISchemaObjectType(QAPISchemaType): def visit(self, visitor): super().visit(visitor) - visitor.visit_object_type(self.name, self.info, self.ifcond, - 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.features) + visitor.visit_object_type( + self.name, self.info, self.ifcond, self.features, + self.base, self.local_members, self.variants) + visitor.visit_object_type_flat( + self.name, self.info, self.ifcond, self.features, + self.members, self.variants) class QAPISchemaMember:
@@ -746,12 +746,10 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): super().visit(visitor) - visitor.visit_command(self.name, self.info, self.ifcond, - self.arg_type, self.ret_type, - self.gen, self.success_response, - self.boxed, self.allow_oob, - self.allow_preconfig, - self.features) + visitor.visit_command( + self.name, self.info, self.ifcond, self.features, + self.arg_type, self.ret_type, self.gen, self.success_response, + self.boxed, self.allow_oob, self.allow_preconfig) class QAPISchemaEvent(QAPISchemaEntity):
scripts/qapi/types.py +2 -2
@@ -289,8 +289,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, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name == 'q_empty': return
scripts/qapi/visit.py +2 -2
@@ -326,8 +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, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): # Nothing to do for the special empty builtin if name == 'q_empty': return
tests/qapi-schema/test-qapi.py +5 -5
@@ -46,8 +46,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, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): print('object %s' % name) if base: print(' base %s' % base.name)
@@ -65,9 +65,9 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_if(ifcond) self._print_features(features) - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): print('command %s %s -> %s' % (name, arg_type and arg_type.name, ret_type and ret_type.name))
Signature · 1 line
2.21.1
PATCH v2 14/30 qapi/introspect: Rename *qlit* to reduce confusion
In reply to Markus ArmbrusterWe generate the value of qmp_schema_qlit from an expression tree. The function doing that is named to_qlit(), and its inputs are accumulated in QAPISchemaGenIntrospectVisitor._qlits. We call both its input and its output "qlit". This is confusing.
Use "tree" for input, and "qlit" only for output: rename to_qlit() to _tree_to_qlit(), ._qlits to ._trees, ._gen_qlit() to ._gen_tree().
--- scripts/qapi/introspect.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
scripts/qapi/introspect.py +18 -17
@@ -16,7 +16,7 @@ from qapi.schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, QAPISchemaType) -def to_qlit(obj, level=0, suppress_first_indent=False): +def _tree_to_qlit(obj, level=0, suppress_first_indent=False): def indent(level): return level * 4 * ' '
@@ -30,7 +30,7 @@ def to_qlit(obj, level=0, suppress_first_indent=False): ret += indent(level) + '/* %s */\n' % comment if ifcond: ret += gen_if(ifcond) - ret += to_qlit(ifobj, level) + ret += _tree_to_qlit(ifobj, level) if ifcond: ret += '\n' + gen_endif(ifcond) return ret
@@ -43,7 +43,7 @@ def to_qlit(obj, level=0, suppress_first_indent=False): elif isinstance(obj, str): ret += 'QLIT_QSTR(' + to_c_string(obj) + ')' elif isinstance(obj, list): - elts = [to_qlit(elt, level + 1).strip('\n') + elts = [_tree_to_qlit(elt, level + 1).strip('\n') for elt in obj] elts.append(indent(level + 1) + "{}") ret += 'QLIT_QLIST(((QLitObject[]) {\n'
@@ -53,7 +53,8 @@ def to_qlit(obj, level=0, suppress_first_indent=False): elts = [] for key, value in sorted(obj.items()): elts.append(indent(level + 1) + '{ %s, %s }' % - (to_c_string(key), to_qlit(value, level + 1, True))) + (to_c_string(key), + _tree_to_qlit(value, level + 1, True))) elts.append(indent(level + 1) + '{}') ret += 'QLIT_QDICT(((QLitDictEntry[]) {\n' ret += ',\n'.join(elts) + '\n'
@@ -79,7 +80,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): ' * QAPI/QMP schema introspection', __doc__) self._unmask = unmask self._schema = None - self._qlits = [] + self._trees = [] self._used_types = [] self._name_map = {} self._genc.add(mcgen('''
@@ -108,9 +109,9 @@ extern const QLitObject %(c_name)s; const QLitObject %(c_name)s = %(c_string)s; ''', c_name=c_name(name), - c_string=to_qlit(self._qlits))) + c_string=_tree_to_qlit(self._trees))) self._schema = None - self._qlits = [] + self._trees = [] self._used_types = [] self._name_map = {}
@@ -144,7 +145,7 @@ const QLitObject %(c_name)s = %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) - def _gen_qlit(self, name, mtype, obj, ifcond, features): + def _gen_tree(self, name, mtype, obj, ifcond, features): extra = {} if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask:
@@ -159,9 +160,9 @@ const QLitObject %(c_name)s = %(c_string)s; if ifcond: extra['if'] = ifcond if extra: - self._qlits.append((obj, extra)) + self._trees.append((obj, extra)) else: - self._qlits.append(obj) + self._trees.append(obj) def _gen_member(self, member): ret = {'name': member.name, 'type': self._use_type(member.type)}
@@ -180,17 +181,17 @@ const QLitObject %(c_name)s = %(c_string)s; {'if': variant.ifcond}) def visit_builtin_type(self, name, info, json_type): - self._gen_qlit(name, 'builtin', {'json-type': json_type}, [], None) + self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) def visit_enum_type(self, name, info, ifcond, features, members, prefix): - self._gen_qlit(name, 'enum', + self._gen_tree(name, 'enum', {'values': [(m.name, {'if': m.ifcond}) for m in members]}, ifcond, features) def visit_array_type(self, name, info, ifcond, element_type): element = self._use_type(element_type) - self._gen_qlit('[' + element + ']', 'array', {'element-type': element}, + self._gen_tree('[' + element + ']', 'array', {'element-type': element}, ifcond, None) def visit_object_type_flat(self, name, info, ifcond, features,
@@ -200,10 +201,10 @@ const QLitObject %(c_name)s = %(c_string)s; obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - self._gen_qlit(name, 'object', obj, ifcond, features) + self._gen_tree(name, 'object', obj, ifcond, features) def visit_alternate_type(self, name, info, ifcond, features, variants): - self._gen_qlit(name, 'alternate', + self._gen_tree(name, 'alternate', {'members': [ ({'type': self._use_type(m.type)}, {'if': m.ifcond}) for m in variants.variants]},
@@ -218,11 +219,11 @@ const QLitObject %(c_name)s = %(c_string)s; 'ret-type': self._use_type(ret_type)} if allow_oob: obj['allow-oob'] = allow_oob - self._gen_qlit(name, 'command', obj, ifcond, features) + self._gen_tree(name, 'command', obj, ifcond, features) def visit_event(self, name, info, ifcond, features, arg_type, boxed): arg_type = arg_type or self._schema.the_empty_object_type - self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)}, + self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type)}, ifcond, features)
Signature · 1 line
2.21.1
PATCH v2 15/30 qapi/introspect: Factor out _make_tree()
In reply to Markus ArmbrusterThe value of @qmp_schema_qlit is generated from an expression tree. Tree nodes are created in several places. Factor out the common code into _make_tree(). This isn't much of a win now. It will pay off when we add feature flags in the next few commits.
--- scripts/qapi/introspect.py | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-)
scripts/qapi/introspect.py +24 -20
@@ -16,6 +16,18 @@ from qapi.schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, QAPISchemaType) +def _make_tree(obj, ifcond, features, extra=None): + if extra is None: + extra = {} + if ifcond: + extra['if'] = ifcond + if features: + obj['features'] = [(f.name, {'if': f.ifcond}) for f in features] + if extra: + return (obj, extra) + return obj + + def _tree_to_qlit(obj, level=0, suppress_first_indent=False): def indent(level):
@@ -146,47 +158,38 @@ const QLitObject %(c_name)s = %(c_string)s; return self._name(typ.name) def _gen_tree(self, name, mtype, obj, ifcond, features): - extra = {} + extra = None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra['comment'] = '"%s" = %s' % (self._name(name), name) + extra = {'comment': '"%s" = %s' % (self._name(name), name)} name = self._name(name) obj['name'] = name obj['meta-type'] = mtype - if features: - obj['features'] = [(f.name, {'if': f.ifcond}) for f in features] - if ifcond: - extra['if'] = ifcond - if extra: - self._trees.append((obj, extra)) - else: - self._trees.append(obj) + self._trees.append(_make_tree(obj, ifcond, features, extra)) def _gen_member(self, member): - ret = {'name': member.name, 'type': self._use_type(member.type)} + obj = {'name': member.name, 'type': self._use_type(member.type)} if member.optional: - ret['default'] = None - if member.ifcond: - ret = (ret, {'if': member.ifcond}) - return ret + obj['default'] = None + return _make_tree(obj, member.ifcond, None) def _gen_variants(self, tag_name, variants): return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} def _gen_variant(self, variant): - return ({'case': variant.name, 'type': self._use_type(variant.type)}, - {'if': variant.ifcond}) + obj = {'case': variant.name, 'type': self._use_type(variant.type)} + return _make_tree(obj, variant.ifcond, None) def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) def visit_enum_type(self, name, info, ifcond, features, members, prefix): self._gen_tree(name, 'enum', - {'values': - [(m.name, {'if': m.ifcond}) for m in members]}, + {'values': [_make_tree(m.name, m.ifcond, None) + for m in members]}, ifcond, features) def visit_array_type(self, name, info, ifcond, element_type):
@@ -206,7 +209,8 @@ const QLitObject %(c_name)s = %(c_string)s; def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_tree(name, 'alternate', {'members': [ - ({'type': self._use_type(m.type)}, {'if': m.ifcond}) + _make_tree({'type': self._use_type(m.type)}, + m.ifcond, None) for m in variants.variants]}, ifcond, features)
Signature · 1 line
2.21.1
PATCH v2 16/30 qapi/schema: Change _make_features() to a take feature list
In reply to Markus ArmbrusterQAPISchema._make_features() takes a definition expression, and extracts its 'features' member. The other ._make_FOO() leave destructuring expressions to their callers. Change ._make_features() to match them.
--- scripts/qapi/schema.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
scripts/qapi/schema.py +9 -8
@@ -905,8 +905,9 @@ class QAPISchema: self._def_entity(QAPISchemaEnumType('QType', None, None, None, None, qtype_values, 'QTYPE')) - def _make_features(self, expr, info): - features = expr.get('features', []) + def _make_features(self, features, info): + if features is None: + return [] return [QAPISchemaFeature(f['name'], info, f.get('if')) for f in features]
@@ -956,7 +957,7 @@ class QAPISchema: data = expr['data'] prefix = expr.get('prefix') ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaEnumType( name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix))
@@ -980,7 +981,7 @@ class QAPISchema: base = expr.get('base') data = expr['data'] ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaObjectType( name, info, doc, ifcond, features, base, self._make_members(data, info),
@@ -1003,7 +1004,7 @@ class QAPISchema: data = expr['data'] base = expr.get('base') ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) tag_name = expr.get('discriminator') tag_member = None if isinstance(base, dict):
@@ -1033,7 +1034,7 @@ class QAPISchema: name = expr['alternate'] data = expr['data'] ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) variants = [self._make_variant(key, value['type'], value.get('if'), info) for (key, value) in data.items()]
@@ -1053,7 +1054,7 @@ class QAPISchema: allow_oob = expr.get('allow-oob', False) allow_preconfig = expr.get('allow-preconfig', False) ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data = self._make_implicit_object_type( name, info, ifcond,
@@ -1071,7 +1072,7 @@ class QAPISchema: data = expr.get('data') boxed = expr.get('boxed', False) ifcond = expr.get('if') - features = self._make_features(expr, info) + features = self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data = self._make_implicit_object_type( name, info, ifcond,
Signature · 1 line
2.21.1
PATCH v2 17/30 qapi/schema: Reorder classes so related ones are together
In reply to Markus ArmbrusterMove QAPISchemaAlternateType up some, so that all QAPISchemaFOOType are together. Move QAPISchemaObjectTypeVariants right behind its users.
--- scripts/qapi/schema.py | 284 ++++++++++++++++++++--------------------- 1 file changed, 142 insertions(+), 142 deletions(-)
scripts/qapi/schema.py +142 -142
@@ -444,82 +444,72 @@ class QAPISchemaObjectType(QAPISchemaType): self.members, self.variants) -class QAPISchemaMember: - """ Represents object members, enum members and features """ - role = 'member' - - def __init__(self, name, info, ifcond=None): - assert isinstance(name, str) - self.name = name - self.info = info - self.ifcond = ifcond or [] - self.defined_in = None - - def set_defined_in(self, name): - assert not self.defined_in - self.defined_in = name - - def check_clash(self, info, seen): - cname = c_name(self.name) - if cname in seen: - raise QAPISemError( - info, - "%s collides with %s" - % (self.describe(info), seen[cname].describe(info))) - seen[cname] = self - - def describe(self, info): - role = self.role - defined_in = self.defined_in - assert defined_in - - if defined_in.startswith('q_obj_'): - # See QAPISchema._make_implicit_object_type() - reverse the - # mapping there to create a nice human-readable description - defined_in = defined_in[6:] - if defined_in.endswith('-arg'): - # Implicit type created for a command's dict 'data' - assert role == 'member' - role = 'parameter' - elif defined_in.endswith('-base'): - # Implicit type created for a flat union's dict 'base' - role = 'base ' + role - else: - # Implicit type created for a simple union's branch - assert defined_in.endswith('-wrapper') - # Unreachable and not implemented - assert False - elif defined_in.endswith('Kind'): - # See QAPISchema._make_implicit_enum_type() - # Implicit enum created for simple union's branches - assert role == 'value' - role = 'branch' - elif defined_in != info.defn_name: - return "%s '%s' of type '%s'" % (role, self.name, defined_in) - return "%s '%s'" % (role, self.name) - - -class QAPISchemaEnumMember(QAPISchemaMember): - role = 'value' - - -class QAPISchemaFeature(QAPISchemaMember): - role = 'feature' - - -class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=None): - super().__init__(name, info, ifcond) - assert isinstance(typ, str) - assert isinstance(optional, bool) - self._type_name = typ - self.type = None - self.optional = optional +class QAPISchemaAlternateType(QAPISchemaType): + meta = 'alternate' + + def __init__(self, name, info, doc, ifcond, features, variants): + super().__init__(name, info, doc, ifcond, features) + assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert variants.tag_member + variants.set_defined_in(name) + variants.tag_member.set_defined_in(self.name) + self.variants = variants def check(self, schema): - assert self.defined_in - self.type = schema.resolve_type(self._type_name, self.info, - self.describe) + super().check(schema) + self.variants.tag_member.check(schema) + # Not calling self.variants.check_clash(), because there's nothing + # to clash with + self.variants.check(schema, {}) + # Alternate branch names have no relation to the tag enum values; + # so we have to check for potential name collisions ourselves. + seen = {} + types_seen = {} + for v in self.variants.variants: + v.check_clash(self.info, seen) + qtype = v.type.alternate_qtype() + if not qtype: + raise QAPISemError( + self.info, + "%s cannot use %s" + % (v.describe(self.info), v.type.describe())) + conflicting = set([qtype]) + if qtype == 'QTYPE_QSTRING': + if isinstance(v.type, QAPISchemaEnumType): + for m in v.type.members: + if m.name in ['on', 'off']: + conflicting.add('QTYPE_QBOOL') + if re.match(r'[-+0-9.]', m.name): + # lazy, could be tightened + conflicting.add('QTYPE_QNUM') + else: + conflicting.add('QTYPE_QNUM') + conflicting.add('QTYPE_QBOOL') + for qt in conflicting: + if qt in types_seen: + raise QAPISemError( + self.info, + "%s can't be distinguished from '%s'" + % (v.describe(self.info), types_seen[qt])) + types_seen[qt] = v.name + + def connect_doc(self, doc=None): + super().connect_doc(doc) + doc = doc or self.doc + if doc: + for v in self.variants.variants: + doc.connect_member(v) + + def c_type(self): + return c_name(self.name) + pointer_suffix + + def json_type(self): + return 'value' + + def visit(self, visitor): + super().visit(visitor) + visitor.visit_alternate_type( + self.name, self.info, self.ifcond, self.features, self.variants) class QAPISchemaObjectTypeVariants:
@@ -613,6 +603,84 @@ class QAPISchemaObjectTypeVariants: v.type.check_clash(info, dict(seen)) +class QAPISchemaMember: + """ Represents object members, enum members and features """ + role = 'member' + + def __init__(self, name, info, ifcond=None): + assert isinstance(name, str) + self.name = name + self.info = info + self.ifcond = ifcond or [] + self.defined_in = None + + def set_defined_in(self, name): + assert not self.defined_in + self.defined_in = name + + def check_clash(self, info, seen): + cname = c_name(self.name) + if cname in seen: + raise QAPISemError( + info, + "%s collides with %s" + % (self.describe(info), seen[cname].describe(info))) + seen[cname] = self + + def describe(self, info): + role = self.role + defined_in = self.defined_in + assert defined_in + + if defined_in.startswith('q_obj_'): + # See QAPISchema._make_implicit_object_type() - reverse the + # mapping there to create a nice human-readable description + defined_in = defined_in[6:] + if defined_in.endswith('-arg'): + # Implicit type created for a command's dict 'data' + assert role == 'member' + role = 'parameter' + elif defined_in.endswith('-base'): + # Implicit type created for a flat union's dict 'base' + role = 'base ' + role + else: + # Implicit type created for a simple union's branch + assert defined_in.endswith('-wrapper') + # Unreachable and not implemented + assert False + elif defined_in.endswith('Kind'): + # See QAPISchema._make_implicit_enum_type() + # Implicit enum created for simple union's branches + assert role == 'value' + role = 'branch' + elif defined_in != info.defn_name: + return "%s '%s' of type '%s'" % (role, self.name, defined_in) + return "%s '%s'" % (role, self.name) + + +class QAPISchemaEnumMember(QAPISchemaMember): + role = 'value' + + +class QAPISchemaFeature(QAPISchemaMember): + role = 'feature' + + +class QAPISchemaObjectTypeMember(QAPISchemaMember): + def __init__(self, name, info, typ, optional, ifcond=None): + super().__init__(name, info, ifcond) + assert isinstance(typ, str) + assert isinstance(optional, bool) + self._type_name = typ + self.type = None + self.optional = optional + + def check(self, schema): + assert self.defined_in + self.type = schema.resolve_type(self._type_name, self.info, + self.describe) + + class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role = 'branch'
@@ -621,74 +689,6 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): False, ifcond) -class QAPISchemaAlternateType(QAPISchemaType): - meta = 'alternate' - - def __init__(self, name, info, doc, ifcond, features, variants): - super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaObjectTypeVariants) - assert variants.tag_member - variants.set_defined_in(name) - variants.tag_member.set_defined_in(self.name) - self.variants = variants - - def check(self, schema): - super().check(schema) - self.variants.tag_member.check(schema) - # Not calling self.variants.check_clash(), because there's nothing - # to clash with - self.variants.check(schema, {}) - # Alternate branch names have no relation to the tag enum values; - # so we have to check for potential name collisions ourselves. - seen = {} - types_seen = {} - for v in self.variants.variants: - v.check_clash(self.info, seen) - qtype = v.type.alternate_qtype() - if not qtype: - raise QAPISemError( - self.info, - "%s cannot use %s" - % (v.describe(self.info), v.type.describe())) - conflicting = set([qtype]) - if qtype == 'QTYPE_QSTRING': - if isinstance(v.type, QAPISchemaEnumType): - for m in v.type.members: - if m.name in ['on', 'off']: - conflicting.add('QTYPE_QBOOL') - if re.match(r'[-+0-9.]', m.name): - # lazy, could be tightened - conflicting.add('QTYPE_QNUM') - else: - conflicting.add('QTYPE_QNUM') - conflicting.add('QTYPE_QBOOL') - for qt in conflicting: - if qt in types_seen: - raise QAPISemError( - self.info, - "%s can't be distinguished from '%s'" - % (v.describe(self.info), types_seen[qt])) - types_seen[qt] = v.name - - def connect_doc(self, doc=None): - super().connect_doc(doc) - doc = doc or self.doc - if doc: - for v in self.variants.variants: - doc.connect_member(v) - - def c_type(self): - return c_name(self.name) + pointer_suffix - - def json_type(self): - return 'value' - - def visit(self, visitor): - super().visit(visitor) - visitor.visit_alternate_type( - self.name, self.info, self.ifcond, self.features, self.variants) - - class QAPISchemaCommand(QAPISchemaEntity): meta = 'command'
Signature · 1 line
2.21.1
PATCH v2 18/30 qapi/schema: Rename QAPISchemaObjectType{Variant, Variants}
In reply to Markus ArmbrusterQAPISchemaObjectTypeVariants represents both object type and alternate type variants. Rename to QAPISchemaVariants.
Rename QAPISchemaObjectTypeVariant the same way.
--- scripts/qapi/schema.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
scripts/qapi/schema.py +11 -11
@@ -338,7 +338,7 @@ class QAPISchemaObjectType(QAPISchemaType): assert isinstance(m, QAPISchemaObjectTypeMember) m.set_defined_in(name) if variants is not None: - assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert isinstance(variants, QAPISchemaVariants) variants.set_defined_in(name) self._base_name = base self.base = None
@@ -449,7 +449,7 @@ class QAPISchemaAlternateType(QAPISchemaType): def __init__(self, name, info, doc, ifcond, features, variants): super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert isinstance(variants, QAPISchemaVariants) assert variants.tag_member variants.set_defined_in(name) variants.tag_member.set_defined_in(self.name)
@@ -512,7 +512,7 @@ class QAPISchemaAlternateType(QAPISchemaType): self.name, self.info, self.ifcond, self.features, self.variants) -class QAPISchemaObjectTypeVariants: +class QAPISchemaVariants: def __init__(self, tag_name, info, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name.
@@ -522,7 +522,7 @@ class QAPISchemaObjectTypeVariants: assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember)) for v in variants: - assert isinstance(v, QAPISchemaObjectTypeVariant) + assert isinstance(v, QAPISchemaVariant) self._tag_name = tag_name self.info = info self.tag_member = tag_member
@@ -572,8 +572,8 @@ class QAPISchemaObjectTypeVariants: cases = {v.name for v in self.variants} for m in self.tag_member.type.members: if m.name not in cases: - v = QAPISchemaObjectTypeVariant(m.name, self.info, - 'q_empty', m.ifcond) + v = QAPISchemaVariant(m.name, self.info, + 'q_empty', m.ifcond) v.set_defined_in(self.tag_member.defined_in) self.variants.append(v) if not self.variants:
@@ -681,7 +681,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): self.describe) -class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): +class QAPISchemaVariant(QAPISchemaObjectTypeMember): role = 'branch' def __init__(self, name, info, typ, ifcond=None):
@@ -988,7 +988,7 @@ class QAPISchema: None)) def _make_variant(self, case, typ, ifcond, info): - return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) + return QAPISchemaVariant(case, info, typ, ifcond) def _make_simple_variant(self, case, typ, ifcond, info): if isinstance(typ, list):
@@ -997,7 +997,7 @@ class QAPISchema: typ = self._make_implicit_object_type( typ, info, self.lookup_type(typ), 'wrapper', [self._make_member('data', typ, None, info)]) - return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) + return QAPISchemaVariant(case, info, typ, ifcond) def _def_union_type(self, expr, info, doc): name = expr['union']
@@ -1027,7 +1027,7 @@ class QAPISchema: self._def_entity( QAPISchemaObjectType(name, info, doc, ifcond, features, base, members, - QAPISchemaObjectTypeVariants( + QAPISchemaVariants( tag_name, info, tag_member, variants))) def _def_alternate_type(self, expr, info, doc):
@@ -1041,7 +1041,7 @@ class QAPISchema: tag_member = QAPISchemaObjectTypeMember('type', info, 'QType', False) self._def_entity( QAPISchemaAlternateType(name, info, doc, ifcond, features, - QAPISchemaObjectTypeVariants( + QAPISchemaVariants( None, info, tag_member, variants))) def _def_command(self, expr, info, doc):
Signature · 1 line
2.21.1
PATCH v2 19/30 qapi/schema: Call QAPIDoc.connect_member() in just one place
In reply to Markus ArmbrusterThe .connect_doc() of classes that have QAPISchemaMember connect them to their documentation. Change them to delegate the actual work to new QAPISchemaMember.connect_doc(). Matches the .connect_doc() that already exist.
--- scripts/qapi/schema.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
scripts/qapi/schema.py +12 -11
@@ -252,9 +252,8 @@ class QAPISchemaEnumType(QAPISchemaType): def connect_doc(self, doc=None): super().connect_doc(doc) doc = doc or self.doc - if doc: - for m in self.members: - doc.connect_member(m) + for m in self.members: + m.connect_doc(doc) def is_implicit(self): # See QAPISchema._make_implicit_enum_type() and ._def_predefineds()
@@ -396,11 +395,10 @@ class QAPISchemaObjectType(QAPISchemaType): def connect_doc(self, doc=None): super().connect_doc(doc) doc = doc or self.doc - if doc: - if self.base and self.base.is_implicit(): - self.base.connect_doc(doc) - for m in self.local_members: - doc.connect_member(m) + if self.base and self.base.is_implicit(): + self.base.connect_doc(doc) + for m in self.local_members: + m.connect_doc(doc) @property def ifcond(self):
@@ -496,9 +494,8 @@ class QAPISchemaAlternateType(QAPISchemaType): def connect_doc(self, doc=None): super().connect_doc(doc) doc = doc or self.doc - if doc: - for v in self.variants.variants: - doc.connect_member(v) + for v in self.variants.variants: + v.connect_doc(doc) def c_type(self): return c_name(self.name) + pointer_suffix
@@ -627,6 +624,10 @@ class QAPISchemaMember: % (self.describe(info), seen[cname].describe(info))) seen[cname] = self + def connect_doc(self, doc): + if doc: + doc.connect_member(self) + def describe(self, info): role = self.role defined_in = self.defined_in
Signature · 1 line
2.21.1
PATCH v2 20/30 qapi: Add feature flags to struct members
In reply to Markus Armbruster--- docs/devel/qapi-code-gen.txt | 4 +++- tests/qapi-schema/doc-good.texi | 2 ++ qapi/introspect.json | 6 +++++- scripts/qapi/expr.py | 3 ++- scripts/qapi/introspect.py | 2 +- scripts/qapi/schema.py | 25 ++++++++++++++++++++----- tests/qapi-schema/doc-good.json | 5 ++++- tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 1 + tests/qapi-schema/test-qapi.py | 7 ++++--- 11 files changed, 46 insertions(+), 14 deletions(-)
docs/devel/qapi-code-gen.txt +3 -1
@@ -234,7 +234,9 @@ Syntax: '*features': FEATURES } MEMBERS = { MEMBER, ... } MEMBER = STRING : TYPE-REF - | STRING : { 'type': TYPE-REF, '*if': COND } + | STRING : { 'type': TYPE-REF, + '*if': COND, + '*features': FEATURES } Member 'struct' names the struct type.
tests/qapi-schema/doc-good.texi +2 -0
@@ -132,6 +132,8 @@ Not documented @table @asis @item @code{variant1-feat} a feature +@item @code{member-feat} +a member feature @end table @end deftp
qapi/introspect.json +5 -1
@@ -206,11 +206,15 @@ # Future extension: if present and non-null, the parameter # is optional, and defaults to this value. # +# @features: names of features associated with the member, in no +# particular order. (since 5.0) +# # Since: 2.5 ## { 'struct': 'SchemaInfoObjectMember', - 'data': { 'name': 'str', 'type': 'str', '*default': 'any' } } + 'data': { 'name': 'str', 'type': 'str', '*default': 'any', # @default's type must be null or match @type + '*features': [ 'str' ] } } ## # @SchemaInfoObjectVariant:
scripts/qapi/expr.py +2 -1
@@ -167,8 +167,9 @@ def check_type(value, info, source, allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "%s uses reserved name" % key_source) - check_keys(arg, info, key_source, ['type'], ['if']) + check_keys(arg, info, key_source, ['type'], ['if', 'features']) check_if(arg, info, key_source) + check_features(arg.get('features'), info) check_type(arg['type'], info, key_source, allow_array=True)
scripts/qapi/introspect.py +1 -1
@@ -173,7 +173,7 @@ const QLitObject %(c_name)s = %(c_string)s; obj = {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] = None - return _make_tree(obj, member.ifcond, None) + return _make_tree(obj, member.ifcond, member.features) def _gen_variants(self, tag_name, variants): return {'tag': tag_name,
scripts/qapi/schema.py +20 -5
@@ -668,18 +668,31 @@ class QAPISchemaFeature(QAPISchemaMember): class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=None): + def __init__(self, name, info, typ, optional, ifcond=None, features=None): super().__init__(name, info, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) + for f in features or []: + assert isinstance(f, QAPISchemaFeature) + f.set_defined_in(name) self._type_name = typ self.type = None self.optional = optional + self.features = features or [] def check(self, schema): assert self.defined_in self.type = schema.resolve_type(self._type_name, self.info, self.describe) + seen = {} + for f in self.features: + f.check_clash(self.info, seen) + + def connect_doc(self, doc): + super().connect_doc(doc) + if doc: + for f in self.features: + doc.connect_feature(f) class QAPISchemaVariant(QAPISchemaObjectTypeMember):
@@ -963,7 +976,7 @@ class QAPISchema: name, info, doc, ifcond, features, self._make_enum_members(data, info), prefix)) - def _make_member(self, name, typ, ifcond, info): + def _make_member(self, name, typ, ifcond, features, info): optional = False if name.startswith('*'): name = name[1:]
@@ -971,10 +984,12 @@ class QAPISchema: if isinstance(typ, list): assert len(typ) == 1 typ = self._make_array_type(typ[0], info) - return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcond) + return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcond, + self._make_features(features, info)) def _make_members(self, data, info): - return [self._make_member(key, value['type'], value.get('if'), info) + return [self._make_member(key, value['type'], value.get('if'), + value.get('features'), info) for (key, value) in data.items()] def _def_struct_type(self, expr, info, doc):
@@ -997,7 +1012,7 @@ class QAPISchema: typ = self._make_array_type(typ[0], info) typ = self._make_implicit_object_type( typ, info, self.lookup_type(typ), - 'wrapper', [self._make_member('data', typ, None, info)]) + 'wrapper', [self._make_member('data', typ, None, None, info)]) return QAPISchemaVariant(case, info, typ, ifcond) def _def_union_type(self, expr, info, doc):
tests/qapi-schema/doc-good.json +4 -1
@@ -78,10 +78,13 @@ # # Features: # @variant1-feat: a feature +# @member-feat: a member feature ## { 'struct': 'Variant1', 'features': [ 'variant1-feat' ], - 'data': { 'var1': { 'type': 'str', 'if': 'defined(IFSTR)' } } } + 'data': { 'var1': { 'type': 'str', + 'features': [ 'member-feat' ], + 'if': 'defined(IFSTR)' } } } ## # @Variant2:
tests/qapi-schema/doc-good.out +3 -0
@@ -21,6 +21,7 @@ object Base object Variant1 member var1: str optional=False if ['defined(IFSTR)'] + feature member-feat feature variant1-feat object Variant2 object Object
@@ -135,6 +136,8 @@ Another paragraph (but no @var: line) feature=variant1-feat a feature + feature=member-feat +a member feature doc symbol=Variant2 body=
tests/qapi-schema/qapi-schema-test.json +1 -1
@@ -258,7 +258,7 @@ 'data': { 'foo': 'int' }, 'features': [] } { 'struct': 'FeatureStruct1', - 'data': { 'foo': 'int' }, + 'data': { 'foo': { 'type': 'int', 'features': [ 'member-feature1' ] } }, 'features': [ 'feature1' ] } { 'struct': 'FeatureStruct2', 'data': { 'foo': 'int' },
tests/qapi-schema/qapi-schema-test.out +1 -0
@@ -359,6 +359,7 @@ object FeatureStruct0 member foo: int optional=False object FeatureStruct1 member foo: int optional=False + feature member-feature1 feature feature1 object FeatureStruct2 member foo: int optional=False
tests/qapi-schema/test-qapi.py +4 -3
@@ -55,6 +55,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print(' member %s: %s optional=%s' % (m.name, m.type.name, m.optional)) self._print_if(m.ifcond, 8) + self._print_features(m.features, indent=8) self._print_variants(variants) self._print_if(ifcond) self._print_features(features)
@@ -96,11 +97,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print('%sif %s' % (' ' * indent, ifcond)) @classmethod - def _print_features(cls, features): + def _print_features(cls, features, indent=4): if features: for f in features: - print(' feature %s' % f.name) - cls._print_if(f.ifcond, 8) + print('%sfeature %s' % (' ' * indent, f.name)) + cls._print_if(f.ifcond, indent + 4) def test_frontend(fname):
Signature · 1 line
2.21.1
PATCH v2 21/30 qapi: Inline do_qmp_dispatch() into qmp_dispatch()
In reply to Markus ArmbrusterBoth functions check @request is a QDict, and both have code for QCO_NO_SUCCESS_RESP. This wasn't the case back when they were created. It's a sign of muddled responsibilities. Inline. The next commits will clean up some more.
--- qapi/qmp-dispatch.c | 90 +++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 49 deletions(-)
qapi/qmp-dispatch.c +41 -49
@@ -75,19 +75,42 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob,return dict; } -static QObject *do_qmp_dispatch (QmpCommandList *cmds,QObject *request, -bool allow_oob,Error **errp) +QDict *qmp_error_response (Error *err) { -Error *local_err =NULL ; +QDict *rsp; + + rsp =qdict_from_jsonf_nofail ("{ 'error': { 'class': %s, 'desc': %s } }" , +QapiErrorClass_str (error_get_class (err)), +error_get_pretty (err)); +error_free (err); +return rsp; +} + +/* +* Does @qdict look like a command to be run out-of-band? +*/ +bool qmp_is_oob (const QDict *dict) +{ +return qdict_haskey (dict,"exec-oob" ) + && !qdict_haskey (dict,"execute" ); +} + +QDict *qmp_dispatch (QmpCommandList *cmds,QObject *request, +bool allow_oob) +{ +Error *err =NULL ;bool oob;const char *command; -QDict *args, *dict; +QDict *args;QmpCommand *cmd; +QDict *dict =qobject_to (QDict, request); +QObject *id = dict ?qdict_get (dict,"id" ) :NULL ;QObject *ret =NULL ; +QDict *rsp; - dict =qmp_dispatch_check_obj (request, allow_oob, errp); + dict =qmp_dispatch_check_obj (request, allow_oob, &err);if (!dict) { -return NULL ; + goto out; } command =qdict_get_try_str (dict,"execute" );
@@ -99,27 +122,27 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request, } cmd =qmp_find_command (cmds, command);if (cmd ==NULL ) { -error_set (errp,ERROR_CLASS_COMMAND_NOT_FOUND , +error_set (&err,ERROR_CLASS_COMMAND_NOT_FOUND ,"The command %s has not been found" , command); -return NULL ; + goto out; }if (!cmd->enabled) { -error_set (errp,ERROR_CLASS_COMMAND_NOT_FOUND , +error_set (&err,ERROR_CLASS_COMMAND_NOT_FOUND ,"The command %s has been disabled for this instance" , command); -return NULL ; + goto out; }if (oob && !(cmd->options &QCO_ALLOW_OOB )) { -error_setg (errp,"The command %s does not support OOB" , +error_setg (&err,"The command %s does not support OOB" , command); -return NULL ; + goto out; }if (runstate_check (RUN_STATE_PRECONFIG ) && !(cmd->options &QCO_ALLOW_PRECONFIG )) { -error_setg (errp,"The command '%s' isn't permitted in '%s' state" , +error_setg (&err,"The command '%s' isn't permitted in '%s' state" , cmd->name,RunState_str (RUN_STATE_PRECONFIG )); -return NULL ; + goto out; }if (!qdict_haskey (dict,"arguments" )) {
@@ -129,9 +152,9 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,qobject_ref (args); } - cmd->fn (args, &ret, &local_err); -if (local_err) { -error_propagate (errp, local_err); + cmd->fn (args, &ret, &err); +if (err) { + ; }else if (cmd->options &QCO_NO_SUCCESS_RESP ) {g_assert (!ret); }else if (!ret) {
@@ -141,38 +164,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,qobject_unref (args); -return ret; -} - -QDict *qmp_error_response (Error *err) -{ -QDict *rsp; - - rsp =qdict_from_jsonf_nofail ("{ 'error': { 'class': %s, 'desc': %s } }" , -QapiErrorClass_str (error_get_class (err)), -error_get_pretty (err)); -error_free (err); -return rsp; -} - -/* -* Does @qdict look like a command to be run out-of-band? -*/ -bool qmp_is_oob (const QDict *dict) -{ -return qdict_haskey (dict,"exec-oob" ) - && !qdict_haskey (dict,"execute" ); -} - -QDict *qmp_dispatch (QmpCommandList *cmds,QObject *request, -bool allow_oob) -{ -Error *err =NULL ; -QDict *dict =qobject_to (QDict, request); -QObject *ret, *id = dict ?qdict_get (dict,"id" ) :NULL ; -QDict *rsp; - - ret =do_qmp_dispatch (cmds, request, allow_oob, &err); +out:if (err) { rsp =qmp_error_response (err); }else if (ret) {
Signature · 1 line
2.21.1
PATCH v2 22/30 qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP
In reply to Markus Armbruster--- qapi/qmp-dispatch.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
qapi/qmp-dispatch.c +13 -12
@@ -106,7 +106,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,QDict *dict =qobject_to (QDict, request);QObject *id = dict ?qdict_get (dict,"id" ) :NULL ;QObject *ret =NULL ; -QDict *rsp; +QDict *rsp =NULL ; dict =qmp_dispatch_check_obj (request, allow_oob, &err);if (!dict) {
@@ -151,31 +151,32 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, args =qdict_get_qdict (dict,"arguments" );qobject_ref (args); } - cmd->fn (args, &ret, &err); +qobject_unref (args);if (err) { - ; - }else if (cmd->options &QCO_NO_SUCCESS_RESP ) { + goto out; + } + +if (cmd->options &QCO_NO_SUCCESS_RESP ) {g_assert (!ret); +return NULL ; }else if (!ret) {/* TODO turn into assertion */ ret =QOBJECT (qdict_new ()); } -qobject_unref (args); + rsp =qdict_new (); +qdict_put_obj (rsp,"return" , ret); out:if (err) { +assert (!rsp); rsp =qmp_error_response (err); - }else if (ret) { - rsp =qdict_new (); -qdict_put_obj (rsp,"return" , ret); - }else { -/* Can only happen for commands with QCO_NO_SUCCESS_RESP */ - rsp =NULL ; } -if (rsp && id) { +assert (rsp); + +if (id) {qdict_put_obj (rsp,"id" ,qobject_ref (id)); }
Signature · 1 line
2.21.1
PATCH v2 23/30 qapi: Simplify how qmp_dispatch() gets the request ID
In reply to Markus ArmbrusterWe convert the request object to a QDict twice: first in qmp_dispatch() to get the request ID, and then again in qmp_dispatch_check_obj(), which converts to QDict, then checks and returns it. We can't get the request ID from the latter, because it's null when the qdict flunks the checks.
Move getting the request ID into qmp_dispatch_check_obj().
--- qapi/qmp-dispatch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
qapi/qmp-dispatch.c +7 -4
@@ -20,7 +20,7 @@#include "qapi/qmp/qbool.h" static QDict *qmp_dispatch_check_obj (const QObject *request,bool allow_oob, -Error **errp) +QObject **id,Error **errp) {const char *exec_key =NULL ;const QDictEntry *ent;
@@ -30,10 +30,13 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob, dict =qobject_to (QDict, request);if (!dict) { + *id =NULL ;error_setg (errp,"QMP input must be a JSON object" );return NULL ; } + *id =qdict_get (dict,"id" ); +for (ent =qdict_first (dict); ent; ent =qdict_next (dict, ent)) { arg_name =qdict_entry_key (ent);
@@ -103,12 +106,12 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,const char *command;QDict *args;QmpCommand *cmd; -QDict *dict =qobject_to (QDict, request); -QObject *id = dict ?qdict_get (dict,"id" ) :NULL ; +QDict *dict; +QObject *id;QObject *ret =NULL ;QDict *rsp =NULL ; - dict =qmp_dispatch_check_obj (request, allow_oob, &err); + dict =qmp_dispatch_check_obj (request, allow_oob, &id, &err);if (!dict) { goto out; }
Signature · 1 line
2.21.1
PATCH v2 24/30 qapi: Replace qmp_dispatch()'s TODO comment by an explanation
In reply to Markus Armbruster--- qapi/qmp-dispatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qapi/qmp-dispatch.c +5 -1
@@ -164,7 +164,11 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,g_assert (!ret);return NULL ; }else if (!ret) { -/* TODO turn into assertion */ +/* +* When the command's schema has no 'returns', cmd->fn() +* leaves @ret null. The QMP spec calls for an the empty +* object then; supply it. +*/ ret =QOBJECT (qdict_new ()); }
Signature · 1 line
2.21.1
PATCH v2 25/30 qapi: New special feature flag "deprecated"
In reply to Markus ArmbrusterUnlike regular feature flags, the new special feature flag "deprecated" is recognized by the QAPI generator. For now, it's only permitted with commands, events, and struct members. It will be put to use shortly.
--- docs/devel/qapi-code-gen.txt | 6 ++++++ scripts/qapi/schema.py | 6 ++++++ tests/Makefile.include | 1 + tests/qapi-schema/features-deprecated-type.err | 2 ++ tests/qapi-schema/features-deprecated-type.json | 3 +++ tests/qapi-schema/features-deprecated-type.out | 0 tests/qapi-schema/qapi-schema-test.json | 6 +++--- tests/qapi-schema/qapi-schema-test.out | 6 +++--- 8 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/qapi-schema/features-deprecated-type.err create mode 100644 tests/qapi-schema/features-deprecated-type.json create mode 100644 tests/qapi-schema/features-deprecated-type.out
docs/devel/qapi-code-gen.txt +6 -0
@@ -683,6 +683,12 @@ Intended use is to have each feature string signal that this build of QEMU shows a certain behaviour. +==== Special features ==== + +Feature "deprecated" makes a command, event, or struct member as +deprecated. It is not supported elsewhere so far. + + === Naming rules and reserved names === All names must begin with a letter, and contain only ASCII letters,
scripts/qapi/schema.py +6 -0
@@ -193,6 +193,12 @@ class QAPISchemaType(QAPISchemaEntity): return None return self.name + def check(self, schema): + QAPISchemaEntity.check(self, schema) + if 'deprecated' in [f.name for f in self.features]: + raise QAPISemError( + self.info, "feature 'deprecated' is not supported for types") + def describe(self): assert self.meta return "%s type '%s'" % (self.meta, self.name)
tests/Makefile.include +1 -0
@@ -242,6 +242,7 @@ 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-deprecated-type.json qapi-schema += features-duplicate-name.json qapi-schema += features-if-invalid.json qapi-schema += features-missing-name.json
tests/qapi-schema/features-deprecated-type.err new file +2 -0
@@ -0,0 +1,2 @@ +features-deprecated-type.json: In struct 'S': +features-deprecated-type.json:2: feature 'deprecated' is not supported for types
tests/qapi-schema/features-deprecated-type.json new file +3 -0
@@ -0,0 +1,3 @@ +# Feature 'deprecated' is not supported for types +{ 'struct': 'S', 'data': {}, + 'features': [ 'deprecated' ] }
tests/qapi-schema/features-deprecated-type.out new file +0 -0
tests/qapi-schema/qapi-schema-test.json +3 -3
@@ -258,7 +258,7 @@ 'data': { 'foo': 'int' }, 'features': [] } { 'struct': 'FeatureStruct1', - 'data': { 'foo': { 'type': 'int', 'features': [ 'member-feature1' ] } }, + 'data': { 'foo': { 'type': 'int', 'features': [ 'deprecated' ] } }, 'features': [ 'feature1' ] } { 'struct': 'FeatureStruct2', 'data': { 'foo': 'int' },
@@ -308,7 +308,7 @@ 'features': [] } { 'command': 'test-command-features1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] } { 'command': 'test-command-features3', 'features': [ 'feature1', 'feature2' ] }
@@ -322,4 +322,4 @@ 'defined(TEST_IF_COND_2)'] } ] } { 'event': 'TEST-EVENT-FEATURES1', - 'features': [ 'feature1' ] } + 'features': [ 'deprecated' ] }
tests/qapi-schema/qapi-schema-test.out +3 -3
@@ -359,7 +359,7 @@ object FeatureStruct0 member foo: int optional=False object FeatureStruct1 member foo: int optional=False - feature member-feature1 + feature deprecated feature feature1 object FeatureStruct2 member foo: int optional=False
@@ -419,7 +419,7 @@ command test-features0 q_obj_test-features0-arg -> None gen=True success_response=True boxed=False oob=False preconfig=False command test-command-features1 None -> None gen=True success_response=True boxed=False oob=False preconfig=False - feature feature1 + feature deprecated command test-command-features3 None -> None gen=True success_response=True boxed=False oob=False preconfig=False feature feature1
@@ -440,7 +440,7 @@ command test-command-cond-features3 None -> None if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] event TEST-EVENT-FEATURES1 None boxed=False - feature feature1 + feature deprecated module include/sub-module.json include sub-sub-module.json object SecondArrayRef
Signature · 1 line
2.21.1
PATCH v2 26/30 qapi: Mark deprecated QMP parts with feature 'deprecated'
In reply to Markus ArmbrusterAdd feature 'deprecated' to the deprecated QMP commands, so their deprecation becomes visible in output of query-qmp-schema. Looks like this:
{"name": "query-cpus",
"ret-type": "[164]",
"meta-type": "command",
"arg-type": "0",---> "features": ["deprecated"]}
Management applications could conceivably use this for static checking.
The deprecated commands are change, cpu-add, migrate-set-cache-size, migrate_set_downtime, migrate_set_speed, query-cpus, query-events, query-migrate-cache-size.
The deprecated command arguments are block-commit arguments @base and @top, and block_set_io_throttle, blockdev-change-medium, blockdev-close-tray, blockdev-open-tray, eject argument @device.
The deprecated command results are query-cpus-fast result @arch, query-block result @dirty-bitmaps, query-named-block-nodes result @encryption_key_missing and result @dirty-bitmaps's member @status. Same for query-block result @inserted, which mirrors query-named-block-nodes.
--- qapi/block-core.json | 69 +++++++++++++++++++++++++++++++++----------- qapi/block.json | 9 ++++-- qapi/control.json | 11 ++++--- qapi/machine.json | 34 ++++++++++++---------- qapi/migration.json | 36 +++++++++++++++-------- qapi/misc.json | 13 +++++---- 6 files changed, 115 insertions(+), 57 deletions(-)
qapi/block-core.json +52 -17
@@ -297,7 +297,7 @@ # # @encrypted: true if the backing device is encrypted # -# @encryption_key_missing: Deprecated; always false +# @encryption_key_missing: always false # # @detect_zeroes: detect and optimize zero writes (Since 2.1) #
@@ -363,13 +363,19 @@ # @dirty-bitmaps: dirty bitmaps information (only present if node # has one or more dirty bitmaps) (Since 4.2) # +# Features: +# @deprecated: Member @encryption_key_missing is deprecated. It is +# always false. +# # Since: 0.14.0 # ## { 'struct': 'BlockDeviceInfo', 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', - 'encrypted': 'bool', 'encryption_key_missing': 'bool', + 'encrypted': 'bool', + 'encryption_key_missing': { 'type': 'bool', + 'features': [ 'deprecated' ] }, 'detect_zeroes': 'BlockdevDetectZeroesOptions', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
@@ -475,7 +481,7 @@ # # @granularity: granularity of the dirty bitmap in bytes (since 1.4) # -# @status: Deprecated in favor of @recording and @locked. (since 2.4) +# @status: current status of the dirty bitmap (since 2.4) # # @recording: true if the bitmap is recording new writes from the guest. # Replaces `active` and `disabled` statuses. (since 4.0)
@@ -492,11 +498,17 @@ # @busy to be false. This bitmap cannot be used. To remove # it, use @block-dirty-bitmap-remove. (Since 4.0) # +# Features: +# @deprecated: Member @status is deprecated. Use @recording and +# @locked instead. +# # Since: 1.3 ## { 'struct': 'BlockDirtyInfo', 'data': {'*name': 'str', 'count': 'int', 'granularity': 'uint32', - 'recording': 'bool', 'busy': 'bool', 'status': 'DirtyBitmapStatus', + 'recording': 'bool', 'busy': 'bool', + 'status': { 'type': 'DirtyBitmapStatus', + 'features': [ 'deprecated' ] }, 'persistent': 'bool', '*inconsistent': 'bool' } } ##
@@ -659,7 +671,6 @@ # # @dirty-bitmaps: dirty bitmaps information (only present if the # driver has one or more dirty bitmaps) (Since 2.0) -# Deprecated in 4.2; see BlockDeviceInfo instead. # # @io-status: @BlockDeviceIoStatus. Only present if the device # supports it and the VM is configured to stop on errors
@@ -669,13 +680,18 @@ # @inserted: @BlockDeviceInfo describing the device if media is # present # +# Features: +# @deprecated: Member @dirty-bitmaps is deprecated. Use @inserted +# member @dirty-bitmaps instead. +# # Since: 0.14.0 ## { 'struct': 'BlockInfo', 'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool', 'locked': 'bool', '*inserted': 'BlockDeviceInfo', '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus', - '*dirty-bitmaps': ['BlockDirtyInfo'] } } + '*dirty-bitmaps': { 'type': ['BlockDirtyInfo'], + 'features': [ 'deprecated' ] } } } ## # @BlockMeasureInfo:
@@ -1616,7 +1632,7 @@ # @base: Same as @base-node, except that it is a file name rather than a node # name. This must be the exact filename string that was used to open the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @top-node: The node name of the backing image within the image chain # which contains the topmost data to be committed down. If
@@ -1625,7 +1641,7 @@ # @top: Same as @top-node, except that it is a file name rather than a node # name. This must be the exact filename string that was used to open the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @backing-file: The backing file string to write into the overlay # image of 'top'. If 'top' is the active layer,
@@ -1679,6 +1695,10 @@ # list without user intervention. # Defaults to true. (Since 3.1) # +# Features: +# @deprecated: Members @base and @top are deprecated. Use @base-node +# and @top-node instead. +# # Returns: - Nothing on success # - If @device does not exist, DeviceNotFound # - Any other error returns a GenericError.
@@ -1695,7 +1715,9 @@ ## { 'command': 'block-commit', 'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str', - '*base': 'str', '*top-node': 'str', '*top': 'str', + '*base': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*top-node': 'str', + '*top': { 'type': 'str', 'features': [ 'deprecated' ] }, '*backing-file': 'str', '*speed': 'int', '*on-error': 'BlockdevOnError', '*filter-node-name': 'str',
@@ -2433,7 +2455,7 @@ # # A set of parameters describing block throttling. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) #
@@ -2501,10 +2523,14 @@ # # @group: throttle group name (Since 2.4) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int',
@@ -4776,7 +4802,7 @@ # to it # - if the guest device does not have an actual tray # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) #
@@ -4785,6 +4811,9 @@ # immediately); if true, the tray will be opened regardless of whether # it is locked # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example:
@@ -4803,7 +4832,7 @@ # ## { 'command': 'blockdev-open-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } }
@@ -4816,10 +4845,13 @@ # # If the tray was already closed before, this will be a no-op. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example:
@@ -4838,7 +4870,7 @@ # ## { 'command': 'blockdev-close-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str' } } ##
@@ -4945,7 +4977,7 @@ # combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-medium # and blockdev-close-tray). # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device # (since: 2.8)
@@ -4958,6 +4990,9 @@ # @read-only-mode: change the read-only mode of the device; defaults # to 'retain' # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Examples:
@@ -4992,7 +5027,7 @@ # ## { 'command': 'blockdev-change-medium', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', 'filename': 'str', '*format': 'str',
qapi/block.json +6 -3
@@ -185,15 +185,18 @@ ## # @eject: # -# Ejects a device from a removable drive. +# Ejects the medium from a removable block device. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # # @force: If true, eject regardless of whether the drive is locked. # If not specified, the default value is false. # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Returns: - Nothing on success # - If @device is not a valid block device, DeviceNotFound # Notes: Ejecting a device with no media results in success
@@ -206,7 +209,7 @@ # <- { "return": {} } ## { 'command': 'eject', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } }
qapi/control.json +7 -4
@@ -174,13 +174,15 @@ # # Return information on QMP events. # +# Features: +# @deprecated: This command is deprecated, because its output doesn't +# reflect compile-time configuration. Use 'query-qmp-schema' +# instead. +# # Returns: A list of @EventInfo. # # Since: 1.2.0 # -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# # Example: # # -> { "execute": "query-events" }
@@ -198,7 +200,8 @@ # Note: This example has been shortened as the real response is too long. # ## -{ 'command': 'query-events', 'returns': ['EventInfo'] } +{ 'command': 'query-events', 'returns': ['EventInfo'], + 'features': [ 'deprecated' ] } ## # @quit:
qapi/machine.json +19 -15
@@ -184,8 +184,11 @@ # This command causes vCPU threads to exit to userspace, which causes # a small interruption to guest CPU execution. This will have a negative # impact on realtime guests and other latency sensitive guest workloads. -# It is recommended to use @query-cpus-fast instead of this command to -# avoid the vCPU interruption. +# +# Features: +# @deprecated: This command is deprecated, because it interferes with +# the guest. Use 'query-cpus-fast' instead to avoid the vCPU +# interruption. # # Returns: a list of @CpuInfo for each virtual CPU #
@@ -216,12 +219,9 @@ # ] # } # -# Notes: This interface is deprecated (since 2.12.0), and it is strongly -# recommended that you avoid using it. Use @query-cpus-fast to -# obtain information about virtual CPUs. -# ## -{ 'command': 'query-cpus', 'returns': ['CpuInfo'] } +{ 'command': 'query-cpus', 'returns': ['CpuInfo'], + 'features': [ 'deprecated' ] } ## # @CpuInfoFast:
@@ -237,12 +237,14 @@ # @props: properties describing to which node/socket/core/thread # virtual CPU belongs to, provided if supported by board # -# @arch: base architecture of the cpu; deprecated since 3.0.0 in favor -# of @target +# @arch: base architecture of the cpu # # @target: the QEMU system emulation target, which determines which # additional fields will be listed (since 3.0) # +# Features: +# @deprecated: Member @arch is deprecated. Use @target instead. +# # Since: 2.12 # ##
@@ -251,7 +253,8 @@ 'qom-path' : 'str', 'thread-id' : 'int', '*props' : 'CpuInstanceProperties', - 'arch' : 'CpuInfoArch', + 'arch' : { 'type': 'CpuInfoArch', + 'features': [ 'deprecated' ] }, 'target' : 'SysEmuTarget' }, 'discriminator' : 'target', 'data' : { 's390x' : 'CpuInfoS390' } }
@@ -307,21 +310,22 @@ # # @id: ID of CPU to be created, valid values [0..max_cpus) # +# Features: +# @deprecated: This command is deprecated. Use `device_add` instead. +# See the `query-hotpluggable-cpus` command for details. +# # Returns: Nothing on success # # Since: 1.5 # -# Note: This command is deprecated. The `device_add` command should be -# used instead. See the `query-hotpluggable-cpus` command for -# details. -# # Example: # # -> { "execute": "cpu-add", "arguments": { "id": 2 } } # <- { "return": {} } # ## -{ 'command': 'cpu-add', 'data': {'id': 'int'} } +{ 'command': 'cpu-add', 'data': {'id': 'int'}, + 'features': [ 'deprecated' ] } ## # @MachineInfo:
qapi/migration.json +24 -12
@@ -1196,9 +1196,11 @@ # # @value: maximum downtime in seconds # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 #
@@ -1208,7 +1210,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } +{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'}, + 'features': [ 'deprecated' ] } ## # @migrate_set_speed:
@@ -1217,9 +1220,11 @@ # # @value: maximum speed in bytes per second. # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 #
@@ -1229,7 +1234,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_speed', 'data': {'value': 'int'} } +{ 'command': 'migrate_set_speed', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } ## # @migrate-set-cache-size:
@@ -1238,13 +1244,15 @@ # # @value: cache size in bytes # +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. +# # The size will be rounded down to the nearest power of 2. # The cache size can be modified before and during ongoing migration # # Returns: nothing on success # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' -# # Since: 1.2 # # Example:
@@ -1254,17 +1262,20 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} } +{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } ## # @query-migrate-cache-size: # # Query migration XBZRLE cache size # +# Features: +# @deprecated: This command is deprecated. Use +# 'query-migrate-parameters' instead. +# # Returns: XBZRLE cache size in bytes # -# Notes: This command is deprecated in favor of 'query-migrate-parameters' -# # Since: 1.2 # # Example:
@@ -1273,7 +1284,8 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int' } +{ 'command': 'query-migrate-cache-size', 'returns': 'int', + 'features': [ 'deprecated' ] } ## # @migrate:
qapi/misc.json +7 -6
@@ -872,14 +872,14 @@ # If @device is 'vnc' and @target is 'password', this is the new VNC # password to set. See change-vnc-password for additional notes. # +# Features: +# @deprecated: This command is deprecated. For changing block +# devices, use 'blockdev-change-medium' instead; for changing VNC +# parameters, use 'change-vnc-password' instead. +# # Returns: - Nothing on success. # - If @device is not a valid block device, DeviceNotFound # -# Notes: This interface is deprecated, and it is strongly recommended that you -# avoid using it. For changing block devices, use -# blockdev-change-medium; for changing VNC parameters, use -# change-vnc-password. -# # Since: 0.14.0 # # Example:
@@ -900,7 +900,8 @@ # ## { 'command': 'change', - 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'}, + 'features': [ 'deprecated' ] } ## # @xen-set-global-dirty-log:
Signature · 1 line
2.21.1
PATCH v2 27/30 qemu-options: New -compat to set policy for deprecated interfaces
In reply to Markus ArmbrusterPolicy is separate for input and output.
Input policy can be "accept" (accept silently), or "reject" (reject the request with an error).
Output policy can be "accept" (pass on unchanged), or "hide" (filter out the deprecated parts).
Default is "accept". Policies other than "accept" are implemented later in this series.
For now, -compat covers only syntactic aspects of QMP, i.e. stuff tagged with feature 'deprecated'. We may want to extend it to cover semantic aspects, CLI, and experimental features.
The option is experimental.
--- qapi/compat.json | 51 ++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + include/qapi/compat-policy.h | 20 ++++++++++++++ qapi/qmp-dispatch.c | 3 +++ softmmu/vl.c | 17 ++++++++++++ qapi/Makefile.objs | 8 +++--- qemu-options.hx | 21 +++++++++++++++ 7 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 qapi/compat.json create mode 100644 include/qapi/compat-policy.h
qapi/compat.json new file +51 -0
@@ -0,0 +1,51 @@ +# -*- Mode: Python -*- + +## +# = Compatibility policy +## + +## +# @CompatPolicyInput: +# +# Policy for handling "funny" input. +# +# @accept: Accept silently +# @reject: Reject with an error +# +# Since: 5.0 +## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept', 'reject' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# @hide: Filter out +# +# Since: 5.0 +## +{ 'enum': 'CompatPolicyOutput', + 'data': [ 'accept', 'hide' ] } + +## +# @CompatPolicy: +# +# Policy for handling deprecated management interfaces. +# +# This is intended for testing users of the management interfaces. +# +# Limitation: covers only syntactic aspects of QMP, i.e. stuff tagged +# with feature 'deprecated'. We may want to extend it to cover +# semantic aspects, CLI, and experimental features. +# +# @deprecated-input: how to handle deprecated input (default 'accept') +# @deprecated-output: how to handle deprecated output (default 'accept') +# +# Since: 5.0 +## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } }
qapi/qapi-schema.json +1 -0
@@ -98,6 +98,7 @@ { 'include': 'migration.json' } { 'include': 'transaction.json' } { 'include': 'trace.json' } +{ 'include': 'compat.json' } { 'include': 'control.json' } { 'include': 'introspect.json' } { 'include': 'qom.json' }
include/qapi/compat-policy.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Policy for handling "funny" management interfaces +* +* Copyright (C) 2019 Red Hat, Inc. +* +* Authors: +* Markus Armbruster <[email protected]>, +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef QAPI_COMPAT_POLICY_H +#define QAPI_COMPAT_POLICY_H + +#include "qapi/qapi-types-compat.h" + +extern CompatPolicy compat_policy; + +#endif
qapi/qmp-dispatch.c +3 -0
@@ -12,6 +12,7 @@*/ #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h"
@@ -19,6 +20,8 @@#include "sysemu/runstate.h" #include "qapi/qmp/qbool.h" +CompatPolicy compat_policy; +static QDict *qmp_dispatch_check_obj (const QObject *request,bool allow_oob,QObject **id,Error **errp) {
softmmu/vl.c +17 -0
@@ -26,6 +26,7 @@#include "qemu-common.h" #include "qemu/units.h" #include "hw/qdev-properties.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qemu-version.h" #include "qemu/cutils.h"
@@ -104,6 +105,7 @@#include "sysemu/replay.h" #include "qapi/qapi-events-run-state.h" #include "qapi/qapi-visit-block-core.h" +#include "qapi/qapi-visit-compat.h" #include "qapi/qapi-visit-ui.h" #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-run-state.h"
@@ -3748,6 +3750,21 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opt_get_bool (opts,"mem-lock" , false); enable_cpu_pm =qemu_opt_get_bool (opts,"cpu-pm" , false);break ; +case QEMU_OPTION_compat: + { +CompatPolicy *opts; +Visitor *v; + + v =qobject_input_visitor_new_str (optarg,NULL , + &error_fatal); + +visit_type_CompatPolicy (v,NULL , &opts, &error_fatal); +QAPI_CLONE_MEMBERS (CompatPolicy, &compat_policy, opts); + +qapi_free_CompatPolicy (opts); +visit_free (v); +break ; + }case QEMU_OPTION_msg: opts =qemu_opts_parse_noisily (qemu_find_opts ("msg" ), optarg, false);
qapi/Makefile.objs +4 -4
@@ -5,10 +5,10 @@ util-obj-y += opts-visitor.o qapi-clone-visitor.o util-obj-y += qmp-event.o util-obj-y += qapi-util.o -QAPI_COMMON_MODULES = audio authz block-core block char common control crypto -QAPI_COMMON_MODULES += dump error introspect job machine migration misc -QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm -QAPI_COMMON_MODULES += trace transaction ui +QAPI_COMMON_MODULES = audio authz block-core block char common compat +QAPI_COMMON_MODULES += control crypto dump error introspect job +QAPI_COMMON_MODULES += machine migration misc net qdev qom rdma rocker +QAPI_COMMON_MODULES += run-state sockets tpm trace transaction ui QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
qemu-options.hx +21 -0
@@ -3360,6 +3360,27 @@ STEXI @table @option ETEXI +DEF("compat", HAS_ARG, QEMU_OPTION_compat, + "-compat [deprecated-input=accept|reject][,deprecated-output=accept|hide]\n" + " Policy for handling deprecated management interfaces\n", + QEMU_ARCH_ALL) +STEXI +@item -compat [deprecated-input=@var{input-policy}][,deprecated-output=@var{output-policy}] +@findex -compat +Set policy for handling deprecated management interfaces (experimental): +@table @option +@item deprecated-input=accept (default) +Accept deprecated commands and arguments +@item deprecated-input=reject +Reject deprecated commands and arguments +@item deprecated-output=accept (default) +Emit deprecated command results and events +@item deprecated-output=hide +Suppress deprecated command results and events +@end table +Limitation: covers only syntactic aspects of QMP. +ETEXI + DEF("fw_cfg", HAS_ARG, QEMU_OPTION_fwcfg, "-fw_cfg [name=]<name>,file=<file>\n" " add named fw_cfg entry with contents from file\n"
Signature · 1 line
2.21.1
PATCH v2 28/30 qapi: Implement -compat deprecated-output=hide
In reply to Markus ArmbrusterThis policy suppresses deprecated command results and deprecated events, and thus permits "testing the future".
Example:
---> {"execute": "query-cpus-fast"}
<--- {"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}Note the absence of deprecated member "arch".
No QMP event is deprecated right now.
--- include/qapi/qobject-output-visitor.h | 9 ++++++ include/qapi/visitor-impl.h | 3 ++ include/qapi/visitor.h | 9 ++++++ qapi/qapi-visit-core.c | 9 ++++++ qapi/qobject-output-visitor.c | 19 +++++++++++ tests/test-qmp-cmds.c | 42 ++++++++++++++++++++++--- tests/test-qmp-event.c | 19 +++++++++++ qapi/trace-events | 1 + scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 14 +++++++-- scripts/qapi/visit.py | 12 +++++++ tests/qapi-schema/qapi-schema-test.json | 17 +++++----- tests/qapi-schema/qapi-schema-test.out | 18 +++++------ 13 files changed, 149 insertions(+), 25 deletions(-)
include/qapi/qobject-output-visitor.h +9 -0
@@ -53,4 +53,13 @@ typedef struct QObjectOutputVisitor QObjectOutputVisitor;*/ Visitor *qobject_output_visitor_new (QObject **result); +/* +* Create a QObject output visitor for @obj for use with QMP +* +* This is like qobject_output_visitor_new(), except it obeys the +* policy for handling deprecated management interfaces set with +* -compat. +*/ +Visitor *qobject_output_visitor_new_qmp (QObject **result); +#endif
include/qapi/visitor-impl.h +3 -0
@@ -110,6 +110,9 @@ struct VisitorThe core takes care of the return type in the public interface. */ void (*optional)(Visitor *v,const char *name,bool *present); +/* Optional */ +bool (*deprecated)(Visitor *v,const char *name); +/* Must be set */ VisitorType type;
include/qapi/visitor.h +9 -0
@@ -449,6 +449,15 @@ void visit_end_alternate(Visitor *v, void **obj);*/ bool visit_optional (Visitor *v,const char *name,bool *present); +/* +* Should we visit deprecated member @name? +* +* @name must not be NULL. This function is only useful between +* visit_start_struct() and visit_end_struct(), since only objects +* have deprecated members. +*/ +bool visit_deprecated (Visitor *v,const char *name); +/* * Visit an enum value. *
qapi/qapi-visit-core.c +9 -0
@@ -137,6 +137,15 @@ bool visit_optional(Visitor *v, const char *name, bool *present)return *present; } +bool visit_deprecated (Visitor *v,const char *name) +{ +trace_visit_deprecated (v, name); +if (v->deprecated) { +return v->deprecated (v, name); + } +return true; +} +bool visit_is_input (Visitor *v) {return v->type ==VISITOR_INPUT ;
qapi/qobject-output-visitor.c +19 -0
@@ -13,6 +13,7 @@*/ #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/qobject-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/queue.h"
@@ -31,6 +32,8 @@ typedef struct QStackEntry {struct QObjectOutputVisitor {Visitor visitor; +CompatPolicyOutput deprecated_policy; + QSLIST_HEAD(, QStackEntry) stack; /* Stack of unfinished containers */QObject *root;/* Root of the output visit */ QObject **result;/* User's storage location for result */
@@ -198,6 +201,13 @@ static void qobject_output_type_null(Visitor *v, const char *name,qobject_output_add (qov, name,qnull ()); } +static bool qobject_output_deprecated (Visitor *v,const char *name) +{ +QObjectOutputVisitor *qov =to_qov (v); + +return qov->deprecated_policy !=COMPAT_POLICY_OUTPUT_HIDE ; +} +/* Finish building, and return the root object. * The root object is never null. The caller becomes the object's * owner, and should use qobject_unref() when done with it. */
@@ -247,6 +257,7 @@ Visitor *qobject_output_visitor_new(QObject **result) v->visitor.type_number = qobject_output_type_number; v->visitor.type_any = qobject_output_type_any; v->visitor.type_null = qobject_output_type_null; + v->visitor.deprecated = qobject_output_deprecated; v->visitor.complete = qobject_output_complete; v->visitor.free = qobject_output_free;
@@ -255,3 +266,11 @@ Visitor *qobject_output_visitor_new(QObject **result)return &v->visitor; } + +Visitor *qobject_output_visitor_new_qmp (QObject **result) +{ +QObjectOutputVisitor *v =to_qov (qobject_output_visitor_new (result)); + + v->deprecated_policy = compat_policy.deprecated_output; +return &v->visitor; +}
tests/test-qmp-cmds.c +37 -5
65 lines not on this page · raw message
tests/test-qmp-event.c +19 -0
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h"
@@ -140,6 +141,23 @@ static void test_event_d(TestEventData *data,qobject_unref (data->expect); } +static void test_event_deprecated (TestEventData *data,const void *unused) +{ + data->expect =qdict_from_jsonf_nofail ("{ 'event': 'TEST-EVENT-FEATURES1' }" ); + +memset (&compat_policy,0 ,sizeof (compat_policy)); + +qapi_event_send_test_event_features1 (); +g_assert (data->emitted); + + compat_policy.deprecated_output =COMPAT_POLICY_OUTPUT_HIDE ; + data->emitted = false; +qapi_event_send_test_event_features1 (); +g_assert (!data->emitted); + +qobject_unref (data->expect); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -148,6 +166,7 @@ int main(int argc, char **argv)event_test_add ("/event/event_b" , test_event_b);event_test_add ("/event/event_c" , test_event_c);event_test_add ("/event/event_d" , test_event_d); +event_test_add ("/event/deprecated" , test_event_deprecated);g_test_run ();return 0 ;
qapi/trace-events +1 -0
@@ -17,6 +17,7 @@ visit_start_alternate(void *v, const char *name, void *obj, size_t size) "v=%p n visit_end_alternate(void *v, void *obj) "v=%p obj=%p" visit_optional(void *v, const char *name, bool *present) "v=%p name=%s present=%p" +visit_deprecated(void *v, const char *name) "v=%p name=%s" visit_type_enum(void *v, const char *name, int *obj) "v=%p name=%s obj=%p" visit_type_int(void *v, const char *name, int64_t *obj) "v=%p name=%s obj=%p"
scripts/qapi/commands.py +1 -1
@@ -69,7 +69,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out, Error *err = NULL; Visitor *v; - v = qobject_output_visitor_new(ret_out); + v = qobject_output_visitor_new_qmp(ret_out); visit_type_%(c_name)s(v, "unused", &ret_in, &err); if (!err) { visit_complete(v, ret_out);
scripts/qapi/events.py +12 -2
@@ -61,7 +61,8 @@ def gen_param_var(typ): return ret -def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): +def gen_event_send(name, arg_type, features, boxed, + event_enum_name, event_emit): # FIXME: Our declaration of local variables (and of 'errp' in the # parameter list) can collide with exploded members of the event's # data type passed in as parameters. If this collision ever hits in
@@ -86,6 +87,14 @@ def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): if not boxed: ret += gen_param_var(arg_type) + if 'deprecated' in [f.name for f in features]: + ret += mcgen(''' + + if (compat_policy.deprecated_output == COMPAT_POLICY_OUTPUT_HIDE) { + return; + } +''') + ret += mcgen(''' qmp = qmp_event_build_dict("%(name)s");
@@ -154,6 +163,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): #include "%(prefix)sqapi-emit-events.h" #include "%(events)s.h" #include "%(visit)s.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qapi/qobject-output-visitor.h"
@@ -192,7 +202,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); def visit_event(self, name, info, ifcond, features, arg_type, boxed): with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) - self._genc.add(gen_event_send(name, arg_type, boxed, + self._genc.add(gen_event_send(name, arg_type, features, boxed, self._event_enum_name, self._event_emit_name)) # Note: we generate the enum member regardless of @ifcond, to
scripts/qapi/visit.py +12 -0
@@ -56,6 +56,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) c_type=base.c_name()) for memb in members: + deprecated = 'deprecated' in [f.name for f in memb.features] ret += gen_if(memb.ifcond) if memb.optional: ret += mcgen('''
@@ -63,6 +64,12 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ''', name=memb.name, c_name=c_name(memb.name)) push_indent() + if deprecated: + ret += mcgen(''' + if (visit_deprecated(v, "%(name)s")) { +''', + name=memb.name) + push_indent() ret += mcgen(''' visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err); if (err) {
@@ -71,6 +78,11 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ''', c_type=memb.type.c_name(), name=memb.name, c_name=c_name(memb.name)) + if deprecated: + pop_indent() + ret += mcgen(''' + } +''') if memb.optional: pop_indent() ret += mcgen('''
tests/qapi-schema/qapi-schema-test.json +9 -8
@@ -297,14 +297,15 @@ 'features': [ 'feature1' ] } { 'command': 'test-features0', - 'data': { 'fs0': 'FeatureStruct0', - 'fs1': 'FeatureStruct1', - 'fs2': 'FeatureStruct2', - 'fs3': 'FeatureStruct3', - 'fs4': 'FeatureStruct4', - 'cfs1': 'CondFeatureStruct1', - 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' }, + 'data': { '*fs0': 'FeatureStruct0', + '*fs1': 'FeatureStruct1', + '*fs2': 'FeatureStruct2', + '*fs3': 'FeatureStruct3', + '*fs4': 'FeatureStruct4', + '*cfs1': 'CondFeatureStruct1', + '*cfs2': 'CondFeatureStruct2', + '*cfs3': 'CondFeatureStruct3' }, + 'returns': 'FeatureStruct1', 'features': [] } { 'command': 'test-command-features1',
tests/qapi-schema/qapi-schema-test.out +9 -9
@@ -407,15 +407,15 @@ alternate FeatureAlternate1 case eins: FeatureStruct1 feature feature1 object q_obj_test-features0-arg - member fs0: FeatureStruct0 optional=False - member fs1: FeatureStruct1 optional=False - member fs2: FeatureStruct2 optional=False - member fs3: FeatureStruct3 optional=False - member fs4: FeatureStruct4 optional=False - member cfs1: CondFeatureStruct1 optional=False - member cfs2: CondFeatureStruct2 optional=False - member cfs3: CondFeatureStruct3 optional=False -command test-features0 q_obj_test-features0-arg -> None + member fs0: FeatureStruct0 optional=True + member fs1: FeatureStruct1 optional=True + member fs2: FeatureStruct2 optional=True + member fs3: FeatureStruct3 optional=True + member fs4: FeatureStruct4 optional=True + member cfs1: CondFeatureStruct1 optional=True + member cfs2: CondFeatureStruct2 optional=True + member cfs3: CondFeatureStruct3 optional=True +command test-features0 q_obj_test-features0-arg -> FeatureStruct1 gen=True success_response=True boxed=False oob=False preconfig=False command test-command-features1 None -> None gen=True success_response=True boxed=False oob=False preconfig=False
Signature · 1 line
2.21.1
PATCH v2 29/30 qapi: Implement -compat deprecated-input=reject
In reply to Markus ArmbrusterThis policy makes deprecated commands fail like this:
---> {"execute": "query-cpus"}
<--- {"error": {"class": "CommandNotFound", "desc": "Deprecated command query-cpus disabled by policy"}}When the command is removed, the error will change to
<--- {"error": {"class": "CommandNotFound", "desc": "The command query-cpus has not been found"}}It makes commands with deprecated arguments fail like this:
---> {"execute": "block-commit", "arguments": {"device": "virtio0", "top": "/tmp/snap1.qcow2"}}
<--- {"error": {"class": "GenericError", "desc": "Deprecated parameter 'top' disabled by policy"}}When the argument is removed, the error will change to
<--- {"error": {"class": "GenericError", "desc": "Parameter 'top' is unexpected"}}The policy thus permits "testing the future".
--- include/qapi/qmp/dispatch.h | 1 + include/qapi/qobject-input-visitor.h | 9 +++++ include/qapi/visitor-impl.h | 2 +- include/qapi/visitor.h | 2 +- qapi/qapi-visit-core.c | 4 +-- qapi/qmp-dispatch.c | 13 ++++++++ qapi/qobject-input-visitor.c | 28 ++++++++++++++++ qapi/qobject-output-visitor.c | 3 +- tests/test-qmp-cmds.c | 49 ++++++++++++++++++++++++++++ scripts/qapi/commands.py | 12 ++++--- scripts/qapi/visit.py | 10 +++--- 11 files changed, 120 insertions(+), 13 deletions(-)
include/qapi/qmp/dispatch.h +1 -0
@@ -24,6 +24,7 @@ typedef enum QmpCommandOptionsQCO_NO_SUCCESS_RESP = (1U <<0 ),QCO_ALLOW_OOB = (1U <<1 ),QCO_ALLOW_PRECONFIG = (1U <<2 ), +QCO_DEPRECATED = (1U <<3 ), } QmpCommandOptions; typedef struct QmpCommand
include/qapi/qobject-input-visitor.h +9 -0
@@ -58,6 +58,15 @@ typedef struct QObjectInputVisitor QObjectInputVisitor;*/ Visitor *qobject_input_visitor_new (QObject *obj); +/* +* Create a QObject input visitor for @obj for use with QMP +* +* This is like qobject_input_visitor_new(), except it obeys the +* policy for handling deprecated management interfaces set with +* -compat. +*/ +Visitor *qobject_input_visitor_new_qmp (QObject *obj); +/* * Create a QObject input visitor for @obj for use with keyval_parse() *
include/qapi/visitor-impl.h +1 -1
@@ -111,7 +111,7 @@ struct Visitorvoid (*optional)(Visitor *v,const char *name,bool *present);/* Optional */ -bool (*deprecated)(Visitor *v,const char *name); +bool (*deprecated)(Visitor *v,const char *name,Error **errp);/* Must be set */ VisitorType type;
include/qapi/visitor.h +1 -1
@@ -456,7 +456,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present);* visit_start_struct() and visit_end_struct(), since only objects * have deprecated members. */ -bool visit_deprecated (Visitor *v,const char *name); +bool visit_deprecated (Visitor *v,const char *name,Error **errp);/* * Visit an enum value.
qapi/qapi-visit-core.c +2 -2
@@ -137,11 +137,11 @@ bool visit_optional(Visitor *v, const char *name, bool *present)return *present; } -bool visit_deprecated (Visitor *v,const char *name) +bool visit_deprecated (Visitor *v,const char *name,Error **errp) {trace_visit_deprecated (v, name);if (v->deprecated) { -return v->deprecated (v, name); +return v->deprecated (v, name, errp); }return true; }
qapi/qmp-dispatch.c +13 -0
@@ -132,6 +132,19 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, "The command %s has not been found", command); goto out; } +if (cmd->options &QCO_DEPRECATED ) { +switch (compat_policy.deprecated_input) { +case COMPAT_POLICY_INPUT_ACCEPT : +break ; +case COMPAT_POLICY_INPUT_REJECT : +error_set (&err,ERROR_CLASS_COMMAND_NOT_FOUND , +"Deprecated command %s disabled by policy" , + command); + goto out; +default : +abort (); + } + }if (!cmd->enabled) { error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has been disabled for this instance",
qapi/qobject-input-visitor.c +28 -0
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include <math.h> +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/visitor-impl.h"
@@ -43,6 +44,7 @@ typedef struct StackObject {struct QObjectInputVisitor {Visitor visitor; +CompatPolicyInput deprecated_policy;/* Root of visit at visitor creation. */ QObject *root;
@@ -640,6 +642,23 @@ static void qobject_input_optional(Visitor *v, const char *name, bool *present) *present = true; } +static bool qobject_input_deprecated (Visitor *v,const char *name, +Error **errp) +{ +QObjectInputVisitor *qiv =to_qiv (v); + +switch (qiv->deprecated_policy) { +case COMPAT_POLICY_INPUT_ACCEPT : +return true; +case COMPAT_POLICY_INPUT_REJECT : +error_setg (errp,"Deprecated parameter '%s' disabled by policy" , + name); +return false; +default : +abort (); + } +} +static void qobject_input_free (Visitor *v) {QObjectInputVisitor *qiv =to_qiv (v);
@@ -674,6 +693,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj) v->visitor.end_list = qobject_input_end_list; v->visitor.start_alternate = qobject_input_start_alternate; v->visitor.optional = qobject_input_optional; + v->visitor.deprecated = qobject_input_deprecated; v->visitor.free = qobject_input_free; v->root =qobject_ref (obj);
@@ -696,6 +716,14 @@ Visitor *qobject_input_visitor_new(QObject *obj)return &v->visitor; } +Visitor *qobject_input_visitor_new_qmp (QObject *obj) +{ +QObjectInputVisitor *v =to_qiv (qobject_input_visitor_new (obj)); + + v->deprecated_policy = compat_policy.deprecated_input; +return &v->visitor; +} +Visitor *qobject_input_visitor_new_keyval (QObject *obj) {QObjectInputVisitor *v =qobject_input_visitor_base_new (obj);
qapi/qobject-output-visitor.c +2 -1
@@ -201,7 +201,8 @@ static void qobject_output_type_null(Visitor *v, const char *name,qobject_output_add (qov, name,qnull ()); } -static bool qobject_output_deprecated (Visitor *v,const char *name) +static bool qobject_output_deprecated (Visitor *v,const char *name, +Error **errp) {QObjectOutputVisitor *qov =to_qov (v);
tests/test-qmp-cmds.c +49 -0
61 lines not on this page · raw message
scripts/qapi/commands.py +8 -4
@@ -132,7 +132,7 @@ def gen_marshal(name, arg_type, boxed, ret_type): push_indent() ret += mcgen(''' - v = qobject_input_visitor_new(QOBJECT(args)); + v = qobject_input_visitor_new_qmp(QOBJECT(args)); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out;
@@ -194,9 +194,13 @@ out: return ret -def gen_register_command(name, success_response, allow_oob, allow_preconfig): +def gen_register_command(name, features, + success_response, allow_oob, allow_preconfig): options = [] + if 'deprecated' in [f.name for f in features]: + options += ['QCO_DEPRECATED'] + if not success_response: options += ['QCO_NO_SUCCESS_RESP'] if allow_oob:
@@ -302,8 +306,8 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type)) self._genh.add(gen_marshal_decl(name)) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) - self._regy.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig)) + self._regy.add(gen_register_command( + name, features, success_response, allow_oob, allow_preconfig)) def gen_commands(schema, output_dir, prefix):
scripts/qapi/visit.py +6 -4
@@ -66,15 +66,12 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) push_indent() if deprecated: ret += mcgen(''' - if (visit_deprecated(v, "%(name)s")) { + if (visit_deprecated(v, "%(name)s", &err)) { ''', name=memb.name) push_indent() ret += mcgen(''' visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err); - if (err) { - goto out; - } ''', c_type=memb.type.c_name(), name=memb.name, c_name=c_name(memb.name))
@@ -82,6 +79,11 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) pop_indent() ret += mcgen(''' } +''') + ret += mcgen(''' + if (err) { + goto out; + } ''') if memb.optional: pop_indent()
Signature · 1 line
2.21.1
PATCH v2 30/30 qapi: New -compat deprecated-input=crash
In reply to Markus ArmbrusterPolicy "crash" calls abort() when deprecated input is received.
Bugs in integration tests may mask the error from policy "reject". Provide a larger hammer: crash outright. Masking that seems unlikely.
--- qapi/compat.json | 3 ++- qapi/qmp-dispatch.c | 1 + qapi/qobject-input-visitor.c | 1 + qemu-options.hx | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-)
qapi/compat.json +2 -1
@@ -11,11 +11,12 @@ # # @accept: Accept silently # @reject: Reject with an error +# @crash: abort() the process # # Since: 5.0 ## { 'enum': 'CompatPolicyInput', - 'data': [ 'accept', 'reject' ] } + 'data': [ 'accept', 'reject', 'crash' ] } ## # @CompatPolicyOutput:
qapi/qmp-dispatch.c +1 -0
@@ -141,6 +141,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,"Deprecated command %s disabled by policy" , command); goto out; +case COMPAT_POLICY_INPUT_CRASH :default :abort (); }
qapi/qobject-input-visitor.c +1 -0
@@ -654,6 +654,7 @@ static bool qobject_input_deprecated(Visitor *v, const char *name,error_setg (errp,"Deprecated parameter '%s' disabled by policy" , name);return false; +case COMPAT_POLICY_INPUT_CRASH :default :abort (); }
qemu-options.hx +3 -1
@@ -3361,7 +3361,7 @@ STEXI ETEXI DEF("compat", HAS_ARG, QEMU_OPTION_compat, - "-compat [deprecated-input=accept|reject][,deprecated-output=accept|hide]\n" + "-compat [deprecated-input=accept|reject|crash][,deprecated-output=accept|hide]\n" " Policy for handling deprecated management interfaces\n", QEMU_ARCH_ALL) STEXI
@@ -3373,6 +3373,8 @@ Set policy for handling deprecated management interfaces (experimental): Accept deprecated commands and arguments @item deprecated-input=reject Reject deprecated commands and arguments +@item deprecated-input=crash +Crash on deprecated command @item deprecated-output=accept (default) Emit deprecated command results and events @item deprecated-output=hide
Signature · 1 line
2.21.1
Quoted 7 lines · Markus Armbruster
Based-on: <[email protected]>
This series extends QMP introspection to cover deprecation. Additionally, new option -compat lets you configure what to do when deprecated interfaces get used. This is intended for testing users of the management interfaces. It is experimental.
How much do you think this is likely to affect the generate-rst-from-qapi-docs series? I'd really like that to go in for this release, but this looks like it's shaping up to be a big conflict :-(
thanks
-- PMM
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Markus Armbruster
Based-on: <[email protected]>
This series extends QMP introspection to cover deprecation. Additionally, new option -compat lets you configure what to do when deprecated interfaces get used. This is intended for testing users of the management interfaces. It is experimental.
Quoted 4 lines
How much do you think this is likely to affect the generate-rst-from-qapi-docs series? I'd really like that to go in for this release, but this looks like it's shaping up to be a big conflict :-(
I paused reviewing your series to post this one, because "I'd really like that to go in for this release" :)
My series touches 21 existing commented definitions in qapi/, six more in tests/qapi-schema/doc-good.json, and adds new module qapi/compat.json. Consolidated diff appended.
Rule of thumb for reducing conflict resolution labor: the bigger manual change goes first. Yours is bigger, but I don't remember how manual it is.
Let's try to get both series reviewed, then figure out together how to get them merged with the least pain.
$ git-diff -p --stat master posted/qapi-features \*.json qapi/block-core.json | 69 +++++++++++++++++++------ qapi/block.json | 9 ++-- qapi/char.json | 1 + qapi/compat.json | 52 +++++++++++++++++++ qapi/control.json | 11 ++-- qapi/introspect.json | 26 +++++----- qapi/machine.json | 34 ++++++------ qapi/migration.json | 36 ++++++++----- qapi/misc.json | 13 ++--- qapi/qapi-schema.json | 1 + tests/qapi-schema/doc-good.json | 22 +++++++- tests/qapi-schema/features-deprecated-type.json | 3 ++ tests/qapi-schema/qapi-schema-test.json | 48 +++++++++++------ 13 files changed, 239 insertions(+), 86 deletions(-)
qapi/block-core.json +52 -17
@@ -297,7 +297,7 @@ # # @encrypted: true if the backing device is encrypted # -# @encryption_key_missing: Deprecated; always false +# @encryption_key_missing: always false # # @detect_zeroes: detect and optimize zero writes (Since 2.1) #
@@ -363,13 +363,19 @@ # @dirty-bitmaps: dirty bitmaps information (only present if node # has one or more dirty bitmaps) (Since 4.2) # +# Features: +# @deprecated: Member @encryption_key_missing is deprecated. It is +# always false. +# # Since: 0.14.0 # ## { 'struct': 'BlockDeviceInfo', 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', - 'encrypted': 'bool', 'encryption_key_missing': 'bool', + 'encrypted': 'bool', + 'encryption_key_missing': { 'type': 'bool', + 'features': [ 'deprecated' ] }, 'detect_zeroes': 'BlockdevDetectZeroesOptions', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
@@ -475,7 +481,7 @@ # # @granularity: granularity of the dirty bitmap in bytes (since 1.4) # -# @status: Deprecated in favor of @recording and @locked. (since 2.4) +# @status: current status of the dirty bitmap (since 2.4) # # @recording: true if the bitmap is recording new writes from the guest. # Replaces `active` and `disabled` statuses. (since 4.0)
@@ -492,11 +498,17 @@ # @busy to be false. This bitmap cannot be used. To remove # it, use @block-dirty-bitmap-remove. (Since 4.0) # +# Features: +# @deprecated: Member @status is deprecated. Use @recording and +# @locked instead. +# # Since: 1.3 ## { 'struct': 'BlockDirtyInfo', 'data': {'*name': 'str', 'count': 'int', 'granularity': 'uint32', - 'recording': 'bool', 'busy': 'bool', 'status': 'DirtyBitmapStatus', + 'recording': 'bool', 'busy': 'bool', + 'status': { 'type': 'DirtyBitmapStatus', + 'features': [ 'deprecated' ] }, 'persistent': 'bool', '*inconsistent': 'bool' } } ##
@@ -659,7 +671,6 @@ # # @dirty-bitmaps: dirty bitmaps information (only present if the # driver has one or more dirty bitmaps) (Since 2.0) -# Deprecated in 4.2; see BlockDeviceInfo instead. # # @io-status: @BlockDeviceIoStatus. Only present if the device # supports it and the VM is configured to stop on errors
@@ -669,13 +680,18 @@ # @inserted: @BlockDeviceInfo describing the device if media is # present # +# Features: +# @deprecated: Member @dirty-bitmaps is deprecated. Use @inserted +# member @dirty-bitmaps instead. +# # Since: 0.14.0 ## { 'struct': 'BlockInfo', 'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool', 'locked': 'bool', '*inserted': 'BlockDeviceInfo', '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus', - '*dirty-bitmaps': ['BlockDirtyInfo'] } } + '*dirty-bitmaps': { 'type': ['BlockDirtyInfo'], + 'features': [ 'deprecated' ] } } } ## # @BlockMeasureInfo:
@@ -1616,7 +1632,7 @@ # @base: Same as @base-node, except that it is a file name rather than a node # name. This must be the exact filename string that was used to open the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @top-node: The node name of the backing image within the image chain # which contains the topmost data to be committed down. If
@@ -1625,7 +1641,7 @@ # @top: Same as @top-node, except that it is a file name rather than a node # name. This must be the exact filename string that was used to open the # node; other strings, even if addressing the same file, are not -# accepted (deprecated, use @base-node instead) +# accepted # # @backing-file: The backing file string to write into the overlay # image of 'top'. If 'top' is the active layer,
@@ -1679,6 +1695,10 @@ # list without user intervention. # Defaults to true. (Since 3.1) # +# Features: +# @deprecated: Members @base and @top are deprecated. Use @base-node +# and @top-node instead. +# # Returns: - Nothing on success # - If @device does not exist, DeviceNotFound # - Any other error returns a GenericError.
@@ -1695,7 +1715,9 @@ ## { 'command': 'block-commit', 'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str', - '*base': 'str', '*top-node': 'str', '*top': 'str', + '*base': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*top-node': 'str', + '*top': { 'type': 'str', 'features': [ 'deprecated' ] }, '*backing-file': 'str', '*speed': 'int', '*on-error': 'BlockdevOnError', '*filter-node-name': 'str',
@@ -2433,7 +2455,7 @@ # # A set of parameters describing block throttling. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) #
@@ -2501,10 +2523,14 @@ # # @group: throttle group name (Since 2.4) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, + '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int',
@@ -4776,7 +4802,7 @@ # to it # - if the guest device does not have an actual tray # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) #
@@ -4785,6 +4811,9 @@ # immediately); if true, the tray will be opened regardless of whether # it is locked # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example:
@@ -4803,7 +4832,7 @@ # ## { 'command': 'blockdev-open-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } }
@@ -4816,10 +4845,13 @@ # # If the tray was already closed before, this will be a no-op. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Example:
@@ -4838,7 +4870,7 @@ # ## { 'command': 'blockdev-close-tray', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str' } } ##
@@ -4945,7 +4977,7 @@ # combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-medium # and blockdev-close-tray). # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device # (since: 2.8)
@@ -4958,6 +4990,9 @@ # @read-only-mode: change the read-only mode of the device; defaults # to 'retain' # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Since: 2.5 # # Examples:
@@ -4992,7 +5027,7 @@ # ## { 'command': 'blockdev-change-medium', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', 'filename': 'str', '*format': 'str',
qapi/block.json +6 -3
@@ -185,15 +185,18 @@ ## # @eject: # -# Ejects a device from a removable drive. +# Ejects the medium from a removable block device. # -# @device: Block device name (deprecated, use @id instead) +# @device: Block device name # # @id: The name or QOM path of the guest device (since: 2.8) # # @force: If true, eject regardless of whether the drive is locked. # If not specified, the default value is false. # +# Features: +# @deprecated: Member @device is deprecated. Use @id instead. +# # Returns: - Nothing on success # - If @device is not a valid block device, DeviceNotFound # Notes: Ejecting a device with no media results in success
@@ -206,7 +209,7 @@ # <- { "return": {} } ## { 'command': 'eject', - 'data': { '*device': 'str', + 'data': { '*device': { 'type': 'str', 'features': [ 'deprecated' ] }, '*id': 'str', '*force': 'bool' } }
qapi/char.json +1 -0
@@ -258,6 +258,7 @@ # @server: create server socket (default: true) # @wait: wait for incoming connection on server # sockets (default: false). +# Silently ignored with server: false. This use is deprecated. # @nodelay: set TCP_NODELAY socket option (default: false) # @telnet: enable telnet protocol on server # sockets (default: false)
qapi/compat.json new file +52 -0
52 lines not on this page · raw message
qapi/control.json +7 -4
@@ -174,13 +174,15 @@ # # Return information on QMP events. # +# Features: +# @deprecated: This command is deprecated, because its output doesn't +# reflect compile-time configuration. Use 'query-qmp-schema' +# instead. +# # Returns: A list of @EventInfo. # # Since: 1.2.0 # -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# # Example: # # -> { "execute": "query-events" }
@@ -198,7 +200,8 @@ # Note: This example has been shortened as the real response is too long. # ## -{ 'command': 'query-events', 'returns': ['EventInfo'] } +{ 'command': 'query-events', 'returns': ['EventInfo'], + 'features': [ 'deprecated' ] } ## # @quit:
qapi/introspect.json +14 -12
@@ -89,12 +89,18 @@ # # @meta-type: the entity's meta type, inherited from @base. # +# @features: names of features associated with the entity, in no +# particular order. +# (since 4.1 for object types, 4.2 for commands, 5.0 for +# the rest) +# # Additional members depend on the value of @meta-type. # # Since: 2.5 ## { 'union': 'SchemaInfo', - 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType' }, + 'base': { 'name': 'str', 'meta-type': 'SchemaMetaType', + '*features': [ 'str' ] }, 'discriminator': 'meta-type', 'data': { 'builtin': 'SchemaInfoBuiltin',
@@ -174,9 +180,6 @@ # and may even differ from the order of the values of the # enum type of the @tag. # -# @features: names of features associated with the type, in no particular -# order. (since: 4.1) -# # Values of this type are JSON object on the wire. # # Since: 2.5
@@ -184,8 +187,7 @@ { 'struct': 'SchemaInfoObject', 'data': { 'members': [ 'SchemaInfoObjectMember' ], '*tag': 'str', - '*variants': [ 'SchemaInfoObjectVariant' ], - '*features': [ 'str' ] } } + '*variants': [ 'SchemaInfoObjectVariant' ] } } ## # @SchemaInfoObjectMember:
@@ -204,11 +206,15 @@ # Future extension: if present and non-null, the parameter # is optional, and defaults to this value. # +# @features: names of features associated with the member, in no +# particular order. (since 5.0) +# # Since: 2.5 ## { 'struct': 'SchemaInfoObjectMember', - 'data': { 'name': 'str', 'type': 'str', '*default': 'any' } } + 'data': { 'name': 'str', 'type': 'str', '*default': 'any', # @default's type must be null or match @type + '*features': [ 'str' ] } } ## # @SchemaInfoObjectVariant:
@@ -266,17 +272,13 @@ # @allow-oob: whether the command allows out-of-band execution, # defaults to false (Since: 2.12) # -# @features: names of features associated with the command, in no particular -# order. (since 4.2) -# # TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ## { 'struct': 'SchemaInfoCommand', 'data': { 'arg-type': 'str', 'ret-type': 'str', - '*allow-oob': 'bool', - '*features': [ 'str' ] } } + '*allow-oob': 'bool' } } ## # @SchemaInfoEvent:
qapi/machine.json +19 -15
@@ -184,8 +184,11 @@ # This command causes vCPU threads to exit to userspace, which causes # a small interruption to guest CPU execution. This will have a negative # impact on realtime guests and other latency sensitive guest workloads. -# It is recommended to use @query-cpus-fast instead of this command to -# avoid the vCPU interruption. +# +# Features: +# @deprecated: This command is deprecated, because it interferes with +# the guest. Use 'query-cpus-fast' instead to avoid the vCPU +# interruption. # # Returns: a list of @CpuInfo for each virtual CPU #
@@ -216,12 +219,9 @@ # ] # } # -# Notes: This interface is deprecated (since 2.12.0), and it is strongly -# recommended that you avoid using it. Use @query-cpus-fast to -# obtain information about virtual CPUs. -# ## -{ 'command': 'query-cpus', 'returns': ['CpuInfo'] } +{ 'command': 'query-cpus', 'returns': ['CpuInfo'], + 'features': [ 'deprecated' ] } ## # @CpuInfoFast:
@@ -237,12 +237,14 @@ # @props: properties describing to which node/socket/core/thread # virtual CPU belongs to, provided if supported by board # -# @arch: base architecture of the cpu; deprecated since 3.0.0 in favor -# of @target +# @arch: base architecture of the cpu # # @target: the QEMU system emulation target, which determines which # additional fields will be listed (since 3.0) # +# Features: +# @deprecated: Member @arch is deprecated. Use @target instead. +# # Since: 2.12 # ##
@@ -251,7 +253,8 @@ 'qom-path' : 'str', 'thread-id' : 'int', '*props' : 'CpuInstanceProperties', - 'arch' : 'CpuInfoArch', + 'arch' : { 'type': 'CpuInfoArch', + 'features': [ 'deprecated' ] }, 'target' : 'SysEmuTarget' }, 'discriminator' : 'target', 'data' : { 's390x' : 'CpuInfoS390' } }
@@ -307,21 +310,22 @@ # # @id: ID of CPU to be created, valid values [0..max_cpus) # +# Features: +# @deprecated: This command is deprecated. Use `device_add` instead. +# See the `query-hotpluggable-cpus` command for details. +# # Returns: Nothing on success # # Since: 1.5 # -# Note: This command is deprecated. The `device_add` command should be -# used instead. See the `query-hotpluggable-cpus` command for -# details. -# # Example: # # -> { "execute": "cpu-add", "arguments": { "id": 2 } } # <- { "return": {} } # ## -{ 'command': 'cpu-add', 'data': {'id': 'int'} } +{ 'command': 'cpu-add', 'data': {'id': 'int'}, + 'features': [ 'deprecated' ] } ## # @MachineInfo:
qapi/migration.json +24 -12
@@ -1196,9 +1196,11 @@ # # @value: maximum downtime in seconds # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 #
@@ -1208,7 +1210,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } +{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'}, + 'features': [ 'deprecated' ] } ## # @migrate_set_speed:
@@ -1217,9 +1220,11 @@ # # @value: maximum speed in bytes per second. # -# Returns: nothing on success +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# Returns: nothing on success # # Since: 0.14.0 #
@@ -1229,7 +1234,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate_set_speed', 'data': {'value': 'int'} } +{ 'command': 'migrate_set_speed', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } ## # @migrate-set-cache-size:
@@ -1238,13 +1244,15 @@ # # @value: cache size in bytes # +# Features: +# @deprecated: This command is deprecated. Use +# 'migrate-set-parameters' instead. +# # The size will be rounded down to the nearest power of 2. # The cache size can be modified before and during ongoing migration # # Returns: nothing on success # -# Notes: This command is deprecated in favor of 'migrate-set-parameters' -# # Since: 1.2 # # Example:
@@ -1254,17 +1262,20 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} } +{ 'command': 'migrate-set-cache-size', 'data': {'value': 'int'}, + 'features': [ 'deprecated' ] } ## # @query-migrate-cache-size: # # Query migration XBZRLE cache size # +# Features: +# @deprecated: This command is deprecated. Use +# 'query-migrate-parameters' instead. +# # Returns: XBZRLE cache size in bytes # -# Notes: This command is deprecated in favor of 'query-migrate-parameters' -# # Since: 1.2 # # Example:
@@ -1273,7 +1284,8 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int' } +{ 'command': 'query-migrate-cache-size', 'returns': 'int', + 'features': [ 'deprecated' ] } ## # @migrate:
qapi/misc.json +7 -6
@@ -872,14 +872,14 @@ # If @device is 'vnc' and @target is 'password', this is the new VNC # password to set. See change-vnc-password for additional notes. # +# Features: +# @deprecated: This command is deprecated. For changing block +# devices, use 'blockdev-change-medium' instead; for changing VNC +# parameters, use 'change-vnc-password' instead. +# # Returns: - Nothing on success. # - If @device is not a valid block device, DeviceNotFound # -# Notes: This interface is deprecated, and it is strongly recommended that you -# avoid using it. For changing block devices, use -# blockdev-change-medium; for changing VNC parameters, use -# change-vnc-password. -# # Since: 0.14.0 # # Example:
@@ -900,7 +900,8 @@ # ## { 'command': 'change', - 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'}, + 'features': [ 'deprecated' ] } ## # @xen-set-global-dirty-log:
qapi/qapi-schema.json +1 -0
@@ -98,6 +98,7 @@ { 'include': 'migration.json' } { 'include': 'transaction.json' } { 'include': 'trace.json' } +{ 'include': 'compat.json' } { 'include': 'control.json' } { 'include': 'introspect.json' } { 'include': 'qom.json' }
tests/qapi-schema/doc-good.json +21 -1
@@ -53,10 +53,14 @@ # @Enum: # @one: The _one_ {and only} # +# Features: +# @enum-feat: Also _one_ {and only} +# # @two is undocumented ## { 'enum': 'Enum', 'data': [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ], + 'features': [ 'enum-feat' ], 'if': 'defined(IFCOND)' } ##
@@ -74,10 +78,13 @@ # # Features: # @variant1-feat: a feature +# @member-feat: a member feature ## { 'struct': 'Variant1', 'features': [ 'variant1-feat' ], - 'data': { 'var1': { 'type': 'str', 'if': 'defined(IFSTR)' } } } + 'data': { 'var1': { 'type': 'str', + 'features': [ 'member-feat' ], + 'if': 'defined(IFSTR)' } } } ## # @Variant2:
@@ -86,24 +93,34 @@ ## # @Object: +# Features: +# @union-feat1: a feature ## { 'union': 'Object', + 'features': [ 'union-feat1' ], 'base': 'Base', 'discriminator': 'base1', 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } } ## # @SugaredUnion: +# Features: +# @union-feat2: a feature ## { 'union': 'SugaredUnion', + 'features': [ 'union-feat2' ], 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } } ## # @Alternate: # @i: an integer # @b is undocumented +# +# Features: +# @alt-feat: a feature ## { 'alternate': 'Alternate', + 'features': [ 'alt-feat' ], 'data': { 'i': 'int', 'b': 'bool' } } ##
@@ -160,6 +177,9 @@ ## # @EVT-BOXED: +# Features: +# @feat3: a feature ## { 'event': 'EVT-BOXED', 'boxed': true, + 'features': [ 'feat3' ], 'data': 'Object' }
tests/qapi-schema/features-deprecated-type.json new file +3 -0
@@ -0,0 +1,3 @@ +# Feature 'deprecated' is not supported for types +{ 'struct': 'S', 'data': {}, + 'features': [ 'deprecated' ] }
tests/qapi-schema/qapi-schema-test.json +32 -16
70 lines not on this page · raw message
Quoted 9 lines · Markus Armbruster
Quoted 4 lines · Peter Maydell
How much do you think this is likely to affect the generate-rst-from-qapi-docs series? I'd really like that to go in for this release, but this looks like it's shaping up to be a big conflict :-(
I paused reviewing your series to post this one, because "I'd really like that to go in for this release" :)
Quoted 7 lines
My series touches 21 existing commented definitions in qapi/, six more in
tests/qapi-schema/doc-good.json, and adds new moduleqapi/compat.json. Consolidated diff appended.Rule of thumb for reducing conflict resolution labor: the bigger manual change goes first. Yours is bigger, but I don't remember how manual it is.
We got pretty much all the manual changes I needed into master already, so all that's left really is the script parts. The conflicts would basically be where this series affects the generate-docs parts of the scripts -- any changes here to doc.py are basically dead-code-walking and would need to be done over again in the equivalent code for rust generation. But looking at the diffstat
scripts/qapi/doc.py | 16 +-
so hopefully it won't be too bad.
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 9 lines · Markus Armbruster
Quoted 4 lines · Peter Maydell
How much do you think this is likely to affect the generate-rst-from-qapi-docs series? I'd really like that to go in for this release, but this looks like it's shaping up to be a big conflict :-(
I paused reviewing your series to post this one, because "I'd really like that to go in for this release" :)
Quoted 7 lines
My series touches 21 existing commented definitions in qapi/, six more in
tests/qapi-schema/doc-good.json, and adds new moduleqapi/compat.json. Consolidated diff appended.Rule of thumb for reducing conflict resolution labor: the bigger manual change goes first. Yours is bigger, but I don't remember how manual it is.
We got pretty much all the manual changes I needed into master already, so all that's left really is the script parts. The conflicts would basically be where this series affects the generate-docs parts of the scripts -- any changes here to
doc.pyare basically dead-code-walking and would need to be done over again in the equivalent code for rust generation. But looking at the diffstat
Quoted 2 lines
scripts/qapi/doc.py | 16 +-so hopefully it won't be too bad.
Not bad at all: two patches, both trivial for this file:
$ git-log --patch master..posted/qapi-features scripts/qapi/doc.py commit 63daae3c1da9a7d8a189a9dfc80804c812b3f6af Author: Markus Armbruster <[email protected]> Date: Fri Oct 18 11:23:40 2019 +0200
qapi: Consistently put @features parameter right after @ifcond
scripts/qapi/doc.py +5 -5
@@ -249,8 +249,8 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_members(doc, 'Values', member_func=texi_enum_value))) - def visit_object_type(self, name, info, ifcond, base, members, variants, - features): + def visit_object_type(self, name, info, ifcond, features, + base, members, variants): doc = self.cur_doc if base and base.is_implicit(): base = None
@@ -262,9 +262,9 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members'))) - def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, - success_response, boxed, allow_oob, allow_preconfig, - features): + def visit_command(self, name, info, ifcond, features, + arg_type, ret_type, gen, success_response, boxed, + allow_oob, allow_preconfig): doc = self.cur_doc self._gen.add(texi_msg('Command', doc, ifcond, texi_arguments(doc,
commit 9e101e2b1803f326df46e42d88bae9f281da9fe4
Author: Markus Armbruster <[email protected]> Date: Tue Oct 15 14:33:24 2019 +0200
qapi: Add feature flags to remaining definitions
In v4.1.0, we added feature flags just to struct types (commit 6a8c0b5102^..f3ed93d545), to satisfy an immediate need (commit c9d4070991 "file-posix: Add dynamic-auto-read-only QAPI feature"). In v4.2.0, we added them to commands (commit 23394b4c39 "qapi: Add feature flags to commands") to satisfy another immediate need (commit d76744e65e "qapi: Allow introspecting fix for savevm's cooperation with blockdev").
Add them to the remaining definitions: enumeration types, union types, alternate types, and events.
scripts/qapi/doc.py +3 -3
@@ -243,7 +243,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): def write(self, output_dir): self._gen.write(output_dir) - def visit_enum_type(self, name, info, ifcond, members, prefix): + def visit_enum_type(self, name, info, ifcond, features, members, prefix): doc = self.cur_doc self._gen.add(texi_type('Enum', doc, ifcond, texi_members(doc, 'Values',
@@ -257,7 +257,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): self._gen.add(texi_type('Object', doc, ifcond, texi_members(doc, 'Members', base, variants))) - def visit_alternate_type(self, name, info, ifcond, variants): + def visit_alternate_type(self, name, info, ifcond, features, variants): doc = self.cur_doc self._gen.add(texi_type('Alternate', doc, ifcond, texi_members(doc, 'Members')))
@@ -270,7 +270,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): texi_arguments(doc, arg_type if boxed else None))) - def visit_event(self, name, info, ifcond, arg_type, boxed): + def visit_event(self, name, info, ifcond, features, arg_type, boxed): doc = self.cur_doc self._gen.add(texi_msg('Event', doc, ifcond, texi_arguments(doc,
Quoted 6 lines · Markus Armbruster
Based-on: <[email protected]>
This series extends QMP introspection to cover deprecation. Additionally, new option -compat lets you configure what to do when deprecated interfaces get used. This is intended for testing users of the management interfaces. It is experimental.
I've quickly hacked up support for the 'deprecated' feature in libvirt's QMP validator. I've found a few uses of deprecated commands but they might very well be in code paths that are no longer invoked in modern qemus:
Offenders from qemumonitorjsontest:
44) qemuMonitorJSONSetCPU ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'cpu-add': failed to validate arguments of 'cpu-add' against QAPI schema: ERROR: 'cpu-add' is deprecated
FAILED
46) qemuMonitorJSONChangeMedia ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'change': failed to validate arguments of 'change' against QAPI schema: ERROR: 'change' is deprecated
FAILED
49) qemuMonitorJSONSetMigrationSpeed ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'migrate_set_speed': failed to validate arguments of 'migrate_set_speed' against QAPI schema: ERROR: 'migrate_set_speed' is deprecated
FAILED
50) qemuMonitorJSONSetMigrationDowntime ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'migrate_set_downtime': failed to validate arguments of 'migrate_set_downtime' against QAPI schema: ERROR: 'migrate_set_downtime' is deprecated
FAILED
77) qemuMonitorJSONGetMigrationCacheSize ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-migrate-cache-size': failed to validate arguments of 'query-migrate-cache-size' against QAPI schema: ERROR: 'query-migrate-cache-size' is deprecated
FAILED
83) qemuMonitorJSONQueryCPUs ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
93) GetCPUInfo(x86-basic-pluggable) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
94) GetCPUInfo(x86-full) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
95) GetCPUInfo(x86-node-full) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
97) GetCPUInfo(ppc64-basic) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
98) GetCPUInfo(ppc64-hotplug-1) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
99) GetCPUInfo(ppc64-hotplug-2) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
100) GetCPUInfo(ppc64-hotplug-4) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
101) GetCPUInfo(ppc64-no-threads) ... libvirt: QEMU Driver error : internal error: unable to execute QEMU command 'query-cpus': failed to validate arguments of 'query-cpus' against QAPI schema: ERROR: 'query-cpus' is deprecated
FAILED
Here all commands are tested just for legacy reasons. query-cpus-fast is used on any live codebase, cpu-add is no longer used, change is not used with -blockdev. I'm not sure about the migration parameter APIs but I didn't check either.
The above shows that we can't enable this without thinking even in our test-suite.
I'll try to come up with a solution where we can enable the reporting of use of deprecated commands through /etc/qemu.conf so that I as an developer can always use it.
I'm currently busy but I plan to follow up later.
I've pushed the test change here:
https://gitlab.com/pipo.sk/libvirt/-/commits/qmp-deprecated
The unfortunate part is that we'll need to manually inspect the codebase for any deprecation in returned values. Our parser is 'artisanaly handcrafted' so it can't be introspected.
Quoted 14 lines · Markus Armbruster
Based-on: <[email protected]>
This series extends QMP introspection to cover deprecation. Additionally, new option -compat lets you configure what to do when deprecated interfaces get used. This is intended for testing users of the management interfaces. It is experimental.
-compat deprecated-input=<in-policy> configures what to do when deprecated input is received. Available policies:
* accept: Accept deprecated commands and arguments (default)
* reject: Reject them
* crash: Crash
Quoted 5 lines
-compat deprecated-output=<out-policy> configures what to do when deprecated output is sent. Available output policies:
* accept: Emit deprecated command results and events (default)
* hide: Suppress them
Missing: hide in output of query-qmp-schema. I can look into that.
Quoted 23 lines
For now, -compat covers only deprecated syntactic aspects of QMP. We may want to extend it to cover semantic aspects, CLI, and experimental features.
PATCH 01-04: Documentation fixes
PATCH 05-10: Test improvements
PATCH 11-24: Add feature flags to remaining user-defined types and to
struct members
PATCH 25-26: New special feature 'deprecated', visible in
introspection
PATCH 27-30: New -compat to set policy for handling stuff marked with
feature 'deprecated'Comparison to RFC (24 Oct 2019):
* Cover arguments and results in addition to commands and events
* Half-baked "[RFC PATCH 18/19] qapi: Include a warning in the response to a deprecated command" droppedSee also last item of
Subject: Minutes of KVM Forum BoF on deprecating stuff Date: Fri, 26 Oct 2018 16:03:51 +0200 Message-ID: <[email protected]> https://lists.nongnu.org/archive/html/qemu-devel/2018-10/msg05828.html