Received: from eggs.gnu.org ([208.118.235.92]:52374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tiqpl-0002QK-LZ for qemu-devel@nongnu.org; Wed, 12 Dec 2012 13:15:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tiqpf-00031u-AE for qemu-devel@nongnu.org; Wed, 12 Dec 2012 13:15:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tiqpf-00031q-2D for qemu-devel@nongnu.org; Wed, 12 Dec 2012 13:14:59 -0500 Date: Wed, 12 Dec 2012 16:16:33 -0200 From: Eduardo Habkost Message-ID: <20121212181633.GH3236@otherpad.lan.raisama.net> References: <1353888766-6951-1-git-send-email-afaerber@suse.de> <1353888766-6951-5-git-send-email-afaerber@suse.de> <20121212142905.GA5334@otherpad.lan.raisama.net> <50C8B606.4000102@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <50C8B606.4000102@suse.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: Paolo Bonzini , qemu-devel@nongnu.org, anthony@codemonkey.ws On Wed, Dec 12, 2012 at 05:51:18PM +0100, Andreas F=E4rber wrote: > Am 12.12.2012 15:29, schrieb Eduardo Habkost: > > On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas F=E4rber wrote: > >> Based on earlier patches by Paolo and me, introduce the QOM realizef= n at > >> device level only, as requested by Anthony. > >> > >> For now this just wraps the qdev initfn. >=20 > ...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 =3D DEVICE_GET_CLASS(dev); > >> =20 > >> - 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_vers= ion); > >> - } > >> - dev->realized =3D true; > >> - if (dev->hotplugged) { > >> - device_reset(dev); > >> + if (dc->init) { > >> + int rc =3D 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 =3D DEVICE_CLASS(oc); > >> + dc->realize =3D device_realize; > >> +} > >> + > > [...] > >=20 > > 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? >=20 > Wherever possible, users should use the new DeviceClass::realize. >=20 > "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. :-) >=20 > 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(). >=20 > 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) th= e > 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? --=20 Eduardo