[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/38] qapi/qom: QAPIfy object-add
From: |
Kevin Wolf |
Subject: |
[PULL 28/38] qapi/qom: QAPIfy object-add |
Date: |
Thu, 11 Mar 2021 15:48:01 +0100 |
This converts object-add from 'gen': false to the ObjectOptions QAPI
type. As an immediate benefit, clients can now use QAPI schema
introspection for user creatable QOM objects.
It is also the first step towards making the QAPI schema the only
external interface for the creation of user creatable objects. Once all
other places (HMP and command lines of the system emulator and all
tools) go through QAPI, too, some object implementations can be
simplified because some checks (e.g. that mandatory options are set) are
already performed by QAPI, and in another step, QOM boilerplate code
could be generated from the schema.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
qapi/qom.json | 11 +----------
include/qom/object_interfaces.h | 7 -------
hw/block/xen-block.c | 16 ++++++++--------
monitor/misc.c | 2 --
qom/qom-qmp-cmds.c | 25 +++++++++++++++++++++++--
storage-daemon/qemu-storage-daemon.c | 2 --
6 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/qapi/qom.json b/qapi/qom.json
index 192a582b07..2056edc072 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -846,13 +846,6 @@
#
# Create a QOM object.
#
-# @qom-type: the class name for the object to be created
-#
-# @id: the name of the new object
-#
-# Additional arguments depend on qom-type and are passed to the backend
-# unchanged.
-#
# Returns: Nothing on success
# Error if @qom-type is not a valid class name
#
@@ -866,9 +859,7 @@
# <- { "return": {} }
#
##
-{ 'command': 'object-add',
- 'data': {'qom-type': 'str', 'id': 'str'},
- 'gen': false } # so we can get the additional arguments
+{ 'command': 'object-add', 'data': 'ObjectOptions', 'boxed': true }
##
# @object-del:
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 07d5cc8832..9b9938b8c0 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -196,11 +196,4 @@ bool user_creatable_del(const char *id, Error **errp);
*/
void user_creatable_cleanup(void);
-/**
- * qmp_object_add:
- *
- * QMP command handler for object-add. See the QAPI schema for documentation.
- */
-void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp);
-
#endif
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index a3b69e2709..ac82d54063 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -836,17 +836,17 @@ static XenBlockIOThread *xen_block_iothread_create(const
char *id,
{
ERRP_GUARD();
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
- QDict *opts;
- QObject *ret_data = NULL;
+ ObjectOptions *opts;
iothread->id = g_strdup(id);
- opts = qdict_new();
- qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
- qdict_put_str(opts, "id", id);
- qmp_object_add(opts, &ret_data, errp);
- qobject_unref(opts);
- qobject_unref(ret_data);
+ opts = g_new(ObjectOptions, 1);
+ *opts = (ObjectOptions) {
+ .qom_type = OBJECT_TYPE_IOTHREAD,
+ .id = g_strdup(id),
+ };
+ qmp_object_add(opts, errp);
+ qapi_free_ObjectOptions(opts);
if (*errp) {
g_free(iothread->id);
diff --git a/monitor/misc.c b/monitor/misc.c
index a7650ed747..42efd9e2ab 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -235,8 +235,6 @@ static void monitor_init_qmp_commands(void)
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,
- QCO_NO_OPTIONS);
QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 19fd5e117f..e577a96adf 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -19,8 +19,11 @@
#include "qapi/error.h"
#include "qapi/qapi-commands-qdev.h"
#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-qom.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
+#include "qapi/qobject-input-visitor.h"
+#include "qapi/qobject-output-visitor.h"
#include "qemu/cutils.h"
#include "qom/object_interfaces.h"
#include "qom/qom-qobject.h"
@@ -223,9 +226,27 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char
*typename,
return prop_list;
}
-void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
+void qmp_object_add(ObjectOptions *options, Error **errp)
{
- user_creatable_add_dict(qdict, false, errp);
+ Visitor *v;
+ QObject *qobj;
+ QDict *props;
+ Object *obj;
+
+ v = qobject_output_visitor_new(&qobj);
+ visit_type_ObjectOptions(v, NULL, &options, &error_abort);
+ visit_complete(v, &qobj);
+ visit_free(v);
+
+ props = qobject_to(QDict, qobj);
+ qdict_del(props, "qom-type");
+ qdict_del(props, "id");
+
+ v = qobject_input_visitor_new(QOBJECT(props));
+ obj = user_creatable_add_type(ObjectType_str(options->qom_type),
+ options->id, props, v, errp);
+ object_unref(obj);
+ visit_free(v);
}
void qmp_object_del(const char *id, Error **errp)
diff --git a/storage-daemon/qemu-storage-daemon.c
b/storage-daemon/qemu-storage-daemon.c
index a39a22386a..a118f3abfb 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -148,8 +148,6 @@ 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);
QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
--
2.29.2
- [PULL 21/38] qapi/qom: Add ObjectOptions for can-*, (continued)
- [PULL 21/38] qapi/qom: Add ObjectOptions for can-*, Kevin Wolf, 2021/03/11
- [PULL 20/38] qapi/qom: Add ObjectOptions for tls-*, deprecate 'loaded', Kevin Wolf, 2021/03/11
- [PULL 24/38] qapi/qom: Add ObjectOptions for pr-manager-helper, Kevin Wolf, 2021/03/11
- [PULL 22/38] qapi/qom: Add ObjectOptions for colo-compare, Kevin Wolf, 2021/03/11
- [PULL 27/38] qapi/qom: Add ObjectOptions for x-remote-object, Kevin Wolf, 2021/03/11
- [PULL 23/38] qapi/qom: Add ObjectOptions for filter-*, Kevin Wolf, 2021/03/11
- [PULL 29/38] qom: Make "object" QemuOptsList optional, Kevin Wolf, 2021/03/11
- [PULL 32/38] qom: Factor out user_creatable_process_cmdline(), Kevin Wolf, 2021/03/11
- [PULL 31/38] qom: Remove user_creatable_add_dict(), Kevin Wolf, 2021/03/11
- [PULL 25/38] qapi/qom: Add ObjectOptions for confidential-guest-support, Kevin Wolf, 2021/03/11
- [PULL 28/38] qapi/qom: QAPIfy object-add,
Kevin Wolf <=
- [PULL 26/38] qapi/qom: Add ObjectOptions for input-*, Kevin Wolf, 2021/03/11
- [PULL 30/38] qemu-storage-daemon: Implement --object with qmp_object_add(), Kevin Wolf, 2021/03/11
- [PULL 34/38] qemu-nbd: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- [PULL 33/38] qemu-io: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- [PULL 35/38] qom: Add user_creatable_add_from_str(), Kevin Wolf, 2021/03/11
- [PULL 38/38] qom: Add user_creatable_parse_str(), Kevin Wolf, 2021/03/11
- [PULL 37/38] hmp: QAPIfy object_add, Kevin Wolf, 2021/03/11
- [PULL 36/38] qemu-img: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- Re: [PULL 00/38] Block layer patches and object-add QAPIfication, Peter Maydell, 2021/03/12