qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com,
	coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com
Subject: [PATCH v2 07/20] qapi: Flatten object-add
Date: Mon, 24 Feb 2020 15:29:55 +0100	[thread overview]
Message-ID: <20200224143008.13362-8-kwolf@redhat.com> (raw)
In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com>

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>
---
 qapi/qom.json                   | 12 +++++++---
 include/qom/object_interfaces.h |  7 ++++++
 hw/block/xen-block.c            | 11 ++++++++-
 monitor/misc.c                  |  2 ++
 qom/qom-qmp-cmds.c              | 42 +++++++++++++++++++++++++++------
 qemu-deprecated.texi            |  4 ++++
 6 files changed, 67 insertions(+), 11 deletions(-)

diff --git a/qapi/qom.json b/qapi/qom.json
index ecc60c4401..8abe998962 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -210,7 +210,12 @@
 #
 # @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
 #          Error if @qom-type is not a valid class name
@@ -221,12 +226,13 @@
 #
 # -> { "execute": "object-add",
 #      "arguments": { "qom-type": "rng-random", "id": "rng1",
-#                     "props": { "filename": "/dev/hwrng" } } }
+#                     "filename": "/dev/hwrng" } }
 # <- { "return": {} }
 #
 ##
 { '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:
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 3e4e1d928b..6f92f3cebb 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -162,4 +162,11 @@ void 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 686bbc3f0d..3885464513 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -18,6 +18,7 @@
 #include "qapi/visitor.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qom/object_interfaces.h"
 #include "hw/xen/xen_common.h"
 #include "hw/block/xen_blkif.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);
     Error *local_err = NULL;
+    QDict *opts;
+    QObject *ret_data;
 
     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) {
         error_propagate(errp, local_err);
 
diff --git a/monitor/misc.c b/monitor/misc.c
index 6c41293102..1748ab3911 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -248,6 +248,8 @@ static void monitor_init_qmp_commands(void)
                          QCO_NO_OPTIONS);
     qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_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 6136efec16..49db926fcc 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)
diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
index 0671c26c80..faf99d3f91 100644
--- a/qemu-deprecated.texi
+++ b/qemu-deprecated.texi
@@ -167,6 +167,10 @@ Use ``migrate-set-parameters'' instead.
 
 Use ``migrate-set-parameters'' and ``query-migrate-parameters'' instead.
 
+@subsection object-add option props (since 5.0)
+
+Specify the properties for the object as top-level arguments instead.
+
 @subsection query-block result field dirty-bitmaps[i].status (since 4.0)
 
 The ``status'' field of the ``BlockDirtyInfo'' structure, returned by
-- 
2.20.1



  parent reply	other threads:[~2020-02-24 14:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24 14:29 [PATCH v2 00/20] Add qemu-storage-daemon Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 01/20] qemu-storage-daemon: Add barebone tool Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 02/20] stubs: Add arch_type Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 03/20] block: Move system emulator QMP commands to block/qapi-sysemu.c Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 04/20] block: Move common QMP commands to block-core QAPI module Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 05/20] block: Move sysemu QMP commands to QAPI block module Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 06/20] qemu-storage-daemon: Add --blockdev option Kevin Wolf
2020-02-24 14:29 ` Kevin Wolf [this message]
2020-02-24 14:29 ` [PATCH v2 08/20] qemu-storage-daemon: Add --object option Kevin Wolf
2020-04-16  5:20   ` Coiby Xu
2020-06-09 23:25   ` Coiby Xu
2020-02-24 14:29 ` [PATCH v2 09/20] qemu-storage-daemon: Add --nbd-server option Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 10/20] blockdev-nbd: Boxed argument type for nbd-server-add Kevin Wolf
2020-02-24 14:29 ` [PATCH v2 11/20] qemu-storage-daemon: Add --export option Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 12/20] qemu-storage-daemon: Add main loop Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 13/20] qemu-storage-daemon: Add --chardev option Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 14/20] stubs: Update monitor stubs for qemu-storage-daemon Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 15/20] qapi: Create 'pragma' module Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 16/20] monitor: Create QAPIfied monitor_init() Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 17/20] qmp: Fail gracefully if chardev is already in use Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 18/20] hmp: " Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 19/20] monitor: Add allow_hmp parameter to monitor_init() Kevin Wolf
2020-02-24 14:30 ` [PATCH v2 20/20] qemu-storage-daemon: Add --monitor option Kevin Wolf
2020-02-24 15:34 ` [PATCH v2 00/20] Add qemu-storage-daemon no-reply
2020-02-28 11:16 ` Stefan Hajnoczi
2020-03-03 17:00   ` Kevin Wolf

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=20200224143008.13362-8-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=coiby.xu@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).