qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
Date: Wed, 12 Dec 2012 16:16:33 -0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Wed, Dec 12, 2012 at 05:51:18PM +0100, Andreas Färber wrote:
> Am 12.12.2012 15:29, schrieb Eduardo Habkost:
> > On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas Färber wrote:
> >> Based on earlier patches by Paolo and me, introduce the QOM realizefn at
> >> device level only, as requested by Anthony.
> >>
> >> For now this just wraps the qdev initfn.
> 
> ...which it deprecates.

Good to know. I thought they had different purposes and I was missing
something.


[...]
> >> +static void device_realize(DeviceState *dev, Error **err)
> >> +{
> >> +    DeviceClass *dc = DEVICE_GET_CLASS(dev);
> >>  
> >> -    if (qdev_get_vmsd(dev)) {
> >> -        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
> >> -                                       dev->instance_id_alias,
> >> -                                       dev->alias_required_for_version);
> >> -    }
> >> -    dev->realized = true;
> >> -    if (dev->hotplugged) {
> >> -        device_reset(dev);
> >> +    if (dc->init) {
> >> +        int rc = dc->init(dev);
> >> +        if (rc < 0) {
> >> +            error_setg(err, "Device initialization failed.");
> >> +            return;
> >> +        }
> >>      }
> >> -    return 0;
> >>  }
> > [...]
> >> +static void device_class_init(ObjectClass *oc, void *data)
> >> +{
> >> +    DeviceClass *dc = DEVICE_CLASS(oc);
> >> +    dc->realize = device_realize;
> >> +}
> >> +
> > [...]
> > 
> > Stupid question: what exactly is the difference in capabilities and
> > semantics between DeviceClass.init() and DeviceClass.realize()? They
> > look exactly the same to me, from a first look. On which cases would
> > somebody use the former instead of the latter, and why?
> 
> Wherever possible, users should use the new DeviceClass::realize.
> 
> "init" or "initfn" clashes with QOM's instance_init name-wise.
> As shown in this series, instance_init can be used in devices today
> already, without having realize.

True. That's something I like in the new name.  :-)

> 
> The distinction between instance_init and realize is that the former
> initializes simple variables, sets up properties and anything the user
> may want to modify, then realize processes these variables and is able
> to fail and report the cause of failure (unlike DeviceClass::init).

I understood the difference between ObjectClass.instance_init() and
DeviceClass.init() (now called realize()), already. My question was
about the difference between DeviceClass.init() and
DeviceClass.realize().


> 
> In the isa patch after all the boring QOM'ish preparations, isa-device's
> class_init overwrites DeviceClass:realize, thereby no longer invoking
> any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus,
> etc. would need to be done in further steps, but a) this is work, b) the
> series shouldn't get too long for review/merge and c) it all depends on
> in which class and thereby with which signature we want to have realize
> - DeviceClass::realize(DeviceState *, Error **) or
> ObjectClass::realize(Object *, Error **).

So, just to check if I understood all correctly:

DeviceClass.init() is just the old and deprecated version of
DeviceClass.realize() (just because the former has no Error parameter),
but both have exactly the same semantics/purpose, and devices should now
use DeviceClass.realize() instead. Correct?

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]