From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5z7j-0007cC-HB for qemu-devel@nongnu.org; Mon, 27 Aug 2012 09:13:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T5z7i-0004fH-7b for qemu-devel@nongnu.org; Mon, 27 Aug 2012 09:12:59 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:32949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5z7i-0004es-3m for qemu-devel@nongnu.org; Mon, 27 Aug 2012 09:12:58 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Aug 2012 09:12:53 -0400 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 815E138C804F for ; Mon, 27 Aug 2012 09:12:49 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7RDClOR25428104 for ; Mon, 27 Aug 2012 09:12:48 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7RDClH8003089 for ; Mon, 27 Aug 2012 10:12:47 -0300 From: Anthony Liguori In-Reply-To: References: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> <1345996298-4892-9-git-send-email-aliguori@us.ibm.com> Date: Mon, 27 Aug 2012 08:12:37 -0500 Message-ID: <87a9xgh41m.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 8/9] qdev: make qdev_set_parent_bus() just set a link property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: Paolo Bonzini , Liu Ping Fan , qemu-devel@nongnu.org, Andreas Faerber liu ping fan writes: > On Sun, Aug 26, 2012 at 11:51 PM, Anthony Liguori wrote: >> Also make setting the link to NULL break the bus link >> >> Signed-off-by: Anthony Liguori >> --- >> hw/qdev.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ >> 1 files changed, 42 insertions(+), 6 deletions(-) >> >> diff --git a/hw/qdev.c b/hw/qdev.c >> index 86e1337..525a0cb 100644 >> --- a/hw/qdev.c >> +++ b/hw/qdev.c >> @@ -100,8 +100,7 @@ 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); >> + object_property_set_link(OBJECT(dev), OBJECT(bus), "parent_bus", NULL); >> } >> >> /* Create a new device. This only initializes the device state structure >> @@ -241,8 +240,8 @@ void qbus_reset_all_fn(void *opaque) >> /* can be used as ->unplug() callback for the simple cases */ >> int qdev_simple_unplug_cb(DeviceState *dev) >> { >> - /* just zap it */ >> - qdev_free(dev); >> + /* Unplug from parent bus via a forced eject */ >> + qdev_set_parent_bus(dev, NULL); > > I think it is more reliable to remove the reference property(child, > link) before object_finialize(). So when uplug-finish, we delete all > the refers: bus->child, bus<-child by _del_property not using > _set_property. object_finalize is called when ref=0. You cannot remove refs in finalize because by definition, ref=0. Regards, Anthony Liguori