From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T61am-0002E9-Up for qemu-devel@nongnu.org; Mon, 27 Aug 2012 11:51:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T61ag-0006Ju-HA for qemu-devel@nongnu.org; Mon, 27 Aug 2012 11:51:08 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:51539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T61ag-0006Jj-DL for qemu-devel@nongnu.org; Mon, 27 Aug 2012 11:51:02 -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 11:51:00 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 8AD97C90046 for ; Mon, 27 Aug 2012 11:50:21 -0400 (EDT) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7RFoIKY184900 for ; Mon, 27 Aug 2012 11:50:19 -0400 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7RFnA8K028166 for ; Mon, 27 Aug 2012 09:49:11 -0600 From: Anthony Liguori In-Reply-To: <503B8BAF.5080809@suse.de> References: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> <1345996298-4892-5-git-send-email-aliguori@us.ibm.com> <503B8BAF.5080809@suse.de> Date: Mon, 27 Aug 2012 10:49:01 -0500 Message-ID: <87a9xgmj2q.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 4/9] object: remove object_finalize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?utf-8?Q?F=C3=A4rber?= Cc: Paolo Bonzini , Liu Ping Fan , qemu-devel@nongnu.org Andreas F=C3=A4rber writes: > Am 26.08.2012 17:51, schrieb Anthony Liguori: >> Callers should just use object_unref >>=20 >> Signed-off-by: Anthony Liguori >> --- >> hw/qdev.c | 4 ---- >> include/qemu/object.h | 9 --------- >> qom/object.c | 2 +- >> 3 files changed, 1 insertions(+), 14 deletions(-) >>=20 >> diff --git a/hw/qdev.c b/hw/qdev.c >> index 6b61daa..fdee91f 100644 >> --- a/hw/qdev.c >> +++ b/hw/qdev.c >> @@ -678,13 +678,9 @@ static void device_initfn(Object *obj) >> static void device_finalize(Object *obj) >> { >> DeviceState *dev =3D DEVICE(obj); >> - BusState *bus; >> DeviceClass *dc =3D DEVICE_GET_CLASS(dev); >>=20=20 >> if (dev->state =3D=3D DEV_STATE_INITIALIZED) { >> - while (dev->num_child_bus) { >> - bus =3D QLIST_FIRST(&dev->child_bus); >> - } >> if (qdev_get_vmsd(dev)) { >> vmstate_unregister(dev, qdev_get_vmsd(dev), dev); >> } > > This seems to answer my remark on 3/9, should've been squashed into that > one. > >> diff --git a/include/qemu/object.h b/include/qemu/object.h >> index 487adcd..8bc9935 100644 >> --- a/include/qemu/object.h >> +++ b/include/qemu/object.h >> @@ -490,15 +490,6 @@ void object_initialize_with_type(void *data, Type t= ype); >> void object_initialize(void *obj, const char *typename); >>=20=20 >> /** >> - * object_finalize: >> - * @obj: The object to finalize. >> - * >> - * This function destroys and object without freeing the memory associa= ted with >> - * it. >> - */ >> -void object_finalize(void *obj); >> - >> -/** >> * object_dynamic_cast: >> * @obj: The object to cast. >> * @typename: The @typename to cast to. >> diff --git a/qom/object.c b/qom/object.c >> index 44135c3..1144f79 100644 >> --- a/qom/object.c >> +++ b/qom/object.c >> @@ -375,7 +375,7 @@ static void object_deinit(Object *obj, TypeImpl *typ= e) >> } >> } >>=20=20 >> -void object_finalize(void *data) >> +static void object_finalize(void *data) >> { >> Object *obj =3D data; >> TypeImpl *ti =3D obj->class->type; > > This is what I was referring to with breaking the encapsulation on 3/9: > When we have a PHB with embedded PCIDevice on its PCIBus, as > demonstrated with i440fx and prep_pci, then when doing object_delete() > on the whole thing I expect the main object's finalizer to call > object_finalize() on its embedded childs, forcing their uninit or an > assert if a programming error. Not just an unref that might or might not > finalize it. > > If however finalize is called only at refcount 0 then who will unref the > self-created children? Finalize would never be called due to pending > references by its children... The refs are stored as properties and when properties are removed during object destruction, those references are dropped. That is what takes the refcount to 0. We could add a g_assert(child->ref =3D=3D 1) before removing the property to catch programming errors. Regards, Anthony Liguori > > Andreas > > --=20 > SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany > GF: Jeff Hawn, Jennifer Guild, Felix Imend=C3=B6rffer; HRB 16746 AG N=C3= =BCrnberg