Paolo Bonzini <pbonz...@redhat.com> writes: > Extend the ObjectOption code that was added in the previous patch to > enable passing JSON to -object. Even though we cannot yet add > non-scalar properties with the human-friendly comma-separated syntax, > they can now be added as JSON. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > softmmu/vl.c | 27 ++++++++++++++++++--------- > 1 file changed, 18 insertions(+), 9 deletions(-) > > diff --git a/softmmu/vl.c b/softmmu/vl.c > index b245e912e5..7b07f19de7 100644 > --- a/softmmu/vl.c > +++ b/softmmu/vl.c > @@ -31,6 +31,7 @@ > #include "hw/qdev-properties.h" > #include "qapi/error.h" > #include "qapi/qmp/qdict.h" > +#include "qapi/qmp/qjson.h" > #include "qemu-version.h" > #include "qemu/cutils.h" > #include "qemu/help_option.h" > @@ -1714,19 +1715,27 @@ static void object_option_parse(const char *optarg) > const char *type; > Visitor *v; > > - opts = qemu_opts_parse_noisily(qemu_find_opts("object"), > - optarg, true); > - if (!opts) { > - exit(1); > - } > + if (optarg[0] == '{') { > + QObject *obj = qobject_from_json(optarg, &error_fatal); > > - type = qemu_opt_get(opts, "qom-type"); > - if (user_creatable_print_help(type, opts)) { > - exit(0); > + v = qobject_input_visitor_new(obj); > + qobject_unref(obj); > + } else { > + opts = qemu_opts_parse_noisily(qemu_find_opts("object"), > + optarg, true); > + if (!opts) { > + exit(1); > + } > + > + type = qemu_opt_get(opts, "qom-type"); > + if (user_creatable_print_help(type, opts)) { > + exit(0); > + } > + > + v = opts_visitor_new(opts); > } > > opt = g_new0(ObjectOption, 1); > - v = opts_visitor_new(opts); > visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); > visit_free(v);
Best viewed with whitespace change ignored: commit d13ba69a7cf33f583a22c28644c28928b120aff0 Author: Paolo Bonzini <pbonz...@redhat.com> Date: Thu Mar 11 12:24:59 2021 -0500 vl: allow passing JSON to -object Extend the ObjectOption code that was added in the previous patch to enable passing JSON to -object. Even though we cannot yet add non-scalar properties with the human-friendly comma-separated syntax, they can now be added as JSON. Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> Message-Id: <20210311172459.990281-4-pbonz...@redhat.com> diff --git a/softmmu/vl.c b/softmmu/vl.c index b245e912e5..7b07f19de7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -31,6 +31,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/help_option.h" @@ -1714,6 +1715,12 @@ static void object_option_parse(const char *optarg) const char *type; Visitor *v; + if (optarg[0] == '{') { + QObject *obj = qobject_from_json(optarg, &error_fatal); + + v = qobject_input_visitor_new(obj); + qobject_unref(obj); + } else { opts = qemu_opts_parse_noisily(qemu_find_opts("object"), optarg, true); if (!opts) { @@ -1725,8 +1732,10 @@ static void object_option_parse(const char *optarg) exit(0); } - opt = g_new0(ObjectOption, 1); v = opts_visitor_new(opts); + } + + opt = g_new0(ObjectOption, 1); visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); visit_free(v); Reviewed-by: Markus Armbruster <arm...@redhat.com>