[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/22] qdev: implement cleanup logic in finalize
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 19/22] qdev: implement cleanup logic in finalize |
Date: |
Wed, 1 Feb 2012 13:51:00 -0600 |
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 57 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 8f13e49..e3b53b7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -247,31 +247,6 @@ void qdev_init_nofail(DeviceState *dev)
/* Unlink device from bus and free the structure. */
void qdev_free(DeviceState *dev)
{
- BusState *bus;
- Property *prop;
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
-
- if (dev->state == DEV_STATE_INITIALIZED) {
- while (dev->num_child_bus) {
- bus = QLIST_FIRST(&dev->child_bus);
- qbus_free(bus);
- }
- if (qdev_get_vmsd(dev)) {
- vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
- }
- if (dc->exit) {
- dc->exit(dev);
- }
- if (dev->opts) {
- qemu_opts_del(dev->opts);
- }
- }
- QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
- for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
- if (prop->info->free) {
- prop->info->free(dev, prop);
- }
- }
object_delete(OBJECT(dev));
}
@@ -634,6 +609,37 @@ static void device_initfn(Object *obj)
object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
}
+/* Unlink device from bus and free the structure. */
+static void device_finalize(Object *obj)
+{
+ DeviceState *dev = DEVICE(obj);
+ BusState *bus;
+ Property *prop;
+ DeviceClass *dc = DEVICE_GET_CLASS(dev);
+
+ if (dev->state == DEV_STATE_INITIALIZED) {
+ while (dev->num_child_bus) {
+ bus = QLIST_FIRST(&dev->child_bus);
+ qbus_free(bus);
+ }
+ if (qdev_get_vmsd(dev)) {
+ vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
+ }
+ if (dc->exit) {
+ dc->exit(dev);
+ }
+ if (dev->opts) {
+ qemu_opts_del(dev->opts);
+ }
+ }
+ QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
+ for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
+ if (prop->info->free) {
+ prop->info->free(dev, prop);
+ }
+ }
+}
+
void device_reset(DeviceState *dev)
{
DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -648,6 +654,7 @@ static TypeInfo device_type_info = {
.parent = TYPE_OBJECT,
.instance_size = sizeof(DeviceState),
.instance_init = device_initfn,
+ .instance_finalize = device_finalize,
.abstract = true,
.class_size = sizeof(DeviceClass),
};
--
1.7.4.1
- [Qemu-devel] [PATCH 11/22] qdev: remove baked in notion of aliases (v2), (continued)
- [Qemu-devel] [PATCH 11/22] qdev: remove baked in notion of aliases (v2), Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 16/22] qdev: nuke qdev_init_chardev(), Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 15/22] qdev: split out UI portions into a new function, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 12/22] qom: add new command to search for types, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 17/22] qom: move properties from qdev to object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 20/22] info qdm: do not require a parent_bus to be set, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 21/22] object: sure up reference counting, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 09/22] qdev: register all types natively through QEMU Object Model, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 22/22] container: make a decendent of Object, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 19/22] qdev: implement cleanup logic in finalize,
Anthony Liguori <=
- [Qemu-devel] [PATCH 07/22] qom: allow object_class_foreach to take additional parameters to refine search, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 13/22] qdev: split out common init to instance_init, Anthony Liguori, 2012/02/01
- [Qemu-devel] [PATCH 18/22] qom: accept any compatible type when setting a link property, Anthony Liguori, 2012/02/01
- Re: [Qemu-devel] [PATCH 00/22] qom: use Type system to register all devices (v2), Anthony Liguori, 2012/02/03