qom: Support JSON in user_creatable_parse_str()
PATCH 1/1 qom: Support JSON in user_creatable_parse_str()
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().
---
Based-on: <[email protected]>
qom/object_interfaces.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
qom/object_interfaces.c +21 -11
@@ -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; }
Signature · 1 line
2.30.2
Quoted 10 lines · Kevin Wolf
Support JSON for --object in all tools and in HMP
object_addin the same way as it is supported inqobject_input_visitor_new_str().Signed-off-by Kevin Wolf <[email protected]>---
Based-on: <[email protected]>qom/object_interfaces.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Paolo Bonzini
AppliedQuoted 8 lines · Eric Blake
Quoted 7 lines · Kevin Wolf
Support JSON for --object in all tools and in HMP
object_addin the same way as it is supported inqobject_input_visitor_new_str().Signed-off-by Kevin Wolf <[email protected]>---
Based-on: <[email protected]>
Quoted 6 lines
Quoted 3 lines
qom/object_interfaces.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)Reviewed-by Eric Blake <[email protected]>
Queued, thanks.
Paolo
Is this an alternative to Paolo's "[PATCH 0/3] vl: QAPIfy -object", and if not, how do the two play together?
Am 12.03.2021 um 17:01 hat Markus Armbruster geschrieben:
Quoted 2 lines
Is this an alternative to Paolo's "[PATCH 0/3] vl: QAPIfy -object", and if not, how do the two play together?
Paolo's patch adds JSON support to the system emulator CLI (using QemuOpts to stay compatible with the list magic), this patch adds it to everything else (tools don't have memory-backend, and HMP isn't a stable interface, so they all use the same keyval-based function modified by this patch).
Kevin
Recommend
qom: Support JSON in HMP object_add and tools --object
to put the most interesting bit right in "git-log --oneline".
Quoted 51 lines · Kevin Wolf
Support JSON for --object in all tools and in HMP
object_addin the same way as it is supported inqobject_input_visitor_new_str().Signed-off-by Kevin Wolf <[email protected]>---
Based-on: <[email protected]>qom/object_interfaces.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)qom/object_interfaces.c +20
-9@@ -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);
qom/object_interfaces.c static void user_creatable_print_help_from_qdict(QDict *args) · line 329
Quoted 10 lines
qom/object_interfaces.c +1
-2} - 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; }
Best viewed with whitespace change ignored:
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 2e50698075..93b8878127 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -242,12 +242,19 @@ 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 (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;
}
@@ -257,10 +264,13 @@ ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
return NULL;
} - v = qobject_input_visitor_new_keyval(QOBJECT(args));
+ obj = QOBJECT(args);
+ v = qobject_input_visitor_new_keyval(obj);
+ }
+
visit_type_ObjectOptions(v, NULL, &options, errp);
visit_free(v); - qobject_unref(args);
+ qobject_unref(obj);
return options;
}Am 13.03.2021 um 09:00 hat Markus Armbruster geschrieben:
Quoted 5 lines
Recommend
qom: Support JSON in HMP
object_addand tools --objectto put the most interesting bit right in "git-log --oneline".
Makes sense. I've updated my patch locally, but Paolo has already queued it. Paolo, can you update the subject line accordingly?
Kevin
Quoted 9 lines · Kevin Wolf
Am 13.03.2021 um 09:00 hat Markus Armbruster geschrieben:
Quoted 5 lines
Recommend
qom: Support JSON in HMP
object_addand tools --objectto put the most interesting bit right in "git-log --oneline".
Makes sense. I've updated my patch locally, but Paolo has already queued it. Paolo, can you update the subject line accordingly?
Ok, done.
Paolo