aboutsummaryrefslogtreecommitdiff
path: root/monitor/qmp-cmds-control.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2021-03-18 16:55:14 +0100
committerMarkus Armbruster <armbru@redhat.com>2021-03-19 16:05:09 +0100
commit624fa80c8c199229af7ff42eb20b5b2ab851e4ee (patch)
tree77b132f8d37ed948dd864fd6bb5f698f5163628a /monitor/qmp-cmds-control.c
parenta291a38fa1db6a67bd9046da26a48e82c591ca49 (diff)
monitor: Drop query-qmp-schema 'gen': false hack
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. 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 command 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. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20210318155519.1224118-7-armbru@redhat.com>
Diffstat (limited to 'monitor/qmp-cmds-control.c')
-rw-r--r--monitor/qmp-cmds-control.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 513b547233..d152fd7e59 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.
@@ -130,17 +134,18 @@ CommandInfoList *qmp_query_commands(Error **errp)
return 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;
}