Skip to contentSkip to conversation

vl: QAPIfy -object

PATCH Applied Paolo Bonzini 4 participants 13 messages Mar 12, 2021 – Apr 16, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover vl: QAPIfy -object

This is a replacement for -object QAPIfication that keeps QemuOpts in order to not break some of the CLI parsing extensions that OptsVisitor includes. Since keyval is not used, support for directly passing JSON syntax to the option must be added manually, which is what patch 3 does. However, both the QemuOpts and the JSON paths go through the new ObjectOptions interface, just with two different visitors, so we can reuse all the new type-safe code that Kevin has added.

Patch 1 is a patch that I already had lying around, which I included to be able to remove user_creatable_add_opts completely in patch 2.

Paolo

Based-on: <[email protected]>

Paolo Bonzini (3):
tests: convert check-qom-proplist to keyval
qom: move user_creatable_add_opts logic to vl.c and QAPIfy it
vl: allow passing JSON to -object

 include/qom/object_interfaces.h | 47 -------------------
 qom/object_interfaces.c         | 54 ---------------------
 softmmu/vl.c                    | 83 ++++++++++++++++++++++++++-------
 tests/check-qom-proplist.c      | 77 +++++++++++++++++++++---------
 4 files changed, 120 insertions(+), 141 deletions(-)

v1->v2: avoid g_assert with side effects, fix -object without qom-type

Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/3 tests: convert check-qom-proplist to keyval

The command-line creation test is using QemuOpts. Switch it to keyval, since the emulator has some special needs and thus the last user of user_creatable_add_opts will go away with the next patch.

---
 tests/check-qom-proplist.c | 77 +++++++++++++++++++++++++++-----------
 1 file changed, 55 insertions(+), 22 deletions(-)
tests/check-qom-proplist.c +55 -22
index 1b76581980..48503e0dff 100644
@@ -21,6 +21,9 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "qapi/qobject-input-visitor.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qobject.h"
 #include "qom/object.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
@@ -398,44 +401,74 @@ static void test_dummy_createlist(void)
     object_unparent(OBJECT(dobj));
 }
 
+static bool test_create_obj(QDict *qdict, Error **errp)
+{
+    Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
+    Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp);
+
+    visit_free(v);
+    object_unref(obj);
+    return !!obj;
+}
+
 static void test_dummy_createcmdl(void)
 {
-    QemuOpts *opts;
+    QDict *qdict;
     DummyObject *dobj;
     Error *err = NULL;
-    const char *params = TYPE_DUMMY \
-                         ",id=dev0," \
-                         "bv=yes,sv=Hiss hiss hiss,av=platypus";
+    bool created, help;
+    const char *params = "bv=yes,sv=Hiss hiss hiss,av=platypus";
 
+    /* Needed for user_creatable_del.  */
     qemu_add_opts(&qemu_object_opts);
-    opts = qemu_opts_parse(&qemu_object_opts, params, true, &err);
+
+    qdict = keyval_parse(params, "qom-type", &help, &err);
     g_assert(err == NULL);
-    g_assert(opts);
+    g_assert(qdict);
+    g_assert(!help);
 
-    dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, &err));
+    created = test_create_obj(qdict, &err);
+    g_assert(created);
     g_assert(err == NULL);
+    qobject_unref(qdict);
+
+    dobj = DUMMY_OBJECT(object_resolve_path_component(object_get_objects_root(),
+                                                      "dev0"));
     g_assert(dobj);
     g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");
     g_assert(dobj->bv == true);
     g_assert(dobj->av == DUMMY_PLATYPUS);
 
+    qdict = keyval_parse(params, "qom-type", &help, &err);
+    created = test_create_obj(qdict, &err);
+    g_assert(!created);
+    g_assert(err);
+    g_assert(object_resolve_path_component(object_get_objects_root(), "dev0")
+             == OBJECT(dobj));
+    qobject_unref(qdict);
+    error_free(err);
+    err = NULL;
+
+    qdict = keyval_parse(params, "qom-type", &help, &err);
     user_creatable_del("dev0", &error_abort);
+    g_assert(object_resolve_path_component(object_get_objects_root(), "dev0")
+             == NULL);
 
-    object_unref(OBJECT(dobj));
-
-    /*
-     * cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry
-     * corresponding to the Object's ID to be added to the QemuOptsList
-     * for objects. To avoid having this entry conflict with future
-     * Objects using the same ID (which can happen in cases where
-     * qemu_opts_parse() is used to parse the object params, such as
-     * with hmp_object_add() at the time of this comment), we need to
-     * check for this in user_creatable_del() and remove the QemuOpts if
-     * it is present.
-     *
-     * The below check ensures this works as expected.
-     */
-    g_assert_null(qemu_opts_find(&qemu_object_opts, "dev0"));
+    created = test_create_obj(qdict, &err);
+    g_assert(created);
+    g_assert(err == NULL);
+    qobject_unref(qdict);
+
+    dobj = DUMMY_OBJECT(object_resolve_path_component(object_get_objects_root(),
+                                                      "dev0"));
+    g_assert(dobj);
+    g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");
+    g_assert(dobj->bv == true);
+    g_assert(dobj->av == DUMMY_PLATYPUS);
+    g_assert(object_resolve_path_component(object_get_objects_root(), "dev0")
+             == OBJECT(dobj));
+
+    object_unparent(OBJECT(dobj));
 }
 
 static void test_dummy_badenum(void)
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/3 qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

In reply to Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

-object memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind

So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi.

In order to minimize code changes, the predicate still takes a string. This can be changed later to use the ObjectType QAPI enum directly.

---
 include/qom/object_interfaces.h | 47 ---------------------
 qom/object_interfaces.c         | 54 ------------------------
 softmmu/vl.c                    | 74 +++++++++++++++++++++++++--------
 3 files changed, 56 insertions(+), 119 deletions(-)
include/qom/object_interfaces.h +0 -47
index fb32330901..81541e2080 100644
@@ -94,56 +94,9 @@ Object *user_creatable_add_type(const char *type, const char *id,
  *
  * Create an instance of the user creatable object according to the
  * options passed in @opts as described in the QAPI schema documentation.
- *
- * Returns: the newly created object or NULL on error
  */
 void user_creatable_add_qapi(ObjectOptions *options, Error **errp);
 
-/**
- * user_creatable_add_opts:
- * @opts: the object definition
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Create an instance of the user creatable object whose type
- * is defined in @opts by the 'qom-type' option, placing it
- * in the object composition tree with name provided by the
- * 'id' field. The remaining options in @opts are used to
- * initialize the object properties.
- *
- * Returns: the newly created object or NULL on error
- */
-Object *user_creatable_add_opts(QemuOpts *opts, Error **errp);
-
-
-/**
- * user_creatable_add_opts_predicate:
- * @type: the QOM type to be added
- *
- * A callback function to determine whether an object
- * of type @type should be created. Instances of this
- * callback should be passed to user_creatable_add_opts_foreach
- */
-typedef bool (*user_creatable_add_opts_predicate)(const char *type);
-
-/**
- * user_creatable_add_opts_foreach:
- * @opaque: a user_creatable_add_opts_predicate callback or NULL
- * @opts: options to create
- * @errp: unused
- *
- * An iterator callback to be used in conjunction with
- * the qemu_opts_foreach() method for creating a list of
- * objects from a set of QemuOpts
- *
- * The @opaque parameter can be passed a user_creatable_add_opts_predicate
- * callback to filter which types of object are created during iteration.
- * When it fails, report the error.
- *
- * Returns: 0 on success, -1 when an error was reported.
- */
-int user_creatable_add_opts_foreach(void *opaque,
-                                    QemuOpts *opts, Error **errp);
-
 /**
  * user_creatable_parse_str:
  * @optarg: the object definition string as passed on the command line
qom/object_interfaces.c +0 -54

60 lines not on this page · raw message

softmmu/vl.c +56 -18

128 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

Am 12.03.2021 um 18:35 hat Paolo Bonzini geschrieben:

Quoted 50 lines

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

-object memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind

So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi.

In order to minimize code changes, the predicate still takes a string. This can be changed later to use the ObjectType QAPI enum directly.

softmmu/vl.c +7 -0
index ff488ea3e7..ae017de46c 100644
@@ -117,6 +117,7 @@
 #include "qapi/qapi-commands-block-core.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-visit-qom.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/iothread.h"
@@ -132,10 +133,16 @@ typedef struct BlockdevOptionsQueueEntry {
 
 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue;
 
+typedef struct ObjectOption {
+    ObjectOptions *opts;
+    QTAILQ_ENTRY(ObjectOption) next;
+} ObjectOption;
+
 static const char *cpu_option;
 static const char *mem_path;
 static const char *incoming;
 static const char *loadvm;
+static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts);
 static ram_addr_t maxram_size;
 static uint64_t ram_slots;
 static int display_remote;
@@ -1684,6 +1691,49 @@ static int machine_set_property(void *opaque,
     return object_parse_property_opt(opaque, name, value, "type", errp);
 }
 

softmmu/vl.c static int machine_set_property(void *opaque, · line 1703

Quoted 10 lines
softmmu/vl.c +10 -0
+static void object_option_foreach_add(bool (*type_opt_predicate)(const char *))
+{
+    ObjectOption *opt, *next;
+
+    QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) {
+        const char *type = ObjectType_str(opt->opts->qom_type);
+        if (type_opt_predicate(type)) {
+            user_creatable_add_qapi(opt->opts, &error_fatal);
+            qapi_free_ObjectOptions(opt->opts);
+            QTAILQ_REMOVE(&object_opts, opt, next);

I added a g_free(opt) here to fix CI failures (LeakSanitizer error).

softmmu/vl.c static int machine_set_property(void *opaque, · line 1706

Quoted 3 lines
softmmu/vl.c +3 -0
+        }
+    }
+}

Kevin

#4 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

In reply to Paolo Bonzini
Quoted 5 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines
   -object memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind

So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi.

In order to minimize code changes, the predicate still takes a string. This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

Quoted 21 lines · David Hildenbrand
Quoted 4 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines

-object
memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string.
This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

Quoted 7 lines

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Wild guess: you didn't add your new properties in the QAPI schema.

For a not-so-wild-guess, send us a git-fetch argument for your rebased series.

#6 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

Quoted 27 lines · Markus Armbruster
Quoted 25 lines · David Hildenbrand
Quoted 4 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines

-object
memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string.
This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Quoted 9 lines
Quoted 3 lines

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Wild guess: you didn't add your new properties in the QAPI schema.

For a not-so-wild-guess, send us a git-fetch argument for your rebased series.

Oh, there is qapi/qom.json -- maybe that does the trick.

(I have mixed feelings about having to specify the same thing twice at different locations)

I'll have a look if that makes it fly.

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

Quoted 38 lines · David Hildenbrand
Quoted 27 lines · Markus Armbruster
Quoted 25 lines · David Hildenbrand
Quoted 4 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines

-object
memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string.
This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Quoted 9 lines
Quoted 3 lines

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Wild guess: you didn't add your new properties in the QAPI schema.

For a not-so-wild-guess, send us a git-fetch argument for your rebased series.

Quoted 6 lines

Oh, there is qapi/qom.json -- maybe that does the trick.

(I have mixed feelings about having to specify the same thing twice at different locations)

I'll have a look if that makes it fly.

Yes, works just fine -- thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

In reply to David Hildenbrand

Am 13.04.2021 um 10:13 hat David Hildenbrand geschrieben:

Quoted 34 lines · Markus Armbruster
Quoted 33 lines
Quoted 21 lines · David Hildenbrand
Quoted 4 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines

-object
memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string.
This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

Quoted 7 lines

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Wild guess: you didn't add your new properties in the QAPI schema.

Quoted 8 lines
Quoted 3 lines

For a not-so-wild-guess, send us a git-fetch argument for your rebased series.

Oh, there is qapi/qom.json -- maybe that does the trick.

(I have mixed feelings about having to specify the same thing twice at different locations)

The idea is that we'll eventually generate some of the QOM boilerplate from the QAPI schema and remove the duplication again.

But yes, for the time being, you need to touch both places.

Kevin

#9 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

In reply to David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 27 lines · Markus Armbruster
Quoted 25 lines · David Hildenbrand
Quoted 4 lines · Paolo Bonzini

Emulators are currently using OptsVisitor (via user_creatable_add_opts) to parse the -object command line option. This has one extra feature, compared to keyval, which is automatic conversion of integers to lists as well as support for lists as repeated options:

Quoted 9 lines

-object
memory-backend-ram,id=pc.ram,size=1048576000,host-nodes=0,policy=bind So we cannot replace OptsVisitor with keyval right now. Still, this patch moves the user_creatable_add_opts logic to vl.c since it is not needed anywhere else, and makes it go through user_creatable_add_qapi. In order to minimize code changes, the predicate still takes a string.
This can be changed later to use the ObjectType QAPI enum directly.

Rebasing my "noreserve"[1] series on this, I get weird errors from QEMU when specifying the new "reserve=off" option for a memory-backend-ram:

"Invalid parameter 'reserve'"

And it looks like this is the case for any new properties. Poking around, I fail to find what's causing this -- or how to unlock new properties. What is the magic toggle to make it work?

Quoted 8 lines
Quoted 3 lines

Thanks!

[1] https://lkml.kernel.org/r/[email protected]

Wild guess: you didn't add your new properties in the QAPI schema. For a not-so-wild-guess, send us a git-fetch argument for your rebased
series.

Quoted 4 lines

Oh, there is qapi/qom.json -- maybe that does the trick.

(I have mixed feelings about having to specify the same thing twice at different locations)

With reason.

We've talked about generating QOM boilerplate from the QAPI schema, but haven't progressed to actual patches.

Quoted 1 line

I'll have a look if that makes it fly.

#10 lore raw

Re: [PATCH v2 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it

Quoted 9 lines · Markus Armbruster
Quoted 4 lines

Oh, there is qapi/qom.json -- maybe that does the trick.

(I have mixed feelings about having to specify the same thing twice at different locations)

With reason.

We've talked about generating QOM boilerplate from the QAPI schema, but haven't progressed to actual patches.

There is an initial sketch at
https://wiki.qemu.org/Features/QOM-QAPI_integration, covering what can be done before touching the code generator.

The basic idea is to keep property getters, which allow to read how an object was configured and already vastly reduces the amount of boilerplate, and replace the setters with a method that takes a QAPI visitor.

Later on the low-level QAPI code can be generated by qapi-gen, similar to QMP commands. However, unlike QMP (where QAPIfication included switching from raw QDicts to QAPI structs) here we already start with code that uses vistors and QAPI structs. So it's not like having to rewrite things twice.

Paolo

#11 lore raw

PATCH v2 3/3 vl: allow passing JSON to -object

In reply to Paolo Bonzini

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.

---
 softmmu/vl.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
softmmu/vl.c +21 -12
index ae017de46c..0e3fa53057 100644
@@ -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);
 
Signature · 1 line
2.26.2
Applied
#12 lore raw
In reply to Paolo Bonzini

Am 12.03.2021 um 18:35 hat Paolo Bonzini geschrieben:

Quoted 8 lines

This is a replacement for -object QAPIfication that keeps QemuOpts in order to not break some of the CLI parsing extensions that OptsVisitor includes. Since keyval is not used, support for directly passing JSON syntax to the option must be added manually, which is what patch 3 does. However, both the QemuOpts and the JSON paths go through the new ObjectOptions interface, just with two different visitors, so we can reuse all the new type-safe code that Kevin has added.

Quoted 6 lines

Patch 1 is a patch that I already had lying around, which I included to be able to remove user_creatable_add_opts completely in patch 2.

Paolo

Based-on: <[email protected]>

Thanks, applied to the block branch.

Kevin