qapi: Flatten object-add

Mapping object-add to the command line as is doesn't result in nice
syntax because of the nesting introduced with 'props'. This becomes
nicer and more consistent with device_add and netdev_add when we accept
properties for the object on the top level instead.

'props' is still accepted after this patch, but marked as deprecated.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200224143008.13362-8-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2020-02-24 15:29:55 +01:00
parent 14837c6493
commit 5f07c4d60d
6 changed files with 68 additions and 11 deletions

View File

@ -190,6 +190,11 @@ Use ``migrate-set-parameters`` instead.
Use ``migrate-set-parameters`` and ``query-migrate-parameters`` instead. Use ``migrate-set-parameters`` and ``query-migrate-parameters`` instead.
``object-add`` option ``props`` (since 5.0)
'''''''''''''''''''''''''''''''''''''''''''
Specify the properties for the object as top-level arguments instead.
``query-block`` result field ``dirty-bitmaps[i].status`` (since 4.0) ``query-block`` result field ``dirty-bitmaps[i].status`` (since 4.0)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

View File

@ -18,6 +18,7 @@
#include "qapi/visitor.h" #include "qapi/visitor.h"
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h" #include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "hw/xen/xen_common.h" #include "hw/xen/xen_common.h"
#include "hw/block/xen_blkif.h" #include "hw/block/xen_blkif.h"
#include "hw/qdev-properties.h" #include "hw/qdev-properties.h"
@ -858,10 +859,18 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id,
{ {
XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1); XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
Error *local_err = NULL; Error *local_err = NULL;
QDict *opts;
QObject *ret_data;
iothread->id = g_strdup(id); iothread->id = g_strdup(id);
qmp_object_add(TYPE_IOTHREAD, id, false, NULL, &local_err); opts = qdict_new();
qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
qdict_put_str(opts, "id", id);
qmp_object_add(opts, &ret_data, &local_err);
qobject_unref(opts);
qobject_unref(ret_data);
if (local_err) { if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);

View File

@ -162,4 +162,11 @@ void user_creatable_del(const char *id, Error **errp);
*/ */
void user_creatable_cleanup(void); 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 #endif

View File

@ -248,6 +248,8 @@ static void monitor_init_qmp_commands(void)
QCO_NO_OPTIONS); QCO_NO_OPTIONS);
qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add,
QCO_NO_OPTIONS); QCO_NO_OPTIONS);
qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
QCO_NO_OPTIONS);
QTAILQ_INIT(&qmp_cap_negotiation_commands); QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",

View File

@ -210,7 +210,12 @@
# #
# @id: the name of the new object # @id: the name of the new object
# #
# @props: a dictionary of properties to be passed to the backend # @props: a dictionary of properties to be passed to the backend. Deprecated
# since 5.0, specify the properties on the top level instead. It is an
# error to specify the same option both on the top level and in @props.
#
# Additional arguments depend on qom-type and are passed to the backend
# unchanged.
# #
# Returns: Nothing on success # Returns: Nothing on success
# Error if @qom-type is not a valid class name # Error if @qom-type is not a valid class name
@ -221,12 +226,13 @@
# #
# -> { "execute": "object-add", # -> { "execute": "object-add",
# "arguments": { "qom-type": "rng-random", "id": "rng1", # "arguments": { "qom-type": "rng-random", "id": "rng1",
# "props": { "filename": "/dev/hwrng" } } } # "filename": "/dev/hwrng" } }
# <- { "return": {} } # <- { "return": {} }
# #
## ##
{ 'command': 'object-add', { 'command': 'object-add',
'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} } 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'},
'gen': false } # so we can get the additional arguments
## ##
# @object-del: # @object-del:

View File

@ -14,6 +14,7 @@
*/ */
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "block/qdict.h"
#include "hw/qdev-core.h" #include "hw/qdev-core.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qapi-commands-qdev.h" #include "qapi/qapi-commands-qdev.h"
@ -240,13 +241,34 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
return prop_list; return prop_list;
} }
void qmp_object_add(const char *type, const char *id, void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
bool has_props, QObject *props, Error **errp)
{ {
QObject *props;
QDict *pdict; QDict *pdict;
Visitor *v; Visitor *v;
Object *obj; Object *obj;
const char *type;
const char *id;
type = qdict_get_try_str(qdict, "qom-type");
if (!type) {
error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
return;
} else {
type = g_strdup(type);
qdict_del(qdict, "qom-type");
}
id = qdict_get_try_str(qdict, "id");
if (!id) {
error_setg(errp, QERR_MISSING_PARAMETER, "id");
return;
} else {
id = g_strdup(id);
qdict_del(qdict, "id");
}
props = qdict_get(qdict, "props");
if (props) { if (props) {
pdict = qobject_to(QDict, props); pdict = qobject_to(QDict, props);
if (!pdict) { if (!pdict) {
@ -254,17 +276,23 @@ void qmp_object_add(const char *type, const char *id,
return; return;
} }
qobject_ref(pdict); qobject_ref(pdict);
} else { qdict_del(qdict, "props");
pdict = qdict_new(); qdict_join(qdict, pdict, false);
if (qdict_size(pdict) != 0) {
error_setg(errp, "Option in 'props' conflicts with top level");
qobject_unref(pdict);
return;
}
qobject_unref(pdict);
} }
v = qobject_input_visitor_new(QOBJECT(pdict)); v = qobject_input_visitor_new(QOBJECT(qdict));
obj = user_creatable_add_type(type, id, pdict, v, errp); obj = user_creatable_add_type(type, id, qdict, v, errp);
visit_free(v); visit_free(v);
if (obj) { if (obj) {
object_unref(obj); object_unref(obj);
} }
qobject_unref(pdict); *ret_data = QOBJECT(qdict_new());
} }
void qmp_object_del(const char *id, Error **errp) void qmp_object_del(const char *id, Error **errp)