From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Juraj Marcin" <jmarcin@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Cédric Le Goater" <clg@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>
Subject: Re: [PATCH 08/12] qdev: Make qdev_get_machine() not use container_get()
Date: Thu, 21 Nov 2024 10:21:48 +0000 [thread overview]
Message-ID: <Zz8JvAxXHqa3wfHv@redhat.com> (raw)
In-Reply-To: <20241120215703.3918445-9-peterx@redhat.com>
On Wed, Nov 20, 2024 at 04:56:59PM -0500, Peter Xu wrote:
> Currently, qdev_get_machine() has a slight misuse on container_get(), as
> the helper says "get a container" but in reality the goal is to get the
> machine object. It is still a "container" but not strictly.
>
> Note that it _may_ get a container (at "/machine") in our current unit test
> of test-qdev-global-props.c before all these changes, but it's probably
> unexpected and worked by accident.
>
> Switch to an explicit object_resolve_path_component(), with a side benefit
> that qdev_get_machine() can happen a lot, and we don't need to split the
> string ("/machine") every time. This also paves way for making the helper
> container_get() never try to return a non-container at all.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> hw/core/qdev.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 5f13111b77..c869c47a27 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -817,7 +817,13 @@ Object *qdev_get_machine(void)
> static Object *dev;
>
> if (dev == NULL) {
> - dev = container_get(object_get_root(), "/machine");
> + /*
> + * NOTE: when the machine is not yet created, this helper will
> + * also keep the cached object untouched and return NULL. The next
> + * invoke of the helper will try to look for the machine again.
> + * It'll only cache the pointer when it's found the first time.
> + */
This smells like a recipe for subtle bugs. I think I'd consider it a code
flaw if something called qdev_get_machine() in a scenario where the machine
does not yet exist.
> + dev = object_resolve_path_component(object_get_root(), "machine");
> }
IOW, I think we should assert that dev != NULL to ensure we immediately
diagnose the flawed sequence of calls.
With regards,
Daniel
--
|: 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 :|
next prev parent reply other threads:[~2024-11-21 10:22 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 21:56 [PATCH 00/12] QOM: container_get() removal Peter Xu
2024-11-20 21:56 ` [PATCH 01/12] qom: Add TYPE_CONTAINER macro Peter Xu
2024-11-21 9:20 ` Philippe Mathieu-Daudé
2024-11-21 10:04 ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 02/12] qom: New container_create() Peter Xu
2024-11-21 10:05 ` Daniel P. Berrangé
2024-11-21 13:20 ` Markus Armbruster
2024-11-21 16:18 ` Peter Xu
2024-11-20 21:56 ` [PATCH 03/12] tests: Fix test-qdev-global-props on anonymous qdev realize() Peter Xu
2024-11-21 9:20 ` Philippe Mathieu-Daudé
2024-11-21 10:16 ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 04/12] tests: Explicitly create containers in test_qom_partial_path() Peter Xu
2024-11-21 9:19 ` Philippe Mathieu-Daudé
2024-11-21 10:16 ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 05/12] ui/console: Explicitly create "/backend" container Peter Xu
2024-11-21 9:19 ` Philippe Mathieu-Daudé
2024-11-21 10:26 ` Daniel P. Berrangé
2024-11-21 16:27 ` Peter Xu
2024-11-20 21:56 ` [PATCH 06/12] hw/ppc: Explicitly create the drc container Peter Xu
2024-11-21 9:35 ` Philippe Mathieu-Daudé
2024-11-21 16:36 ` Peter Xu
2024-11-21 17:14 ` Philippe Mathieu-Daudé
2024-11-20 21:56 ` [PATCH 07/12] ppc/e500: Avoid abuse of container_get() Peter Xu
2024-11-21 9:38 ` Cédric Le Goater
2024-11-21 9:48 ` Cédric Le Goater
2024-11-21 16:41 ` Peter Xu
2024-11-21 17:17 ` Philippe Mathieu-Daudé
2024-11-21 10:28 ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 08/12] qdev: Make qdev_get_machine() not use container_get() Peter Xu
2024-11-21 10:21 ` Daniel P. Berrangé [this message]
2024-11-21 16:48 ` Peter Xu
2024-11-20 21:57 ` [PATCH 09/12] qdev: Add machine_get_container() Peter Xu
2024-11-21 9:23 ` Philippe Mathieu-Daudé
2024-11-21 10:23 ` Daniel P. Berrangé
2024-11-21 13:23 ` Markus Armbruster
2024-11-20 21:57 ` [PATCH 10/12] qom: Create system containers explicitly Peter Xu
2024-11-21 9:13 ` Philippe Mathieu-Daudé
2024-11-21 10:30 ` Daniel P. Berrangé
2024-11-21 13:01 ` Philippe Mathieu-Daudé
2024-11-21 17:17 ` Peter Xu
2024-11-21 17:29 ` Philippe Mathieu-Daudé
2024-11-21 18:03 ` Peter Xu
2024-11-21 19:03 ` Philippe Mathieu-Daudé
2024-11-21 13:31 ` Markus Armbruster
2024-11-21 17:24 ` Peter Xu
2024-11-20 21:57 ` [PATCH 11/12] qom: Add object_get_container() Peter Xu
2024-11-21 9:23 ` Philippe Mathieu-Daudé
2024-11-21 10:30 ` Daniel P. Berrangé
2024-11-20 21:57 ` [PATCH 12/12] qom: Drop container_get() Peter Xu
2024-11-21 10:32 ` Daniel P. Berrangé
2024-11-21 9:18 ` [PATCH 00/12] QOM: container_get() removal Philippe Mathieu-Daudé
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=Zz8JvAxXHqa3wfHv@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=clg@redhat.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).