]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qom: Support JSON in HMP object_add and tools --object
authorKevin Wolf <kwolf@redhat.com>
Fri, 12 Mar 2021 13:19:21 +0000 (14:19 +0100)
committerKevin Wolf <kwolf@redhat.com>
Fri, 19 Mar 2021 09:18:17 +0000 (10:18 +0100)
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>
Message-Id: <20210312131921.421023-1-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qom/object_interfaces.c

index 0614246f8a00aa087ffe73e38e3cdd9f4488b141..7b87f21883624baa8fd25b5c31791d1fa84eb4f7 100644 (file)
@@ -296,25 +296,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;
 }