From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SlfoW-0003cA-B2 for qemu-devel@nongnu.org; Mon, 02 Jul 2012 08:33:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SlfoH-0008WB-5o for qemu-devel@nongnu.org; Mon, 02 Jul 2012 08:33:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SlfoG-0008Vm-U2 for qemu-devel@nongnu.org; Mon, 02 Jul 2012 08:32:57 -0400 Message-ID: <4FF194F4.2010500@redhat.com> Date: Mon, 02 Jul 2012 14:32:52 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1340664222-25098-1-git-send-email-aliguori@us.ibm.com> <1340664222-25098-3-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1340664222-25098-3-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/4] qdev: add realized property and make adding child bus implied by realize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org, Markus Armbruster , Amit Shah , Andreas Faerber Why does this lack recursive realization? (I'm not top posting, I'm replying to the commit message. :)) Paolo Il 26/06/2012 00:43, Anthony Liguori ha scritto: > Signed-off-by: Anthony Liguori > --- > hw/qdev.c | 36 +++++++++++++++++++++++++++++++++++- > 1 files changed, 35 insertions(+), 1 deletions(-) > > diff --git a/hw/qdev.c b/hw/qdev.c > index a6c4c02..d305128 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -101,7 +101,6 @@ static void bus_add_child(BusState *bus, DeviceState *child) > void qdev_set_parent_bus(DeviceState *dev, BusState *bus) > { > dev->parent_bus = bus; > - bus_add_child(bus, dev); > } > > /* Create a new device. This only initializes the device state structure > @@ -157,6 +156,10 @@ int qdev_init(DeviceState *dev) > > assert(dev->state == DEV_STATE_CREATED); > > + if (dev->parent_bus) { > + bus_add_child(dev->parent_bus, dev); > + } > + > rc = dc->init(dev); > if (rc < 0) { > object_unparent(OBJECT(dev)); > @@ -663,6 +666,33 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, > assert_no_error(local_err); > } > > +static bool qdev_prop_get_realized(Object *obj, Error **errp) > +{ > + DeviceState *dev = DEVICE(obj); > + > + return (dev->state == DEV_STATE_INITIALIZED); > +} > + > +static void qdev_prop_set_realized(Object *obj, bool value, Error **errp) > +{ > + DeviceState *dev = DEVICE(obj); > + bool realized = (dev->state == DEV_STATE_INITIALIZED); > + > + if (realized == value) { > + return; > + } > + > + if (realized && !value) { > + error_set(errp, QERR_PERMISSION_DENIED); > + return; > + } > + > + if (qdev_init(dev) < 0) { > + error_set(errp, QERR_DEVICE_INIT_FAILED, ""); > + return; > + } > +} > + > static void device_initfn(Object *obj) > { > DeviceState *dev = DEVICE(obj); > @@ -687,6 +717,10 @@ static void device_initfn(Object *obj) > } while (class != object_class_by_name(TYPE_DEVICE)); > qdev_prop_set_globals(dev); > > + object_property_add_bool(obj, "realized", > + qdev_prop_get_realized, qdev_prop_set_realized, > + NULL); > + > object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS, > (Object **)&dev->parent_bus, NULL); > } >