From: Peter Xu <peterx@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P . Berrangé" <berrange@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 02/12] qom: New container_create()
Date: Thu, 21 Nov 2024 11:18:05 -0500 [thread overview]
Message-ID: <Zz9dPefajA8aOtAN@x1n> (raw)
In-Reply-To: <87ttc0iuz7.fsf@pond.sub.org>
On Thu, Nov 21, 2024 at 02:20:44PM +0100, Markus Armbruster wrote:
> Peter Xu <peterx@redhat.com> writes:
>
> > To move towards explicit creations of containers, starting that by
> > providing a helper for creating container objects.
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > include/qom/object.h | 12 ++++++++++++
> > qom/container.c | 18 +++++++++++++++---
> > 2 files changed, 27 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index 3ba370ce9b..41ef53241e 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -2033,6 +2033,18 @@ int object_child_foreach_recursive(Object *obj,
> > */
> > Object *container_get(Object *root, const char *path);
> >
> > +
> > +/**
> > + * container_create:
> > + * @root: root of the object to create the new container
> > + * @name: name of the new container
>
> Is this the name of the property of @root to hold the new container?
> Peeking ahead to the implementation... yes.
>
> > + *
> > + * Create a container object under @root with @name.
> > + *
> > + * Returns: the newly created container object.
> > + */
> > +Object *container_create(Object *root, const char *name);
>
> No function in this file is named like FOO_create(). Hmm.
>
> Compare:
>
> /**
> * object_property_try_add_child:
> * @obj: the object to add a property to
> * @name: the name of the property
> * @child: the child object
> * @errp: pointer to error object
> *
> * Child properties form the composition tree. All objects need to be a child
> * of another object. Objects can only be a child of one object.
> *
> * There is no way for a child to determine what its parent is. It is not
> * a bidirectional relationship. This is by design.
>
> Aside: this is nonsense. While you're not supposed to simply use
> obj->parent (it's documented as private), you can still get the child's
> canonical path with object_get_canonical_path(), split off its last
> component to get the parent's canonical path, then use
> object_resolve_path() to get the parent.
>
> *
> * The value of a child property as a C string will be the child object's
> * canonical path. It can be retrieved using object_property_get_str().
> * The child object itself can be retrieved using object_property_get_link().
> *
> * Returns: The newly added property on success, or %NULL on failure.
> */
>
> What about
>
> /**
> * object_property_add_new_container:
> * @obj: the parent object
> * @name: the name of the parent object's property to add
> *
> * Add a newly created container object to a parent object.
> *
> * Returns: the newly created container object. Its reference count
> * is 1, and the reference is owned by the parent object.
> */
Sure, this may indeed align better with the rest function names.
>
> > +
> > /**
> > * object_property_help:
> > * @name: the name of the property
> > diff --git a/qom/container.c b/qom/container.c
> > index cfec92a944..da657754a4 100644
> > --- a/qom/container.c
> > +++ b/qom/container.c
> > @@ -24,6 +24,20 @@ static void container_register_types(void)
> > type_register_static(&container_info);
> > }
> >
> > +Object *container_create(Object *obj, const char *name)
> > +{
> > + Object *child = object_new(TYPE_CONTAINER);
> > +
> > + object_property_add_child(obj, name, child);
> > + /*
> > + * Simplify the caller by always drop the refcount directly here, as
> > + * containers are normally never destroyed after created anyway.
> > + */
> > + object_unref(child);
>
> Do we still need the comment if we document the reference count in the
> function comment?
Probably not. I'll drop this comment while taking above suggestion.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2024-11-21 16:19 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 [this message]
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é
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=Zz9dPefajA8aOtAN@x1n \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@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=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).