From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaCUB-00060D-Ed for qemu-devel@nongnu.org; Mon, 12 Dec 2011 15:28:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaCUA-00020G-1d for qemu-devel@nongnu.org; Mon, 12 Dec 2011 15:28:31 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:57153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaCU9-0001xC-R0 for qemu-devel@nongnu.org; Mon, 12 Dec 2011 15:28:30 -0500 Received: by iagj37 with SMTP id j37so3206961iag.4 for ; Mon, 12 Dec 2011 12:28:29 -0800 (PST) Message-ID: <4EE663E9.1070905@codemonkey.ws> Date: Mon, 12 Dec 2011 14:28:25 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1323721273-32404-1-git-send-email-aliguori@us.ibm.com> <1323721273-32404-2-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1323721273-32404-2-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino On 12/12/2011 02:17 PM, Anthony Liguori wrote: > To ensure that a device isn't removed from the graph until all of its links are > broken. > > Signed-off-by: Anthony Liguori Sorry, my mail script went awry :-( Ignore this series. Regards, Anthony Liguori > --- > hw/qdev.c | 16 ++++++++++++++++ > hw/qdev.h | 26 ++++++++++++++++++++++++++ > 2 files changed, 42 insertions(+), 0 deletions(-) > > diff --git a/hw/qdev.c b/hw/qdev.c > index 106407f..fdc9843 100644 > --- a/hw/qdev.c > +++ b/hw/qdev.c > @@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev) > } > assert(dev->info->unplug != NULL); > > + if (dev->ref != 0) { > + qerror_report(QERR_DEVICE_IN_USE, dev->id?:""); > + return -1; > + } > + > qdev_hot_removed = true; > > return dev->info->unplug(dev); > @@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev) > > return strdup(path); > } > + > +void qdev_ref(DeviceState *dev) > +{ > + dev->ref++; > +} > + > +void qdev_unref(DeviceState *dev) > +{ > + g_assert(dev->ref> 0); > + dev->ref--; > +} > diff --git a/hw/qdev.h b/hw/qdev.h > index 36a4198..2397b4e 100644 > --- a/hw/qdev.h > +++ b/hw/qdev.h > @@ -45,6 +45,12 @@ struct DeviceState { > QTAILQ_ENTRY(DeviceState) sibling; > int instance_id_alias; > int alias_required_for_version; > + > + /** > + * This tracks the number of references between devices. See @qdev_ref for > + * more information. > + */ > + uint32_t ref; > }; > > typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); > @@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev); > /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ > extern struct BusInfo system_bus_info; > > +/** > + * @qdev_ref > + * > + * Increase the reference count of a device. A device cannot be freed as long > + * as its reference count is greater than zero. > + * > + * @dev - the device > + */ > +void qdev_ref(DeviceState *dev); > + > +/** > + * @qdef_unref > + * > + * Decrease the reference count of a device. A device cannot be freed as long > + * as its reference count is greater than zero. > + * > + * @dev - the device > + */ > +void qdev_unref(DeviceState *dev); > + > #endif