Skip to contentSkip to conversation

vl: Partial support for non-scalar properties with -object

PATCH In review Markus Armbruster 3 participants 14 messages Aug 11, 2017 – Jun 8, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover vl: Partial support for non-scalar properties with -object

v2:
* PATCH 1: Whitespace change dropped [Eric]
* PATCH 2: Deallocation done differently [Paolo], R-by dropped Commit message typo [Eric]

Markus Armbruster (2):
vl: Factor object_create() out of main()
vl: Partial support for non-scalar properties with -object

 qapi-schema.json | 14 ++++++++---
 vl.c             | 71 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 72 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.5
#1 lore raw

PATCH v2 1/2 vl: Factor object_create() out of main()

---
 vl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
vl.c +10 -10
index 8e247cc..96c5da1 100644
@@ -2855,6 +2855,14 @@ static bool object_create_delayed(const char *type)
     return !object_create_initial(type);
 }
 
+static void object_create(bool (*type_predicate)(const char *))
+{
+    if (qemu_opts_foreach(qemu_find_opts("object"),
+                          user_creatable_add_opts_foreach,
+                          type_predicate, NULL)) {
+        exit(1);
+    }
+}
 
 static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
                                MachineClass *mc)
@@ -4391,11 +4399,7 @@ int main(int argc, char **argv, char **envp)
     page_size_init();
     socket_init();
 
-    if (qemu_opts_foreach(qemu_find_opts("object"),
-                          user_creatable_add_opts_foreach,
-                          object_create_initial, NULL)) {
-        exit(1);
-    }
+    object_create(object_create_initial);
 
     if (qemu_opts_foreach(qemu_find_opts("chardev"),
                           chardev_init_func, NULL, NULL)) {
@@ -4520,11 +4524,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    if (qemu_opts_foreach(qemu_find_opts("object"),
-                          user_creatable_add_opts_foreach,
-                          object_create_delayed, NULL)) {
-        exit(1);
-    }
+    object_create(object_create_delayed);
 
 #ifdef CONFIG_TPM
     if (tpm_init() < 0) {
Signature · 1 line
2.7.5
#2 lore raw

PATCH v2 2/2 vl: Partial support for non-scalar properties with -object

In reply to Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)
qapi-schema.json +11 -3
index 802ea53..7ed1db1 100644
@@ -3618,15 +3618,23 @@
 { 'command': 'netdev_del', 'data': {'id': 'str'} }
 
 ##
-# @object-add:
+# @ObjectOptions:
 #
-# Create a QOM object.
+# Options for creating an object.
 #
 # @qom-type: the class name for the object to be created
 #
 # @id: the name of the new object
 #
 # @props: a dictionary of properties to be passed to the backend
+##
+{ 'struct': 'ObjectOptions',
+  'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
+
+##
+# @object-add:
+#
+# Create a QOM object.
 #
 # Returns: Nothing on success
 #          Error if @qom-type is not a valid class name
@@ -3642,7 +3650,7 @@
 #
 ##
 { 'command': 'object-add',
-  'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
+  'data': 'ObjectOptions' }
 
 ##
 # @object-del:
vl.c +51 -0

65 lines not on this page · raw message

Signature · 1 line
2.7.5
Reviewed-by on v2 2/2
#3 lore raw
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
Quoted 50 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

Quoted 8 lines

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

Yes, that's another restriction: if you need your -object evaluated in a certain order, you may have to stick to one of the two syntax variants.

Aside: there are two sane evaluation orders: (1) strictly left to right, and (2) order doesn't matter. QEMU of course does (3) unpredicable for humans without referring back to the source code.

Quoted 1 line

Thanks!

#5 lore raw
Quoted 61 lines · Markus Armbruster
Quoted 50 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

Quoted 8 lines

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

Quoted 6 lines

Yes, that's another restriction: if you need your -object evaluated in a certain order, you may have to stick to one of the two syntax variants.

Aside: there are two sane evaluation orders: (1) strictly left to right, and (2) order doesn't matter. QEMU of course does (3) unpredicable for humans without referring back to the source code.

IIUC, to "fix" the ordering problem we need to be able to consider the ordering of all QEMU args, not just -object.

The horrible hack with the two stage setup of -object in vl.c is driven by the fact that some objects are referenced by -device/-chardev args, while objects are referencing -device/-chardev args etc. This is the big problem to untangle, and understandable you don't want to tackle that for this patch. Until we can figure out how to address the big problem, it would be nice not to introduce yet another ordering though driven off usage of json vs non-json syntax.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Markus Armbruster
Quoted 50 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

Quoted 8 lines

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

Yes, that's another restriction: if you need your -object evaluated in a certain order, you may have to stick to one of the two syntax variants.

Quoted 6 lines
Quoted 3 lines

Aside: there are two sane evaluation orders: (1) strictly left to right, and (2) order doesn't matter. QEMU of course does (3) unpredicable for humans without referring back to the source code.

IIUC, to "fix" the ordering problem we need to be able to consider the ordering of all QEMU args, not just -object.

Yes.

Quoted 7 lines

The horrible hack with the two stage setup of -object in vl.c is driven by the fact that some objects are referenced by -device/-chardev args, while objects are referencing -device/-chardev args etc. This is the big problem to untangle, and understandable you don't want to tackle that for this patch. Until we can figure out how to address the big problem, it would be nice not to introduce yet another ordering though driven off usage of json vs non-json syntax.

I proposed the patch as a quick hack to unblock development. We then decided we had nothing worthwhile to unblock at the time.

You now want it as a stop gap so certain features don't have to wait until I crack the more general command line expressiveness problem. I agree we should reconsider what warts and restrictions are acceptable for this different, more serious purpose.

I doubt the reordering wart and its accompanying "don't mix dotted keys with JSON if you need evaluation in order" restriction is inacceptable. However, avoiding the reordering wart might be easier than debating it, so let me look into that first.

#7 lore raw
In reply to Eric Blake
Quoted 50 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

Quoted 8 lines

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

I don't really like such a constraint - the ordering of object creation is already complex with some objets created at a different point in startup to other objects. Adding yet another constraint feels like it is painting ourselves into a corner wrt future changes. In particular I think it is quite possible to use the dotted form primarily, and only use JSON for the immediate scenario where non-JSON form won't work - I expect that's how we would use it in libvirt - I don't see libvirt changing 100% to JSON based objects

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

Quoted 7 lines
Quoted 2 lines

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

I don't really like such a constraint - the ordering of object creation is already complex with some objets created at a different point in startup to other objects. Adding yet another constraint feels like it is painting ourselves into a corner wrt future changes.

The full solution will evaluate -object left to right.

This partial solution doesn't, but it's not meant for use in anger, just for unblocking development work. Can add scary warnings to deter premature use.

Quoted 5 lines

In particular I think it is quite possible to use the dotted form primarily, and only use JSON for the immediate scenario where non-JSON form won't work - I expect that's how we would use it in libvirt - I don't see libvirt changing 100% to JSON based objects

You need the JSON form anyway for QMP, and for the cases where dotted keys break down. Doing both just for the command line requires code to do dotted keys (which may already exist), and code to decide whether it can be used (which probably doesn't exist, yet).

Wouldn't this add complexity? For what benefit exactly?

#9 lore raw
Quoted 79 lines · Markus Armbruster
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

Quoted 7 lines
Quoted 2 lines

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

I don't really like such a constraint - the ordering of object creation is already complex with some objets created at a different point in startup to other objects. Adding yet another constraint feels like it is painting ourselves into a corner wrt future changes.

The full solution will evaluate -object left to right.

This partial solution doesn't, but it's not meant for use in anger, just for unblocking development work. Can add scary warnings to deter premature use.

Quoted 5 lines

In particular I think it is quite possible to use the dotted form primarily, and only use JSON for the immediate scenario where non-JSON form won't work - I expect that's how we would use it in libvirt - I don't see libvirt changing 100% to JSON based objects

Quoted 6 lines

You need the JSON form anyway for QMP, and for the cases where dotted keys break down. Doing both just for the command line requires code to do dotted keys (which may already exist), and code to decide whether it can be used (which probably doesn't exist, yet).

Wouldn't this add complexity? For what benefit exactly?

Surprisingly, it appears we do actually have code that generates the JSON syntax for (probably) all uses of -object today. In fact we are actually generating JSON and then converting it to dotted syntax in most cases, which I didn't realize when writing the above.

We'll have to keep support for dotted syntax around a while for old QEMU versions, but it looks like we could reasonably easily switch to JSON syntax for all -object usage at the same time.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw
Quoted 87 lines · Daniel P. Berrangé
Quoted 79 lines · Markus Armbruster
Quoted 57 lines · Daniel P. Berrange
Quoted 56 lines · Eric Blake
Quoted 35 lines · Markus Armbruster

We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems.

Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object.

The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=VALUE,... case, to sidestep compatibility problems.

If we did this for more options, we'd have to factor out common code. But for one option, this will do.

---
 qapi-schema.json | 14 +++++++++++---
 vl.c             | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)

static void object_create(bool (*type_predicate)(const char *)) {

vl.c +7 -0
+    ObjectOptionsQueueEntry *e, *next;
+
+    QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+        if (!type_predicate(e->oo->qom_type)) {
+            continue;
+        }
+

vl.c static bool object_create_delayed(const char *type) · line 2888

Quoted 10 lines
vl.c +9 -0
+        loc_push_restore(&e->loc);
+        qmp_object_add(e->oo->qom_type, e->oo->id,
+                       e->oo->has_props, e->oo->props, &error_fatal);
+        loc_pop(&e->loc);
+
+        QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+        qapi_free_ObjectOptions(e->oo);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("object"),

This handles all JSON forms prior to any QemuOpt forms (within the two priority levels), such that a command line using:

-object type,id=1,oldstyle... -object '{'id':2, 'type':..., newstyle...}'

processes the arguments in a different order than

-object type,id=1,oldstyle... -object type,id=2,oldstyle

Quoted 7 lines
Quoted 2 lines

But I don't see that as too bad (ideally, someone using the {} JSON style will use it consistently).

I don't really like such a constraint - the ordering of object creation is already complex with some objets created at a different point in startup to other objects. Adding yet another constraint feels like it is painting ourselves into a corner wrt future changes.

The full solution will evaluate -object left to right.

This partial solution doesn't, but it's not meant for use in anger, just for unblocking development work. Can add scary warnings to deter premature use.

Quoted 5 lines

In particular I think it is quite possible to use the dotted form primarily, and only use JSON for the immediate scenario where non-JSON form won't work - I expect that's how we would use it in libvirt - I don't see libvirt changing 100% to JSON based objects

Quoted 6 lines

You need the JSON form anyway for QMP, and for the cases where dotted keys break down. Doing both just for the command line requires code to do dotted keys (which may already exist), and code to decide whether it can be used (which probably doesn't exist, yet).

Wouldn't this add complexity? For what benefit exactly?

Quoted 8 lines

Surprisingly, it appears we do actually have code that generates the JSON syntax for (probably) all uses of -object today. In fact we are actually generating JSON and then converting it to dotted syntax in most cases, which I didn't realize when writing the above.

We'll have to keep support for dotted syntax around a while for old QEMU versions, but it looks like we could reasonably easily switch to JSON syntax for all -object usage at the same time.

Excellent.

#11 lore raw
In reply to Markus Armbruster

Just a ping to say I'd like us to restart work this patch and try to get it mergable for the 2.13 cycle, so I can rely it on for the ACL support I've had out of tree since 2.6 :-)

Quoted 5 lines · Markus Armbruster

v2:
* PATCH 1: Whitespace change dropped [Eric]
* PATCH 2: Deallocation done differently [Paolo], R-by dropped Commit message typo [Eric]

Quoted 11 lines

Markus Armbruster (2):
vl: Factor object_create() out of main()
vl: Partial support for non-scalar properties with -object

 qapi-schema.json | 14 ++++++++---
 vl.c             | 71 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 72 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.5

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw
Quoted 3 lines · Daniel P. Berrangé

Just a ping to say I'd like us to restart work this patch and try to get it mergable for the 2.13 cycle, so I can rely it on for the ACL support I've had out of tree since 2.6 :-)

Fair enough. I'll see what I can do.

#13 lore raw
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Daniel P. Berrangé

Just a ping to say I'd like us to restart work this patch and try to get it mergable for the 2.13 cycle, so I can rely it on for the ACL support I've had out of tree since 2.6 :-)

Fair enough. I'll see what I can do.

Heads up that in retrospect I don't think this is a blocker for my ACL work anymore. I decided it was more useful to store the access control list in external files, so we can auto-reload them on the fly without involving the monitor.

Still desirable long term, but no need to rush.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|