aboutsummaryrefslogtreecommitdiff
path: root/softmmu
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-03-12 12:35:47 -0500
committerKevin Wolf <kwolf@redhat.com>2021-03-19 10:18:17 +0100
commit009ff89328b1da3ea8ba316bf2be2125bc9937c5 (patch)
tree3bd417d7482bd71e16dbdcf8a27a79b3f2b23106 /softmmu
parentbc2f4fcb1dd1a66ede126593fa091c23a94e3ab8 (diff)
downloadqemu-009ff89328b1da3ea8ba316bf2be2125bc9937c5.zip
qemu-009ff89328b1da3ea8ba316bf2be2125bc9937c5.tar.gz
qemu-009ff89328b1da3ea8ba316bf2be2125bc9937c5.tar.bz2
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. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20210312173547.1283477-4-pbonzini@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'softmmu')
-rw-r--r--softmmu/vl.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/softmmu/vl.c b/softmmu/vl.c
index cfb1ae9..cba7ab3 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"
@@ -1712,22 +1713,30 @@ 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 (!type) {
- error_setg(&error_fatal, QERR_MISSING_PARAMETER, "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 (!type) {
+ error_setg(&error_fatal, QERR_MISSING_PARAMETER, "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);