From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, pkrempa@redhat.com,
armbru@redhat.com
Subject: [PATCH] qom: Support JSON in user_creatable_parse_str()
Date: Fri, 12 Mar 2021 14:19:21 +0100 [thread overview]
Message-ID: <20210312131921.421023-1-kwolf@redhat.com> (raw)
Support JSON for --object in all tools and in HMP object_add in the same
way as it is supported in qobject_input_visitor_new_str().
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
Based-on: <20210311144811.313451-1-kwolf@redhat.com>
qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 62d7db7629..f5ea84b6c4 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -295,25 +295,35 @@ static void user_creatable_print_help_from_qdict(QDict *args)
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
{
ERRP_GUARD();
- QDict *args;
+ QObject *obj;
bool help;
Visitor *v;
ObjectOptions *options;
- args = keyval_parse(optarg, "qom-type", &help, errp);
- if (*errp) {
- return NULL;
- }
- if (help) {
- user_creatable_print_help_from_qdict(args);
- qobject_unref(args);
- return NULL;
+ if (optarg[0] == '{') {
+ obj = qobject_from_json(optarg, errp);
+ if (!obj) {
+ return NULL;
+ }
+ v = qobject_input_visitor_new(obj);
+ } else {
+ QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
+ if (*errp) {
+ return NULL;
+ }
+ if (help) {
+ user_creatable_print_help_from_qdict(args);
+ qobject_unref(args);
+ return NULL;
+ }
+
+ obj = QOBJECT(args);
+ v = qobject_input_visitor_new_keyval(obj);
}
- v = qobject_input_visitor_new_keyval(QOBJECT(args));
visit_type_ObjectOptions(v, NULL, &options, errp);
visit_free(v);
- qobject_unref(args);
+ qobject_unref(obj);
return options;
}
--
2.30.2
next reply other threads:[~2021-03-12 13:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 13:19 Kevin Wolf [this message]
2021-03-12 13:59 ` [PATCH] qom: Support JSON in user_creatable_parse_str() Eric Blake
2021-03-12 14:47 ` Paolo Bonzini
2021-03-12 16:01 ` Markus Armbruster
2021-03-12 16:32 ` Kevin Wolf
2021-03-13 8:00 ` Markus Armbruster
2021-03-15 11:56 ` Kevin Wolf
2021-03-15 12:00 ` Paolo Bonzini
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=20210312131921.421023-1-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pkrempa@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).