From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com
Subject: [PATCH v3 31/34] qapi: Implement deprecated-output=hide for QMP introspection
Date: Sun, 15 Mar 2020 15:46:50 +0100 [thread overview]
Message-ID: <20200315144653.22660-32-armbru@redhat.com> (raw)
In-Reply-To: <20200315144653.22660-1-armbru@redhat.com>
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 <armbru@redhat.com>
---
qapi/introspect.json | 2 +-
monitor/monitor-internal.h | 3 --
monitor/misc.c | 2 -
monitor/qmp-cmds-control.c | 102 ++++++++++++++++++++++++++++++++-----
qemu-storage-daemon.c | 2 -
5 files changed, 90 insertions(+), 21 deletions(-)
diff --git a/qapi/introspect.json b/qapi/introspect.json
index b1aabd4cfd..3ebd817866 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -48,7 +48,7 @@
##
{ 'command': 'query-qmp-schema',
'returns': [ 'SchemaInfo' ],
- 'gen': false } # just to simplify qmp_query_json()
+ 'allow-preconfig': true }
##
# @SchemaMetaType:
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 3e6baba88f..4d402ded85 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -180,7 +180,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
diff --git a/monitor/misc.c b/monitor/misc.c
index c3bc34c099..0237c71140 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -243,8 +243,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, "netdev_add", qmp_netdev_add,
diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 5cd9bb817c..bf5b711a7b 100644
--- a/monitor/qmp-cmds-control.c
+++ b/monitor/qmp-cmds-control.c
@@ -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.
@@ -153,17 +157,89 @@ 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)
-{
- *ret_data = qobject_from_qlit(&qmp_schema_qlit);
+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);
+ 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);
+
+ if (compat_policy.deprecated_output == COMPAT_POLICY_OUTPUT_HIDE) {
+ return zap_deprecated(schema);
+ }
+ return schema;
}
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index dd128978cc..23433090a8 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -142,8 +142,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);
QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
--
2.21.1
next prev parent reply other threads:[~2020-03-15 15:42 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-15 14:46 [PATCH v3 00/34] Configurable policy for handling deprecated interfaces Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 01/34] qemu-doc: Belatedly document QMP command arg & result deprecation Markus Armbruster
2020-03-16 15:10 ` Eric Blake
2020-03-16 18:34 ` Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 02/34] qapi: Belatedly update doc comment for @wait deprecation Markus Armbruster
2020-03-16 14:51 ` Marc-André Lureau
2020-03-16 15:10 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 03/34] docs/devel/qapi-code-gen: Clarify allow-oob introspection Markus Armbruster
2020-03-16 15:12 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 04/34] docs/devel/qapi-code-gen: Document 'features' introspection Markus Armbruster
2020-03-16 15:15 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 05/34] tests/test-qmp-cmds: Factor out qmp_dispatch() test helpers Markus Armbruster
2020-03-16 15:06 ` Marc-André Lureau
2020-03-16 19:46 ` Markus Armbruster
2020-03-16 17:16 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 06/34] tests/test-qmp-cmds: Check responses more thoroughly Markus Armbruster
2020-03-16 15:08 ` Marc-André Lureau
2020-03-16 17:18 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 07/34] tests/test-qmp-cmds: Simplify test data setup Markus Armbruster
2020-03-16 15:10 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 08/34] tests/test-qmp-event: " Markus Armbruster
2020-03-16 15:11 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 09/34] tests/test-qmp-event: Use qobject_is_equal() Markus Armbruster
2020-03-16 15:13 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 10/34] tests/test-qmp-event: Check event is actually emitted Markus Armbruster
2020-03-16 15:14 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 11/34] qapi/schema: Clean up around QAPISchemaEntity.connect_doc() Markus Armbruster
2020-03-16 16:47 ` Marc-André Lureau
2020-03-16 17:23 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 12/34] qapi: Add feature flags to remaining definitions Markus Armbruster
2020-03-16 17:55 ` Eric Blake
2020-03-17 5:46 ` Markus Armbruster
2020-03-17 11:29 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 13/34] qapi: Consistently put @features parameter right after @ifcond Markus Armbruster
2020-03-16 16:52 ` Marc-André Lureau
2020-03-16 17:57 ` Eric Blake
2020-03-15 14:46 ` [PATCH v3 14/34] qapi/introspect: Rename *qlit* to reduce confusion Markus Armbruster
2020-03-16 16:54 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 15/34] qapi/introspect: Factor out _make_tree() Markus Armbruster
2020-03-16 16:58 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 16/34] qapi/schema: Change _make_features() to a take feature list Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 17/34] qapi/schema: Reorder classes so related ones are together Markus Armbruster
2020-03-16 17:03 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 18/34] qapi/schema: Rename QAPISchemaObjectType{Variant, Variants} Markus Armbruster
2020-03-16 17:06 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 19/34] qapi/schema: Call QAPIDoc.connect_member() in just one place Markus Armbruster
2020-03-16 17:08 ` Marc-André Lureau
2020-03-16 17:08 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 20/34] qapi: Add feature flags to struct members Markus Armbruster
2020-03-16 17:10 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 21/34] qapi: Inline do_qmp_dispatch() into qmp_dispatch() Markus Armbruster
2020-03-16 17:25 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 22/34] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP Markus Armbruster
2020-03-16 17:28 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 23/34] qapi: Simplify how qmp_dispatch() gets the request ID Markus Armbruster
2020-03-16 17:33 ` Marc-André Lureau
2020-03-17 6:39 ` Markus Armbruster
2020-03-17 7:37 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 24/34] qapi: Replace qmp_dispatch()'s TODO comment by an explanation Markus Armbruster
2020-03-16 17:36 ` Marc-André Lureau
2020-03-17 6:52 ` Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 25/34] qapi: New special feature flag "deprecated" Markus Armbruster
2020-03-15 15:49 ` Philippe Mathieu-Daudé
2020-03-15 16:53 ` Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 26/34] qapi: Mark deprecated QMP parts with feature 'deprecated' Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 27/34] qemu-options: New -compat to set policy for deprecated interfaces Markus Armbruster
2020-03-16 17:43 ` Marc-André Lureau
2020-03-15 14:46 ` [PATCH v3 28/34] qapi: Implement deprecated-output=hide for QMP command results Markus Armbruster
2020-03-16 17:53 ` Marc-André Lureau
2020-03-16 19:46 ` Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 29/34] qapi: Implement deprecated-output=hide for QMP events Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 30/34] qapi: Implement deprecated-output=hide for QMP event data Markus Armbruster
2020-03-16 19:48 ` Markus Armbruster
2020-03-15 14:46 ` Markus Armbruster [this message]
2020-03-15 14:46 ` [PATCH v3 32/34] qapi: Implement deprecated-input=reject for QMP commands Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 33/34] qapi: Implement deprecated-input=reject for QMP command arguments Markus Armbruster
2020-03-15 14:46 ` [PATCH v3 34/34] qapi: New -compat deprecated-input=crash Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200315144653.22660-32-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).