Received: from eggs.gnu.org ([208.118.235.92]:49407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TioCH-0005tZ-V4 for qemu-devel@nongnu.org; Wed, 12 Dec 2012 10:26:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TioCB-0005A3-SP for qemu-devel@nongnu.org; Wed, 12 Dec 2012 10:26:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TioCB-00059s-Ll for qemu-devel@nongnu.org; Wed, 12 Dec 2012 10:26:03 -0500 Date: Wed, 12 Dec 2012 12:29:05 -0200 From: Eduardo Habkost Message-ID: <20121212142905.GA5334@otherpad.lan.raisama.net> References: <1353888766-6951-1-git-send-email-afaerber@suse.de> <1353888766-6951-5-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1353888766-6951-5-git-send-email-afaerber@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 Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas F=E4rber wrote: > Based on earlier patches by Paolo and me, introduce the QOM realizefn a= t > device level only, as requested by Anthony. >=20 > For now this just wraps the qdev initfn. >=20 > Signed-off-by: Paolo Bonzini > Signed-off-by: Andreas F=E4rber > Cc: Anthony Liguori > --- > hw/qdev-core.h | 4 +++ > hw/qdev.c | 100 ++++++++++++++++++++++++++++++++++++++++++------= -------- > 2 Dateien ge=E4ndert, 80 Zeilen hinzugef=FCgt(+), 24 Zeilen entfernt(-= ) >=20 > diff --git a/hw/qdev-core.h b/hw/qdev-core.h > index f0d3a5e..580a811 100644 > --- a/hw/qdev-core.h > +++ b/hw/qdev-core.h > @@ -29,6 +29,8 @@ enum { > typedef int (*qdev_initfn)(DeviceState *dev); > typedef int (*qdev_event)(DeviceState *dev); > typedef void (*qdev_resetfn)(DeviceState *dev); > +typedef void (*DeviceRealize)(DeviceState *dev, Error **err); > +typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err); > =20 > struct VMStateDescription; > =20 > @@ -47,6 +49,8 @@ typedef struct DeviceClass { > const struct VMStateDescription *vmsd; > =20 > /* Private to qdev / bus. */ > + DeviceRealize realize; > + DeviceUnrealize unrealize; > qdev_initfn init; > qdev_event unplug; > qdev_event exit; > diff --git a/hw/qdev.c b/hw/qdev.c > index bce6ad5..d7b6320 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const= char *type) > Return 0 on success. */ > int qdev_init(DeviceState *dev) > { > - DeviceClass *dc =3D DEVICE_GET_CLASS(dev); > - int rc; > + Error *local_err =3D NULL; > =20 > assert(!dev->realized); > =20 > - rc =3D dc->init(dev); > - if (rc < 0) { > + object_property_set_bool(OBJECT(dev), true, "realized", &local_err= ); > + if (local_err !=3D NULL) { > + error_free(local_err); > object_delete(OBJECT(dev)); > - return rc; > + return -1; > } > + return 0; > +} > =20 > - if (!OBJECT(dev)->parent) { > - static int unattached_count =3D 0; > - gchar *name =3D g_strdup_printf("device[%d]", unattached_count= ++); > - > - object_property_add_child(container_get(qdev_get_machine(), > - "/unattached"), > - name, OBJECT(dev), NULL); > - g_free(name); > - } > +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), de= v, > - dev->instance_id_alias, > - dev->alias_required_for_version= ); > - } > - 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; > +} > + [...] 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 Eduardo