Configurable policy for handling deprecated interfaces
v6 cover Configurable policy for handling deprecated interfaces
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.
v6:
* Rebased, with straightforward conflicts
* PATCH 1: More verbose commit message, explaining intent, and the lack of introspection [Peter], comments updated for 6.0, Eric's R-by kept anyway
* PATCH 5+6: Split old PATCH 5 [Eric], Eric's R-by lept anyway
* PATCH 7: New, correcting a latent issue so it doesn't break PATCH 8
* PATCH 10: Doc fix [Eric]
v5:
* Old PATCH 01-26 merged in commit f57587c7d47.
* Rebased, non-trivial conflicts in PATCH 1 due to Meson, and in PATCH 7 due to visitor changes
* PATCH 1: Comments updated for 5.2 [Eric]
* PATCH 2: Harmless missing initialization fixed [Eric]
* PATCH 3+4: Harmless missing has_FOO = true fixed [Eric]
* PATCH 6+7: Commit message tweaked
v4:
* PATCH 05+07: Temporary memory leak plugged [Marc-André]
* PATCH 23: Rewritten [Marc-André]
* PATCH 24: Comment typo [Marc-André]
* PATCH 30: Memory leaks plugged
v3:
* Rebased, non-trivial conflicts in PATCH 01+26+27+34 due to RST conversion and code motion
* PATCH 28-29: Old PATCH 28 split up to ease review
* PATCH 30-31: New
* PATCH 32-33: Old PATCH 29 split up to ease review
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 (10):
qemu-options: New -compat to set policy for deprecated interfaces
qapi: Implement deprecated-output=hide for QMP command results
qapi: Implement deprecated-output=hide for QMP events
qapi: Implement deprecated-output=hide for QMP event data
monitor: Drop query-qmp-schema 'gen': false hack
qapi: Implement deprecated-output=hide for QMP introspection
test-util-sockets: Add stub for monitor_set_cur()
qapi: Implement deprecated-input=reject for QMP commands
qapi: Implement deprecated-input=reject for QMP command arguments
qapi: New -compat deprecated-input=crash
qapi/compat.json | 52 ++++++++++++ qapi/introspect.json | 2 +- 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 | 6 ++ include/qapi/visitor.h | 18 +++++ monitor/monitor-internal.h | 3 - monitor/misc.c | 2 - monitor/qmp-cmds-control.c | 100 +++++++++++++++++++++--- qapi/qapi-visit-core.c | 18 +++++ qapi/qmp-dispatch.c | 17 ++++ qapi/qobject-input-visitor.c | 29 +++++++ qapi/qobject-output-visitor.c | 19 +++++ softmmu/vl.c | 17 ++++ storage-daemon/qemu-storage-daemon.c | 2 - tests/test-qmp-cmds.c | 91 +++++++++++++++++++-- tests/test-qmp-event.c | 41 ++++++++++ tests/test-util-sockets.c | 1 + qapi/meson.build | 1 + qapi/trace-events | 2 + qemu-options.hx | 22 ++++++ scripts/qapi/commands.py | 14 ++-- scripts/qapi/events.py | 20 ++++- scripts/qapi/visit.py | 15 ++++ tests/qapi-schema/qapi-schema-test.json | 20 +++-- tests/qapi-schema/qapi-schema-test.out | 20 ++--- 29 files changed, 522 insertions(+), 50 deletions(-) create mode 100644 qapi/compat.json create mode 100644 include/qapi/compat-policy.h
Signature · 1 line
2.26.2
PATCH v6 1/10 qemu-options: New -compat to set policy for deprecated interfaces
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=<input-policy> configures what to do when deprecated input is received. Input policy can be "accept" (accept silently), or "reject" (reject the request with an error).
-compat deprecated-output=<out-policy> configures what to do when deprecated output is sent. 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.
Note that there is no good way for management application to detect presence of -compat: it's not visible output of query-qmp-schema or query-command-line-options. Tolerable, because it's meant for testing. If running with -compat fails, skip the test.
--- 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/meson.build | 1 + qemu-options.hx | 20 ++++++++++++++ 7 files changed, 113 insertions(+) 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.2 +## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept', 'reject' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# @hide: Filter out +# +# Since: 5.2 +## +{ '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.2 +## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } }
qapi/qapi-schema.json +1 -0
@@ -79,6 +79,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) 2020 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
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include "block/aio.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h"
@@ -23,6 +24,8 @@#include "qemu/coroutine.h" #include "qemu/main-loop.h" +CompatPolicy compat_policy; +static QDict *qmp_dispatch_check_obj (QDict *dict,bool allow_oob,Error **errp) {
softmmu/vl.c +17 -0
@@ -29,6 +29,7 @@#include "exec/cpu-common.h" #include "hw/boards.h" #include "hw/qdev-properties.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qemu-version.h"
@@ -113,6 +114,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-migration.h"
@@ -3413,6 +3415,21 @@ void qemu_init(int argc, char **argv, char **envp) enable_mlock =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/meson.build +1 -0
@@ -24,6 +24,7 @@ qapi_all_modules = [ 'block-export', 'char', 'common', + 'compat', 'control', 'crypto', 'dump',
qemu-options.hx +20 -0
@@ -3470,6 +3470,26 @@ DEFHEADING() DEFHEADING(Debug/Expert options:) +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) +SRST +``-compat [deprecated-input=@var{input-policy}][,deprecated-output=@var{output-policy}]`` + Set policy for handling deprecated management interfaces (experimental): + + ``deprecated-input=accept`` (default) + Accept deprecated commands and arguments + ``deprecated-input=reject`` + Reject deprecated commands and arguments + ``deprecated-output=accept`` (default) + Emit deprecated command results and events + ``deprecated-output=hide`` + Suppress deprecated command results and events + + Limitation: covers only syntactic aspects of QMP. +ERST + 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.26.2
Re: [PATCH v6 01/10] qemu-options: New -compat to set policy for deprecated interfaces
Quoted 35 lines · Markus Armbruster
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=<input-policy> configures what to do when deprecated input is received. Input policy can be "accept" (accept silently), or "reject" (reject the request with an error).
-compat deprecated-output=<out-policy> configures what to do when deprecated output is sent. 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.
Note that there is no good way for management application to detect presence of -compat: it's not visible output of query-qmp-schema or query-command-line-options. Tolerable, because it's meant for testing. If running with -compat fails, skip the test.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>---
+++
b/qapi/compat.jsonqapi/compat.json new file +5
-0@@ -0,0 +1,51 @@ +# -*- Mode: Python -*- + +## +# = Compatibility policy +##
qapi/compat.json line 15
Quoted 10 lines
qapi/compat.json new file +10
-0+ +## +# @CompatPolicyInput: +# +# Policy for handling "funny" input. +# +# @accept: Accept silently +# @reject: Reject with an error +# +# Since: 5.2
6.0
qapi/compat.json line 28
Quoted 13 lines
qapi/compat.json new file +13
-0+## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept', 'reject' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# @hide: Filter out +# +# Since: 5.2
and here
Quoted 9 lines
qapi/compat.json new file +9
-0+## +{ 'enum': 'CompatPolicyOutput', + 'data': [ 'accept', 'hide' ] } + +## +# @CompatPolicy: +# +# Policy for handling deprecated management interfaces. +#
qapi/compat.json line 47
Quoted 10 lines
qapi/compat.json new file +10
-0+# 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.2
and here
qapi/qapi-schema.json
Quoted 6 lines
qapi/compat.json new file +4
-0+## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } }qapi/qapi-schema.json +0
-0
R-b still stands once you make the necessary tweaks.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v6 01/10] qemu-options: New -compat to set policy for deprecated interfaces
Quoted 87 lines · Eric Blake
Quoted 35 lines · Markus Armbruster
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=<input-policy> configures what to do when deprecated input is received. Input policy can be "accept" (accept silently), or "reject" (reject the request with an error).
-compat deprecated-output=<out-policy> configures what to do when deprecated output is sent. 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.
Note that there is no good way for management application to detect presence of -compat: it's not visible output of query-qmp-schema or query-command-line-options. Tolerable, because it's meant for testing. If running with -compat fails, skip the test.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>---
+++
b/qapi/compat.jsonqapi/compat.json new file +5
-0@@ -0,0 +1,51 @@ +# -*- Mode: Python -*- + +## +# = Compatibility policy +##qapi/compat.json line 15
Quoted 10 lines
qapi/compat.json new file +10
-0+ +## +# @CompatPolicyInput: +# +# Policy for handling "funny" input. +# +# @accept: Accept silently +# @reject: Reject with an error +# +# Since: 5.26.0
qapi/compat.json line 28
Quoted 13 lines
qapi/compat.json new file +13
-0+## +{ 'enum': 'CompatPolicyInput', + 'data': [ 'accept', 'reject' ] } + +## +# @CompatPolicyOutput: +# +# Policy for handling "funny" output. +# +# @accept: Pass on unchanged +# @hide: Filter out +# +# Since: 5.2and here
Quoted 9 lines
qapi/compat.json new file +9
-0+## +{ 'enum': 'CompatPolicyOutput', + 'data': [ 'accept', 'hide' ] } + +## +# @CompatPolicy: +# +# Policy for handling deprecated management interfaces. +#qapi/compat.json line 47
Quoted 10 lines
qapi/compat.json new file +10
-0+# 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.2and here
Quoted 8 lines
qapi/qapi-schema.json
Quoted 6 lines
qapi/compat.json new file +4
-0+## +{ 'struct': 'CompatPolicy', + 'data': { '*deprecated-input': 'CompatPolicyInput', + '*deprecated-output': 'CompatPolicyOutput' } }qapi/qapi-schema.json +0
-0R-b still stands once you make the necessary tweaks.
I thought I had updated these... Thanks for catching my mistake!
PATCH v6 2/10 qapi: Implement deprecated-output=hide for QMP command results
In reply to Markus ArmbrusterThis 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".
--- 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 ++++++++++++++++++++++--- qapi/trace-events | 1 + scripts/qapi/commands.py | 2 +- scripts/qapi/visit.py | 12 +++++++ tests/qapi-schema/qapi-schema-test.json | 17 +++++----- tests/qapi-schema/qapi-schema-test.out | 18 +++++------ 11 files changed, 118 insertions(+), 23 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
@@ -113,6 +113,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
@@ -459,6 +459,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
@@ -135,6 +135,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 */
@@ -207,6 +210,13 @@ static bool qobject_output_type_null(Visitor *v, const char *name,return true; } +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. */
@@ -256,6 +266,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;
@@ -264,3 +275,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
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
@@ -96,7 +96,7 @@ def gen_marshal_output(ret_type: QAPISchemaType) -> str: { 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); }
scripts/qapi/visit.py +12 -0
@@ -77,6 +77,7 @@ def gen_visit_object_members(name: str, 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 @@ def gen_visit_object_members(name: str, ''', 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 @@ def gen_visit_object_members(name: str, ''', 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('''
tests/qapi-schema/qapi-schema-test.json +9 -8
@@ -299,14 +299,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
@@ -409,15 +409,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.26.2
Re: [PATCH v6 02/10] qapi: Implement deprecated-output=hide for QMP command results
Quoted 6 lines · Markus Armbruster
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"}
Quoted 7 lines
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"}]}
Example may not be relevant much longer, given Dan's patch [1] to make this permanent since we've already passed the deprecation wait. Up to you if you want to choose a different example.
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg07564.html
Quoted 6 lines
Note the suppression of deprecated member "arch".
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>---
R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v6 02/10] qapi: Implement deprecated-output=hide for QMP command results
Quoted 13 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
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
Quoted 7 lines
Quoted 1 line
{"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"}]}Example may not be relevant much longer, given Dan's patch [1] to make this permanent since we've already passed the deprecation wait. Up to you if you want to choose a different example.
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg07564.html
I think I'll keep this one just to save me some time. Even a slightly outdated example should serve okay as illustration.
Quoted 9 lines
Quoted 7 lines
Note the suppression of deprecated member "arch".
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>---
R-b still stands.
Thanks!
Re: [PATCH v6 02/10] qapi: Implement deprecated-output=hide for QMP command results
In reply to Markus ArmbrusterQuoted 19 lines · Markus Armbruster
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 <[email protected]>Reviewed-by Eric Blake <[email protected]>---
[...]
Quoted 4 lines
qapi/qobject-output-visitor.c +0
-0
[...]
qapi/qobject-output-visitor.c Visitor *qobject_output_visitor_new(QObject **result) · line 285
Quoted 12 lines
qapi/qobject-output-visitor.c +8
-0@@ -264,3 +275,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; +}
Linking fail when we link qapi/qobject-output-visitor.o (which uses @compat_policy), but not qapi/qmp-dispatch.o (which defines it).
Fails for me when I configure --disable-system --disable-tools.
Minimally invasive fix: move the function to qmp-dispatch.c.
Same for qobject_input_visitor_new_qmp() in PATCH 09.
[...]
PATCH v6 3/10 qapi: Implement deprecated-output=hide for QMP events
In reply to Markus ArmbrusterThis 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.
--- tests/test-qmp-event.c | 20 ++++++++++++++++++++ scripts/qapi/events.py | 12 +++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-)
tests/test-qmp-event.c +20 -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,24 @@ 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.has_deprecated_output = true; + 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 +167,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 ;
scripts/qapi/events.py +11 -1
@@ -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 @@ def _begin_user_module(self, name: str) -> None: #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 @@ def visit_event(self, 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
Signature · 1 line
2.26.2
PATCH v6 4/10 qapi: Implement deprecated-output=hide for QMP event data
In reply to Markus ArmbrusterThis 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.
--- tests/test-qmp-event.c | 21 +++++++++++++++++++++ scripts/qapi/events.py | 8 ++++++-- tests/qapi-schema/qapi-schema-test.json | 3 +++ tests/qapi-schema/qapi-schema-test.out | 2 ++ 4 files changed, 32 insertions(+), 2 deletions(-)
tests/test-qmp-event.c +21 -0
@@ -159,6 +159,26 @@ static void test_event_deprecated(TestEventData *data, const void *unused)qobject_unref (data->expect); } +static void test_event_deprecated_data (TestEventData *data,const void *unused) +{ +memset (&compat_policy,0 ,sizeof (compat_policy)); + + data->expect =qdict_from_jsonf_nofail ("{ 'event': 'TEST-EVENT-FEATURES0'," +" 'data': { 'foo': 42 } }" ); +qapi_event_send_test_event_features0 (42 ); +g_assert (data->emitted); + +qobject_unref (data->expect); + + compat_policy.has_deprecated_output = true; + compat_policy.deprecated_output =COMPAT_POLICY_OUTPUT_HIDE ; + data->expect =qdict_from_jsonf_nofail ("{ 'event': 'TEST-EVENT-FEATURES0' }" ); +qapi_event_send_test_event_features0 (42 ); +g_assert (data->emitted); + +qobject_unref (data->expect); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -168,6 +188,7 @@ int main(int argc, char **argv)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); +event_test_add ("/event/deprecated_data" , test_event_deprecated_data);g_test_run ();return 0 ;
scripts/qapi/events.py +6 -2
@@ -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('''
tests/qapi-schema/qapi-schema-test.json +3 -0
@@ -324,5 +324,8 @@ 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] } ] } +{ 'event': 'TEST-EVENT-FEATURES0', + 'data': 'FeatureStruct1' } + { 'event': 'TEST-EVENT-FEATURES1', 'features': [ 'deprecated' ] }
tests/qapi-schema/qapi-schema-test.out +2 -0
@@ -440,6 +440,8 @@ 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-FEATURES0 FeatureStruct1 + boxed=False event TEST-EVENT-FEATURES1 None boxed=False feature deprecated
Signature · 1 line
2.26.2
PATCH v6 5/10 monitor: Drop query-qmp-schema 'gen': false hack
In reply to Markus ArmbrusterQMP commands return their response as a generated QAPI type, which the monitor core converts to JSON via QObject.
query-qmp-schema's response is the generated introspection data. This is a QLitObject since commit 7d0f982bfb "qapi: generate a literal qobject for introspection", v2.12). Before, it was a string. Instead of converting QLitObject / string -> QObject -> QAPI type SchemaInfoList -> QObject -> JSON, we take a shortcut: the command is 'gen': false, so it can return the QObject instead of the QAPI type. Slightly simpler and more efficient.
The next commit will filter the response for output policy, and this is easier in the SchemaInfoList representation. Drop the shortcut.
This replaces the manual command registration by a generated one. The manual registration makes the commnd available before the machine is built by passing flag QCO_ALLOW_PRECONFIG. To keep it available there, we need need to add 'allow-preconfig': true to its definition in the schema.
--- qapi/introspect.json | 2 +- monitor/monitor-internal.h | 3 --- monitor/misc.c | 2 -- monitor/qmp-cmds-control.c | 29 ++++++++++++++++------------ storage-daemon/qemu-storage-daemon.c | 2 -- 5 files changed, 18 insertions(+), 20 deletions(-)
qapi/introspect.json +1 -1
@@ -49,7 +49,7 @@ ## { 'command': 'query-qmp-schema', 'returns': [ 'SchemaInfo' ], - 'gen': false } # just to simplify qmp_query_json() + 'allow-preconfig': true } ## # @SchemaMetaType:
monitor/monitor-internal.h +0 -3
@@ -183,7 +183,4 @@ void help_cmd(Monitor *mon, const char *name);void handle_hmp_command (MonitorHMP *mon,const char *cmdline);int hmp_compare_cmd (const char *name,const char *list); -void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data, -Error **errp); -#endif
monitor/misc.c +0 -2
@@ -231,8 +231,6 @@ static void monitor_init_qmp_commands(void)qmp_init_marshal (&qmp_commands); -qmp_register_command (&qmp_commands,"query-qmp-schema" , - qmp_query_qmp_schema,QCO_ALLOW_PRECONFIG );qmp_register_command (&qmp_commands,"device_add" , qmp_device_add,QCO_NO_OPTIONS ); qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
monitor/qmp-cmds-control.c +17 -12
@@ -26,10 +26,14 @@#include "monitor-internal.h" #include "qemu-version.h" +#include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-introspect.h" #include "qapi/qapi-emit-events.h" #include "qapi/qapi-introspect.h" +#include "qapi/qapi-visit-introspect.h" +#include "qapi/qobject-input-visitor.h" /* * Accept QMP capabilities in @list for @mon.
@@ -154,17 +158,18 @@ EventInfoList *qmp_query_events(Error **errp)return ev_list; } -/* -* Minor hack: generated marshalling suppressed for this command -* ('gen': false in the schema) so we can parse the JSON string -* directly into QObject instead of first parsing it with -* visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it -* to QObject with generated output marshallers, every time. Instead, -* we do it in test-qobject-input-visitor.c, just to make sure -* qapi-gen.py's output actually conforms to the schema. -*/ -void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data, -Error **errp) +SchemaInfoList *qmp_query_qmp_schema (Error **errp) { - *ret_data =qobject_from_qlit (&qmp_schema_qlit); +QObject *obj =qobject_from_qlit (&qmp_schema_qlit); +Visitor *v =qobject_input_visitor_new (obj); +SchemaInfoList *schema =NULL ; + +/* test_visitor_in_qmp_introspect() ensures this can't fail */ +visit_type_SchemaInfoList (v,NULL , &schema, &error_abort); +g_assert (schema); + +qobject_unref (obj); +visit_free (v); + +return schema; }
storage-daemon/qemu-storage-daemon.c +0 -2
@@ -146,8 +146,6 @@ static QemuOptsList qemu_object_opts = {static void init_qmp_commands (void ) {qmp_init_marshal (&qmp_commands); -qmp_register_command (&qmp_commands,"query-qmp-schema" , - qmp_query_qmp_schema,QCO_ALLOW_PRECONFIG );qmp_register_command (&qmp_commands,"object-add" , qmp_object_add,QCO_NO_OPTIONS );
Signature · 1 line
2.26.2
Re: [PATCH v6 05/10] monitor: Drop query-qmp-schema 'gen': false hack
Quoted 11 lines · Markus Armbruster
QMP commands return their response as a generated QAPI type, which the monitor core converts to JSON via QObject.
query-qmp-schema's response is the generated introspection data. This is a QLitObject since commit
7d0f982bfb"qapi: generate a literal qobject for introspection", v2.12). Before, it was a string. Instead of converting QLitObject / string -> QObject -> QAPI type SchemaInfoList -> QObject -> JSON, we take a shortcut: the command is 'gen': false, so it can return the QObject instead of the QAPI type. Slightly simpler and more efficient.
Quoted 5 lines
The next commit will filter the response for output policy, and this is easier in the SchemaInfoList representation. Drop the shortcut.
This replaces the manual command registration by a generated one. The manual registration makes the commnd available before the machine is
command
Quoted 6 lines
built by passing flag
QCO_ALLOW_PRECONFIG. To keep it available there, we need need to add 'allow-preconfig': true to its definition in the schema.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>
Quoted 8 lines
--- qapi/introspect.json | 2 +- monitor/monitor-internal.h | 3 --- monitor/misc.c | 2 -- monitor/qmp-cmds-control.c | 29 ++++++++++++++++------------ storage-daemon/qemu-storage-daemon.c | 2 -- 5 files changed, 18 insertions(+), 20 deletions(-)
R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v6 05/10] monitor: Drop query-qmp-schema 'gen': false hack
Quoted 12 lines · Eric Blake
Quoted 11 lines · Markus Armbruster
QMP commands return their response as a generated QAPI type, which the monitor core converts to JSON via QObject.
query-qmp-schema's response is the generated introspection data. This is a QLitObject since commit
7d0f982bfb"qapi: generate a literal qobject for introspection", v2.12). Before, it was a string. Instead of converting QLitObject / string -> QObject -> QAPI type SchemaInfoList -> QObject -> JSON, we take a shortcut: the command is 'gen': false, so it can return the QObject instead of the QAPI type. Slightly simpler and more efficient.
Quoted 7 lines
Quoted 5 lines
The next commit will filter the response for output policy, and this is easier in the SchemaInfoList representation. Drop the shortcut.
This replaces the manual command registration by a generated one. The manual registration makes the commnd available before the machine is
command
Fixing...
Quoted 15 lines
Quoted 6 lines
built by passing flag
QCO_ALLOW_PRECONFIG. To keep it available there, we need need to add 'allow-preconfig': true to its definition in the schema.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>Quoted 8 lines
--- qapi/introspect.json | 2 +- monitor/monitor-internal.h | 3 --- monitor/misc.c | 2 -- monitor/qmp-cmds-control.c | 29 ++++++++++++++++------------ storage-daemon/qemu-storage-daemon.c | 2 -- 5 files changed, 18 insertions(+), 20 deletions(-)
Quoted 1 line
R-b still stands.
Thanks!
PATCH v6 6/10 qapi: Implement deprecated-output=hide for QMP introspection
In reply to Markus ArmbrusterThis policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP command query-qmp-schema:
suppress information on deprecated commands, events and object type members, i.e. anything that has the special feature flag "deprecated".
--- monitor/qmp-cmds-control.c | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
monitor/qmp-cmds-control.c +71 -0
@@ -158,6 +158,74 @@ EventInfoList *qmp_query_events(Error **errp)return ev_list; } +static void *split_off_generic_list (void *list, +bool (*splitp)(void *elt), +void **part) +{ +GenericList *keep =NULL , **keep_tailp = &keep; +GenericList *split =NULL , **split_tailp = &split; +GenericList *tail; + +for (tail = list; tail; tail = tail->next) { +if (splitp (tail)) { + *split_tailp = tail; + split_tailp = &tail->next; + }else { + *keep_tailp = tail; + keep_tailp = &tail->next; + } + } + + *keep_tailp = *split_tailp =NULL ; + *part = split; +return keep; +} + +static bool is_in (const char *s,strList *list) +{ +strList *tail; + +for (tail = list; tail; tail = tail->next) { +if (!strcmp (tail->value, s)) { +return true; + } + } +return false; +} + +static bool is_entity_deprecated (void *link) +{ +return is_in ("deprecated" , ((SchemaInfoList *)link)->value->features); +} + +static bool is_member_deprecated (void *link) +{ +return is_in ("deprecated" , + ((SchemaInfoObjectMemberList *)link)->value->features); +} + +static SchemaInfoList *zap_deprecated (SchemaInfoList *schema) +{ +void *to_zap; +SchemaInfoList *tail; +SchemaInfo *ent; + + schema =split_off_generic_list (schema, is_entity_deprecated, &to_zap); +qapi_free_SchemaInfoList (to_zap); + +for (tail = schema; tail; tail = tail->next) { + ent = tail->value; +if (ent->meta_type ==SCHEMA_META_TYPE_OBJECT ) { + ent->u.object.members + =split_off_generic_list (ent->u.object.members, + is_member_deprecated, &to_zap); +qapi_free_SchemaInfoObjectMemberList (to_zap); + } + } + +return schema; +} +SchemaInfoList *qmp_query_qmp_schema (Error **errp) {QObject *obj =qobject_from_qlit (&qmp_schema_qlit);
@@ -171,5 +239,8 @@ SchemaInfoList *qmp_query_qmp_schema(Error **errp)qobject_unref (obj);visit_free (v); +if (compat_policy.deprecated_output ==COMPAT_POLICY_OUTPUT_HIDE ) { +return zap_deprecated (schema); + }return schema; }
Signature · 1 line
2.26.2
Re: [PATCH v6 06/10] qapi: Implement deprecated-output=hide for QMP introspection
Quoted 26 lines · Markus Armbruster
This policy suppresses deprecated bits in output, and thus permits "testing the future". Implement it for QMP command query-qmp-schema:
suppress information on deprecated commands, events and object type members, i.e. anything that has the special feature flag "deprecated".Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>--- monitor/qmp-cmds-control.c | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)monitor/qmp-cmds-control.c +7
-0@@ -158,6 +158,74 @@ EventInfoList *qmp_query_events(Error **errp)return ev_list; } +static void *split_off_generic_list (void *list, +bool (*splitp)(void *elt), +void **part) +{ +GenericList *keep =NULL , **keep_tailp = &keep; +GenericList *split =NULL , **split_tailp = &split; +GenericList *tail;
monitor/qmp-cmds-control.c EventInfoList *qmp_query_events(Error **errp) · line 177
Quoted 10 lines
monitor/qmp-cmds-control.c +10
-0+ +for (tail = list; tail; tail = tail->next) { +if (splitp (tail)) { + *split_tailp = tail; + split_tailp = &tail->next; + }else { + *keep_tailp = tail; + keep_tailp = &tail->next; + } + }
At first glance, I wondered if QAPI_LIST_APPEND would be better than open coding, but with a bit more thought, I agree that this particular case is best written as presented (you are manipulating two tail pointers in one iteration, which is different semantics than QAPI_LIST_APPEND advancing a single tail pointer).
R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v6 7/10 test-util-sockets: Add stub for monitor_set_cur()
In reply to Markus ArmbrusterWithout this stub, the next commit fails to link. I suspect the real cause is 947e47448d "monitor: Use getter/setter functions for cur_mon".
--- tests/test-util-sockets.c | 1 + 1 file changed, 1 insertion(+)
tests/test-util-sockets.c +1 -0
@@ -73,6 +73,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)* otherwise we get duplicate syms at link time. */ Monitor *monitor_cur (void ) {return cur_mon; } +Monitor *monitor_set_cur (Coroutine *co,Monitor *mon) {abort (); }int monitor_vprintf (Monitor *mon,const char *fmt,va_list ap) {abort (); }#ifndef _WIN32
Signature · 1 line
2.26.2
Re: [PATCH v6 07/10] test-util-sockets: Add stub for monitor_set_cur()
Quoted 9 lines · Markus Armbruster
Without this stub, the next commit fails to link. I suspect the real cause is
947e47448d"monitor: Use getter/setter functions forcur_mon".Cc Kevin Wolf <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- tests/test-util-sockets.c | 1 + 1 file changed, 1 insertion(+)
We may be able to clean this up later, but in the interest of getting this series into soft freeze,
Quoted 14 lines
tests/test-util-sockets.c +1
-0@@ -73,6 +73,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)* otherwise we get duplicate syms at link time. */ Monitor *monitor_cur (void ) {return cur_mon; } +Monitor *monitor_set_cur (Coroutine *co,Monitor *mon) {abort (); }int monitor_vprintf (Monitor *mon,const char *fmt,va_list ap) {abort (); }#ifndef _WIN32
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v6 8/10 qapi: Implement deprecated-input=reject for QMP commands
In reply to Markus ArmbrusterThis 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"}}--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 13 +++++++++++++ tests/test-qmp-cmds.c | 24 ++++++++++++++++++++++++ scripts/qapi/commands.py | 10 +++++++--- 4 files changed, 45 insertions(+), 3 deletions(-)
include/qapi/qmp/dispatch.h +1 -0
@@ -26,6 +26,7 @@ typedef enum QmpCommandOptionsQCO_ALLOW_OOB = (1U <<1 ),QCO_ALLOW_PRECONFIG = (1U <<2 ),QCO_COROUTINE = (1U <<3 ), +QCO_DEPRECATED = (1U <<4 ), } QmpCommandOptions; typedef struct QmpCommand
qapi/qmp-dispatch.c +13 -0
@@ -158,6 +158,19 @@ QDict *qmp_dispatch(const 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",
tests/test-qmp-cmds.c +24 -0
@@ -281,6 +281,28 @@ static void test_dispatch_cmd_io(void)qobject_unref (ret3); } +static void test_dispatch_cmd_deprecated (void ) +{ +const char *cmd ="{ 'execute': 'test-command-features1' }" ; +QDict *ret; + +memset (&compat_policy,0 ,sizeof (compat_policy)); + +/* accept */ + ret =qobject_to (QDict,do_qmp_dispatch (false, cmd)); +assert (ret &&qdict_size (ret) ==0 ); +qobject_unref (ret); + + compat_policy.has_deprecated_input = true; + compat_policy.deprecated_input =COMPAT_POLICY_INPUT_ACCEPT ; + ret =qobject_to (QDict,do_qmp_dispatch (false, cmd)); +assert (ret &&qdict_size (ret) ==0 ); +qobject_unref (ret); + + compat_policy.deprecated_input =COMPAT_POLICY_INPUT_REJECT ; +do_qmp_dispatch_error (false,ERROR_CLASS_COMMAND_NOT_FOUND , cmd); +} +static void test_dispatch_cmd_ret_deprecated (void ) {const char *cmd ="{ 'execute': 'test-features0' }" ;
@@ -379,6 +401,8 @@ int main(int argc, char **argv)g_test_add_func ("/qmp/dispatch_cmd_io" , test_dispatch_cmd_io);g_test_add_func ("/qmp/dispatch_cmd_success_response" , test_dispatch_cmd_success_response); +g_test_add_func ("/qmp/dispatch_cmd_deprecated" , + test_dispatch_cmd_deprecated);g_test_add_func ("/qmp/dispatch_cmd_ret_deprecated" , test_dispatch_cmd_ret_deprecated);g_test_add_func ("/qmp/dealloc_types" , test_dealloc_types);
scripts/qapi/commands.py +7 -3
@@ -210,12 +210,16 @@ def gen_marshal(name: str, 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 @@ def visit_command(self, 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,
Signature · 1 line
2.26.2
Re: [PATCH v6 08/10] qapi: Implement deprecated-input=reject for QMP commands
Quoted 6 lines · Markus Armbruster
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"}
Quoted 7 lines
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"}}
Again, Dan's patch changes this permanently:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg07566.html
Up to you if you want to tweak the example, but the concept of the patch is still fine, so my R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v6 9/10 qapi: Implement deprecated-input=reject for QMP command arguments
In reply to Markus ArmbrusterThis 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"}}--- include/qapi/qobject-input-visitor.h | 9 +++++++++ include/qapi/visitor-impl.h | 3 +++ include/qapi/visitor.h | 9 +++++++++ qapi/qapi-visit-core.c | 9 +++++++++ qapi/qobject-input-visitor.c | 28 ++++++++++++++++++++++++++++ tests/test-qmp-cmds.c | 25 +++++++++++++++++++++++++ qapi/trace-events | 1 + scripts/qapi/commands.py | 2 +- scripts/qapi/visit.py | 3 +++ 9 files changed, 88 insertions(+), 1 deletion(-)
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 +3 -0
@@ -113,6 +113,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_accept)(Visitor *v,const char *name,Error **errp); +/* Optional */ bool (*deprecated)(Visitor *v,const char *name);
include/qapi/visitor.h +9 -0
@@ -459,6 +459,15 @@ void visit_end_alternate(Visitor *v, void **obj);*/ bool visit_optional (Visitor *v,const char *name,bool *present); +/* +* Should we reject 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_accept (Visitor *v,const char *name,Error **errp); +/* * Should we visit deprecated member @name? *
qapi/qapi-visit-core.c +9 -0
@@ -135,6 +135,15 @@ bool visit_optional(Visitor *v, const char *name, bool *present)return *present; } +bool visit_deprecated_accept (Visitor *v,const char *name,Error **errp) +{ +trace_visit_deprecated_accept (v, name); +if (v->deprecated_accept) { +return v->deprecated_accept (v, name, errp); + } +return true; +} +bool visit_deprecated (Visitor *v,const char *name) {trace_visit_deprecated (v, name);
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;
@@ -662,6 +664,23 @@ static void qobject_input_optional(Visitor *v, const char *name, bool *present) *present = true; } +static bool qobject_input_deprecated_accept (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);
@@ -696,6 +715,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_accept = qobject_input_deprecated_accept; v->visitor.free = qobject_input_free; v->root =qobject_ref (obj);
@@ -718,6 +738,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);
tests/test-qmp-cmds.c +25 -0
@@ -303,6 +303,29 @@ static void test_dispatch_cmd_deprecated(void)do_qmp_dispatch_error (false,ERROR_CLASS_COMMAND_NOT_FOUND , cmd); } +static void test_dispatch_cmd_arg_deprecated (void ) +{ +const char *cmd ="{ 'execute': 'test-features0'," +" 'arguments': { 'fs1': { 'foo': 42 } } }" ; +QDict *ret; + +memset (&compat_policy,0 ,sizeof (compat_policy)); + +/* accept */ + ret =qobject_to (QDict,do_qmp_dispatch (false, cmd)); +assert (ret &&qdict_size (ret) ==1 ); +qobject_unref (ret); + + compat_policy.has_deprecated_input = true; + compat_policy.deprecated_input =COMPAT_POLICY_INPUT_ACCEPT ; + ret =qobject_to (QDict,do_qmp_dispatch (false, cmd)); +assert (ret &&qdict_size (ret) ==1 ); +qobject_unref (ret); + + compat_policy.deprecated_input =COMPAT_POLICY_INPUT_REJECT ; +do_qmp_dispatch_error (false,ERROR_CLASS_GENERIC_ERROR , cmd); +} +static void test_dispatch_cmd_ret_deprecated (void ) {const char *cmd ="{ 'execute': 'test-features0' }" ;
@@ -403,6 +426,8 @@ int main(int argc, char **argv) test_dispatch_cmd_success_response);g_test_add_func ("/qmp/dispatch_cmd_deprecated" , test_dispatch_cmd_deprecated); +g_test_add_func ("/qmp/dispatch_cmd_arg_deprecated" , + test_dispatch_cmd_arg_deprecated);g_test_add_func ("/qmp/dispatch_cmd_ret_deprecated" , test_dispatch_cmd_ret_deprecated);g_test_add_func ("/qmp/dealloc_types" , test_dealloc_types);
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_accept(void *v, const char *name) "v=%p name=%s" 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"
scripts/qapi/commands.py +1 -1
@@ -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; }
scripts/qapi/visit.py +3 -0
@@ -87,6 +87,9 @@ def gen_visit_object_members(name: str, 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)
Signature · 1 line
2.26.2
PATCH v6 10/10 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 | 9 +++++---- qapi/qmp-dispatch.c | 1 + qapi/qobject-input-visitor.c | 1 + qemu-options.hx | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-)
qapi/compat.json +5 -4
@@ -11,11 +11,12 @@ # # @accept: Accept silently # @reject: Reject with an error +# @crash: abort() the process # -# Since: 5.2 +# Since: 6.0 ## { 'enum': 'CompatPolicyInput', - 'data': [ 'accept', 'reject' ] } + 'data': [ 'accept', 'reject', 'crash' ] } ## # @CompatPolicyOutput:
@@ -25,7 +26,7 @@ # @accept: Pass on unchanged # @hide: Filter out # -# Since: 5.2 +# Since: 6.0 ## { 'enum': 'CompatPolicyOutput', 'data': [ 'accept', 'hide' ] }
@@ -44,7 +45,7 @@ # @deprecated-input: how to handle deprecated input (default 'accept') # @deprecated-output: how to handle deprecated output (default 'accept') # -# Since: 5.2 +# Since: 6.0 ## { 'struct': 'CompatPolicy', 'data': { '*deprecated-input': 'CompatPolicyInput',
qapi/qmp-dispatch.c +1 -0
@@ -167,6 +167,7 @@ QDict *qmp_dispatch(const 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
@@ -676,6 +676,7 @@ static bool qobject_input_deprecated_accept(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
@@ -3471,7 +3471,7 @@ DEFHEADING() DEFHEADING(Debug/Expert options:) 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) SRST
@@ -3482,6 +3482,8 @@ SRST Accept deprecated commands and arguments ``deprecated-input=reject`` Reject deprecated commands and arguments + ``deprecated-input=crash`` + Crash on deprecated commands and arguments ``deprecated-output=accept`` (default) Emit deprecated command results and events ``deprecated-output=hide``
Signature · 1 line
2.26.2
Re: [PATCH v6 10/10] qapi: New -compat deprecated-input=crash
Quoted 19 lines · Markus Armbruster
Policy "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.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>--- qapi/compat.json | 9 +++++---- qapi/qmp-dispatch.c | 1 + qapi/qobject-input-visitor.c | 1 + qemu-options.hx | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-)qapi/compat.json +0
-0
qapi/compat.json line 16
Quoted 7 lines
qapi/compat.json +2
-1@@ -11,11 +11,12 @@ # # @accept: Accept silently # @reject: Reject with an error +# @crash: abort() the process # -# Since: 5.2 +# Since: 6.0
Rebase churn once you fix this earlier in the series.
R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
This series needs fixups to not break --disable-system --disable-tools builds. It's not much (see appended diff), but enough to make me respin it as v7. I'll respin the pull request, too.
include/qapi/compat-policy.h +18 -0
@@ -17,4 +17,22 @@extern CompatPolicy compat_policy; +/* +* 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 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/qobject-input-visitor.h +3 -8
@@ -15,6 +15,7 @@#ifndef QOBJECT_INPUT_VISITOR_H #define QOBJECT_INPUT_VISITOR_H +#include "qapi/qapi-types-compat.h" #include "qapi/visitor.h" typedef struct QObjectInputVisitor QObjectInputVisitor ;
@@ -58,14 +59,8 @@ 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); +void qobject_input_visitor_set_policy (Visitor *v, +CompatPolicyInput deprecated);/* * Create a QObject input visitor for @obj for use with keyval_parse()
include/qapi/qobject-output-visitor.h +3 -8
@@ -15,6 +15,7 @@#define QOBJECT_OUTPUT_VISITOR_H #include "qapi/visitor.h" +#include "qapi/qapi-types-compat.h" typedef struct QObjectOutputVisitor QObjectOutputVisitor ;
@@ -53,13 +54,7 @@ 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); +void qobject_output_visitor_set_policy (Visitor *v, +CompatPolicyOutput deprecated);#endif
qapi/qmp-dispatch.c +18 -0
@@ -19,6 +19,8 @@#include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" #include "sysemu/runstate.h" #include "qapi/qmp/qbool.h" #include "qemu/coroutine.h"
@@ -26,6 +28,22 @@CompatPolicy compat_policy; +Visitor *qobject_input_visitor_new_qmp (QObject *obj) +{ +Visitor *v =qobject_input_visitor_new (obj); + +qobject_input_visitor_set_policy (v, compat_policy.deprecated_input); +return v; +} + +Visitor *qobject_output_visitor_new_qmp (QObject **result) +{ +Visitor *v =qobject_output_visitor_new (result); + +qobject_output_visitor_set_policy (v, compat_policy.deprecated_output); +return v; +} +static QDict *qmp_dispatch_check_obj (QDict *dict,bool allow_oob,Error **errp) {
qapi/qobject-input-visitor.c +4 -4
@@ -739,12 +739,12 @@ Visitor *qobject_input_visitor_new(QObject *obj)return &v->visitor; } -Visitor *qobject_input_visitor_new_qmp (QObject *obj) +void qobject_input_visitor_set_policy (Visitor *v, +CompatPolicyInput deprecated) { -QObjectInputVisitor *v =to_qiv (qobject_input_visitor_new (obj)); +QObjectInputVisitor *qiv =to_qiv (v); - v->deprecated_policy = compat_policy.deprecated_input; -return &v->visitor; + qiv->deprecated_policy = deprecated; }Visitor *qobject_input_visitor_new_keyval (QObject *obj)
qapi/qobject-output-visitor.c +4 -4
@@ -276,10 +276,10 @@ Visitor *qobject_output_visitor_new(QObject **result)return &v->visitor; } -Visitor *qobject_output_visitor_new_qmp (QObject **result) +void qobject_output_visitor_set_policy (Visitor *v, +CompatPolicyOutput deprecated) { -QObjectOutputVisitor *v =to_qov (qobject_output_visitor_new (result)); +QObjectOutputVisitor *qov =to_qov (v); - v->deprecated_policy = compat_policy.deprecated_output; -return &v->visitor; + qov->deprecated_policy = deprecated; }
scripts/qapi/commands.py +1 -2
@@ -255,10 +255,9 @@ def _begin_user_module(self, name: str) -> None: 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" #include "%(visit)s.h"
scripts/qapi/events.py +0 -1
@@ -192,7 +192,6 @@ def _begin_user_module(self, name: str) -> None: #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" ''',