qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [PULL 07/11] qapi: Implement deprecated-output=hide for QMP introspection
Date: Tue, 16 Mar 2021 18:05:47 +0100	[thread overview]
Message-ID: <20210316170551.3911643-8-armbru@redhat.com> (raw)
In-Reply-To: <20210316170551.3911643-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>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210312153210.2810514-7-armbru@redhat.com>
---
 monitor/qmp-cmds-control.c | 71 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 25afd0867f..bcfccc4ac4 100644
--- a/monitor/qmp-cmds-control.c
+++ b/monitor/qmp-cmds-control.c
@@ -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;
 }
-- 
2.26.2



  parent reply	other threads:[~2021-03-16 17:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 17:05 [PULL 00/11] QOM and fdc patches patches for 2021-03-16 Markus Armbruster
2021-03-16 17:05 ` [PULL 01/11] qemuutil: remove qemu_set_fd_handler duplicate symbol Markus Armbruster
2021-03-16 17:05 ` [PULL 02/11] qemu-options: New -compat to set policy for deprecated interfaces Markus Armbruster
2021-03-16 17:05 ` [PULL 03/11] qapi: Implement deprecated-output=hide for QMP command results Markus Armbruster
2021-03-16 17:05 ` [PULL 04/11] qapi: Implement deprecated-output=hide for QMP events Markus Armbruster
2021-03-16 17:05 ` [PULL 05/11] qapi: Implement deprecated-output=hide for QMP event data Markus Armbruster
2021-03-16 17:05 ` [PULL 06/11] monitor: Drop query-qmp-schema 'gen': false hack Markus Armbruster
2021-03-16 17:05 ` Markus Armbruster [this message]
2021-03-16 17:05 ` [PULL 08/11] test-util-sockets: Add stub for monitor_set_cur() Markus Armbruster
2021-03-16 17:05 ` [PULL 09/11] qapi: Implement deprecated-input=reject for QMP commands Markus Armbruster
2021-03-16 17:05 ` [PULL 10/11] qapi: Implement deprecated-input=reject for QMP command arguments Markus Armbruster
2021-03-16 17:05 ` [PULL 11/11] qapi: New -compat deprecated-input=crash Markus Armbruster
2021-03-16 17:19 ` [PULL 00/11] QOM and fdc patches patches for 2021-03-16 Markus Armbruster
  -- strict thread matches above, loose matches on Subject: below --
2021-03-16 16:52 Markus Armbruster
2021-03-16 16:52 ` [PULL 07/11] qapi: Implement deprecated-output=hide for QMP introspection Markus Armbruster
2021-03-16 10:32 [PULL 00/11] QAPI patches patches for 2021-03-16 Markus Armbruster
2021-03-16 10:33 ` [PULL 07/11] qapi: Implement deprecated-output=hide for QMP introspection 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=20210316170551.3911643-8-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).