From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
"William Tsai" <williamtsai1111@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Kevin Wolf" <kwolf@redhat.com>
Subject: [PATCH 1/1] qom: fix setting of array properties
Date: Mon, 4 Sep 2023 17:25:44 +0100 [thread overview]
Message-ID: <20230904162544.2388037-2-berrange@redhat.com> (raw)
In-Reply-To: <20230904162544.2388037-1-berrange@redhat.com>
DEFINE_PROP_ARRAY() creates a property 'len-$ARRAY-PROP-NAME'
which, when set, will create a sequence of '$ARRAY-PROP-NAME[N]'
properties.
This only works if the 'len-$ARRAY-PROP-NAME' property is
set first, and the array elements afterwards. Historically
this required the user to set correct ordering and QemuOpts
traversal would preserve that ordering. With QemuOpts now
converted to QDict, iteration ordering is undefined. Thus
to keep array properties working, we iterate over the QDict
twice.
Doing this in QOM is a bit of a layering violation since
DEFINE_PROP_ARRAY is part of QDev, but it is the simplest
option to preserve backwards compatibility, without ripple
effects across any other part of QEMU.
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1090
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
qom/object_interfaces.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 7d31589b04..6aaaf42ffc 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -51,7 +51,37 @@ static void object_set_properties_from_qdict(Object *obj, const QDict *qdict,
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
return;
}
+
+ /* Layering violation here...
+ *
+ * DEFINE_PROP_ARRAY() creates a property 'len-$ARRAY-PROP-NAME'
+ * which, when set, will create a sequence of '$ARRAY-PROP-NAME[N]'
+ * properties.
+ *
+ * This only works if the 'len-$ARRAY-PROP-NAME' property is
+ * set first, and the array elements afterwards. Historically
+ * this required the user to get correct ordering and QemuOpts
+ * traversal would preserve that ordering. With QemuOpts now
+ * converted to QDict, iteration ordering is undefined. Thus
+ * to keep array properties working, we iterate over the QDict
+ * twice.
+ */
+
+ /* First the props that control array property length */
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+ if (!g_str_has_prefix(e->key, "len-")) {
+ continue;
+ }
+ if (!object_property_set(obj, e->key, v, errp)) {
+ goto out;
+ }
+ }
+
+ /* Then any other normal properties */
+ for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+ if (g_str_has_prefix(e->key, "len-")) {
+ continue;
+ }
if (!object_property_set(obj, e->key, v, errp)) {
goto out;
}
--
2.41.0
next prev parent reply other threads:[~2023-09-04 16:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 16:25 [PATCH 0/1] qom: fix setting of qdev array properties Daniel P. Berrangé
2023-09-04 16:25 ` Daniel P. Berrangé [this message]
2023-09-05 8:58 ` Kevin Wolf
2023-09-05 9:35 ` Peter Maydell
2023-09-07 9:33 ` Markus Armbruster
2023-09-07 9:35 ` Peter Maydell
2023-09-07 10:06 ` Daniel P. Berrangé
2023-09-08 9:25 ` Kevin Wolf
2023-09-08 9:27 ` Daniel P. Berrangé
2023-09-08 12:16 ` Kevin Wolf
2023-09-08 12:19 ` Daniel P. Berrangé
2023-09-08 9:53 ` Peter Maydell
2023-09-08 12:22 ` Kevin Wolf
2023-09-08 12:52 ` Peter Maydell
2023-09-07 12:59 ` Kevin Wolf
2023-09-07 14:16 ` Markus Armbruster
2023-09-07 9:45 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230904162544.2388037-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=eduardo@habkost.net \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=williamtsai1111@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).