From 91fa93e516d080d440ead2ad4f88960545bd5b2c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 18 Mar 2021 16:55:11 +0100 Subject: qapi: Implement deprecated-output=hide for QMP command results This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP command results. Example: when QEMU is run with -compat deprecated-output=hide, then {"execute": "query-cpus-fast"} yields {"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"}]} instead of {"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]} Note the suppression of deprecated member "arch". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210318155519.1224118-4-armbru@redhat.com> --- scripts/qapi/commands.py | 4 ++-- scripts/qapi/visit.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 0a75a93..b7e577a 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -96,7 +96,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, { Visitor *v; - v = qobject_output_visitor_new(ret_out); + v = qobject_output_visitor_new_qmp(ret_out); if (visit_type_%(c_name)s(v, "unused", &ret_in, errp)) { visit_complete(v, ret_out); } @@ -251,9 +251,9 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' #include "qemu/osdep.h" +#include "qapi/compat-policy.h" #include "qapi/visitor.h" #include "qapi/qmp/qdict.h" -#include "qapi/qobject-output-visitor.h" #include "qapi/qobject-input-visitor.h" #include "qapi/dealloc-visitor.h" #include "qapi/error.h" diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 9aa0b1e..9d83bf6 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -77,6 +77,7 @@ bool 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(''' @@ -84,6 +85,12 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ''', name=memb.name, c_name=c_name(memb.name)) indent.increase() + if deprecated: + ret += mcgen(''' + if (visit_deprecated(v, "%(name)s")) { +''', + name=memb.name) + indent.increase() ret += mcgen(''' if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) { return false; @@ -91,6 +98,11 @@ bool 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: + indent.decrease() + ret += mcgen(''' + } +''') if memb.optional: indent.decrease() ret += mcgen(''' -- cgit v1.1 From 278fc2f7d3425dfbc6aa91644bffc65e94afad7c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 18 Mar 2021 16:55:12 +0100 Subject: qapi: Implement deprecated-output=hide for QMP events This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP events: suppress deprecated ones. No QMP event is deprecated right now. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210318155519.1224118-5-armbru@redhat.com> --- scripts/qapi/events.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 90d2f61..f6e1e76 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -79,6 +79,7 @@ def gen_param_var(typ: QAPISchemaObjectType) -> str: def gen_event_send(name: str, arg_type: Optional[QAPISchemaObjectType], + features: List[QAPISchemaFeature], boxed: bool, event_enum_name: str, event_emit: str) -> str: @@ -107,6 +108,14 @@ def gen_event_send(name: str, 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"); @@ -176,6 +185,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" @@ -220,7 +230,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); boxed: bool) -> None: 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 -- cgit v1.1 From a291a38fa1db6a67bd9046da26a48e82c591ca49 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 18 Mar 2021 16:55:13 +0100 Subject: qapi: Implement deprecated-output=hide for QMP event data This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP event data: suppress deprecated members. No QMP event data is deprecated right now. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210318155519.1224118-6-armbru@redhat.com> --- scripts/qapi/events.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index f6e1e76..fee8c67 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -126,7 +126,7 @@ def gen_event_send(name: str, if have_args: assert arg_type is not None ret += mcgen(''' - v = qobject_output_visitor_new(&obj); + v = qobject_output_visitor_new_qmp(&obj); ''') if not arg_type.is_implicit(): ret += mcgen(''' @@ -145,7 +145,11 @@ def gen_event_send(name: str, ret += mcgen(''' visit_complete(v, &obj); - qdict_put_obj(qmp, "data", obj); + if (qdict_size(qobject_to(QDict, obj))) { + qdict_put_obj(qmp, "data", obj); + } else { + qobject_unref(obj); + } ''') ret += mcgen(''' @@ -188,7 +192,6 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): #include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" -#include "qapi/qobject-output-visitor.h" #include "qapi/qmp-event.h" ''', -- cgit v1.1 From d2032598c434fe385145ee6ea58007a19ef7e723 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 18 Mar 2021 16:55:17 +0100 Subject: qapi: Implement deprecated-input=reject for QMP commands This policy rejects deprecated input, and thus permits "testing the future". Implement it for QMP commands: make deprecated ones fail. Example: when QEMU is run with -compat deprecated-input=reject, then {"execute": "query-cpus"} fails like this {"error": {"class": "CommandNotFound", "desc": "Deprecated command query-cpus disabled by policy"}} When the deprecated command is removed, the error will change to {"error": {"class": "CommandNotFound", "desc": "The command query-cpus has not been found"}} Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210318155519.1224118-10-armbru@redhat.com> --- scripts/qapi/commands.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index b7e577a..c462851 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -210,12 +210,16 @@ out: def gen_register_command(name: str, + features: List[QAPISchemaFeature], success_response: bool, allow_oob: bool, allow_preconfig: bool, coroutine: bool) -> str: 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: @@ -326,9 +330,9 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) with self._temp_module('./init'): with ifcontext(ifcond, self._genh, self._genc): - self._genc.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig, - coroutine)) + self._genc.add(gen_register_command( + name, features, success_response, allow_oob, + allow_preconfig, coroutine)) def gen_commands(schema: QAPISchema, -- cgit v1.1 From db29164103e53ae7c112086127e3d1c92b1d4d89 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 18 Mar 2021 16:55:18 +0100 Subject: qapi: Implement deprecated-input=reject for QMP command arguments This policy rejects deprecated input, and thus permits "testing the future". Implement it for QMP command arguments: reject commands with deprecated ones. Example: when QEMU is run with -compat deprecated-input=reject, then {"execute": "eject", "arguments": {"device": "cd"}} fails like this {"error": {"class": "GenericError", "desc": "Deprecated parameter 'device' disabled by policy"}} When the deprecated parameter is removed, the error will change to {"error": {"class": "GenericError", "desc": "Parameter 'device' is unexpected"}} Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20210318155519.1224118-11-armbru@redhat.com> --- scripts/qapi/commands.py | 3 +-- scripts/qapi/visit.py | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index c462851..0e13d51 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -154,7 +154,7 @@ def gen_marshal(name: str, ret += mcgen(''' - v = qobject_input_visitor_new(QOBJECT(args)); + v = qobject_input_visitor_new_qmp(QOBJECT(args)); if (!visit_start_struct(v, NULL, NULL, 0, errp)) { goto out; } @@ -258,7 +258,6 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): #include "qapi/compat-policy.h" #include "qapi/visitor.h" #include "qapi/qmp/qdict.h" -#include "qapi/qobject-input-visitor.h" #include "qapi/dealloc-visitor.h" #include "qapi/error.h" #include "%(visit)s.h" diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 9d83bf6..9e96f3c 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -87,6 +87,9 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) indent.increase() if deprecated: ret += mcgen(''' + if (!visit_deprecated_accept(v, "%(name)s", errp)) { + return false; + } if (visit_deprecated(v, "%(name)s")) { ''', name=memb.name) -- cgit v1.1