All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Mark Cave-Ayland <mark.caveayland@nutanix.com>
Subject: Re: [PATCH] include/hw/core/qdev.h: Fix where device_class_set_parent_realize docs suggest putting parent_realize
Date: Fri, 16 Oct 2026 15:26:16 +0100	[thread overview]
Message-ID: <atI0CCfUsBR2kqkB@redhat.com> (raw)
In-Reply-To: <CAFEAcA8hJ_WK+4itRtQiJBtDnd5TfA5jrtrcF2qPAj0cnJ+U9Q@mail.gmail.com>

On Fri, Oct 16, 2026 at 03:09:55PM +0100, Peter Maydell wrote:
> On Fri, 16 Oct 2026 at 11:53, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Fri, Oct 16, 2026 at 11:14:16AM +0100, Peter Maydell wrote:
> > > On Fri, 16 Oct 2026 at 10:31, Daniel P. Berrangé <berrange@redhat.com> wrote:
> 
> > > > +#define qdev_realize_chain_parent(dev, dc, errp) \
> > > > +    DEVICE_CLASS(object_class_get_parent(OBJECT_CLASS(dc)))->realize(dev, errp)
> > >
> > > I'm tempted to suggest that we drop the 'dc' argument here and
> > > have the macro get the class from the dev:
> > >     DEVICE_CLASS(object_class_get_parent(object_get_class(OBJECT(dev))))->realize(dev,
> > > errp)
> > >
> > > because I think almost all realize methods wanting to chain back up
> > > won't have the class pointer to hand.
> > >
> > > We could maybe have an extra layer of abstraction here such that
> > > you write something like:
> > >
> > >    parent_invoke(DEVICE_CLASS, dev)->realize(dev, errp);
> > >
> > > Or is that trying to be too clever?
> >
> > This won't work if we have multiple levels in the class hierarchy
> > that need chaining up, as object_class_get_parent(object_get_class(dev))
> > will always just get the first level parent class of 'dev'.
> 
> Isn't that always what you want, though? In a class hierarchy
> Object->Device->A->B->C, C's realize method always wants to
> chain to B's realize method, and more generally "invoke the
> superclass method" from C wants B's implementation, not A's
> (assuming B actually implemented it).

Yes, C wants to invoke B's realize method, but then B also
wants to invoke A's realize method.

> > Somewhere/how we need to identify the current class level we're
> > calling from, so we know what parent to ask for.
> >
> > Another option is to do what GObject does and provide a simple
> > helper for getting the parent class, from OBJECT_DEFINE_TYPE*
> > macros:
> >
> >     ...
> >     static inline ObjectClass * \
> >     module_obj_name##_parent_class() { \
> >         return object_class_by_name(TYPE_##PARENT_MODULE_OBJ_NAME); \
> >     } \
> >     ...
> >
> > which would be used
> >
> >     DeviceClass *dc = DEVICE_CLASS(pl050_kbd_parent_class());
> >
> >     dc->realize(dev, errp);
> >
> > but many (most) of qdev impls don't use the relatively new
> > OBJECT_DEFINE_TYPE macros. They would have to instead explicitly
> > reference the parent type name:
> >
> >     DeviceClass *dc = DEVICE_CLASS(object_class_by_name(TYPE_PL050));
> >     dc->realize(dev, errp);
> 
> I still don't understand why we need to get the parent's
> object class by name here, rather than saying "give me
> the parent class of this object's class".

No matter which realize() method we are executing in, the "dev"
object parameter will always be an instance of the leaf class "C"
and thus the result of object_class_get_parent(objct_get_class(dev))
will always be B. That is only correct if executgnig "C"s realize
method, so breaks if we need to chain up realize many times.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-10-16 14:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 16:33 [PATCH] include/hw/core/qdev.h: Fix where device_class_set_parent_realize docs suggest putting parent_realize Peter Maydell
2026-10-15 16:44 ` Daniel P. Berrangé
2026-10-15 18:16   ` Peter Maydell
2026-10-16  9:15     ` Daniel P. Berrangé
2026-10-16  9:30       ` Daniel P. Berrangé
2026-10-16 10:14         ` Peter Maydell
2026-10-16 10:53           ` Daniel P. Berrangé
2026-10-16 14:09             ` Peter Maydell
2026-10-16 14:26               ` Daniel P. Berrangé [this message]
2026-10-16 14:30                 ` Peter Maydell
2026-10-16 13:11           ` Mark Cave-Ayland
2026-10-16 13:07         ` Mark Cave-Ayland
2026-10-16  9:09 ` Mark Cave-Ayland

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=atI0CCfUsBR2kqkB@redhat.com \
    --to=berrange@redhat.com \
    --cc=mark.caveayland@nutanix.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.