aboutsummaryrefslogtreecommitdiff
path: root/qom
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2020-02-24 15:29:55 +0100
committerKevin Wolf <kwolf@redhat.com>2020-03-06 17:21:27 +0100
commit5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e (patch)
tree26dee459d8fc099c99ba98d020ee9820df7df9e1 /qom
parent14837c6493d42f5f85d910935654725217a5770b (diff)
downloadqemu-5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e.zip
qemu-5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e.tar.gz
qemu-5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e.tar.bz2
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>
Diffstat (limited to 'qom')
-rw-r--r--qom/qom-qmp-cmds.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 6136efe..49db926 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -14,6 +14,7 @@
*/
#include "qemu/osdep.h"
+#include "block/qdict.h"
#include "hw/qdev-core.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-qdev.h"
@@ -240,13 +241,34 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
return prop_list;
}
-void qmp_object_add(const char *type, const char *id,
- bool has_props, QObject *props, Error **errp)
+void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
{
+ QObject *props;
QDict *pdict;
Visitor *v;
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) {
pdict = qobject_to(QDict, props);
if (!pdict) {
@@ -254,17 +276,23 @@ void qmp_object_add(const char *type, const char *id,
return;
}
qobject_ref(pdict);
- } else {
- pdict = qdict_new();
+ qdict_del(qdict, "props");
+ 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));
- obj = user_creatable_add_type(type, id, pdict, v, errp);
+ v = qobject_input_visitor_new(QOBJECT(qdict));
+ obj = user_creatable_add_type(type, id, qdict, v, errp);
visit_free(v);
if (obj) {
object_unref(obj);
}
- qobject_unref(pdict);
+ *ret_data = QOBJECT(qdict_new());
}
void qmp_object_del(const char *id, Error **errp)