qom: trigger unrealized when device_finalize
PATCH 1/1 qom: trigger unrealized when device_finalize
Currently, unrealized is triggered in device_unparent(). But unrealized normally involves the reclaim of resource occupied by DeviceState. To obey the idiom that reclaiming resource when refcnt reach zero, move it on the path of object_finalize().
As for device_unparent(), it would be the place to detach the device from the other system.
--- hw/core/qdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/core/qdev.c +4 -3
@@ -768,6 +768,10 @@ static void device_initfn(Object *obj)static void device_finalize (Object *obj) {DeviceState *dev =DEVICE (obj); + +if (dev->realized) { +object_property_set_bool (obj, false,"realized" ,NULL ); + }if (dev->opts) {qemu_opts_del (dev->opts); }
@@ -794,9 +798,6 @@ static void device_unparent(Object *obj) bus =QLIST_FIRST (&dev->child_bus);qbus_free (bus); } -if (dev->realized) { -object_property_set_bool (obj, false,"realized" ,NULL ); - }if (dev->parent_bus) {bus_remove_child (dev->parent_bus, dev);object_unref (OBJECT (dev->parent_bus));
Signature · 1 line
1.8.1.4
Il 05/07/2013 05:26, Liu Ping Fan ha scritto:
Quoted 7 lines
Currently, unrealized is triggered in
device_unparent(). But unrealized normally involves the reclaim of resource occupied by DeviceState. To obey the idiom that reclaiming resource when refcnt reach zero, move it on the path ofobject_finalize().As for
device_unparent(), it would be the place to detach the device from the other system.
This is wrong, unrealize is where the resources should be made invisible to the guest. This removes a bunch of references to the memory regions (from the flatview, from the parent region, etc.). Ultimately causes finalization to be called (after we add RCU, finalization will happen at the next grace period, because some of the references are removed from call_rcu callbacks).
What you want is
http://permalink.gmane.org/gmane.comp.emulators.qemu/214871.
Paolo
Quoted 31 lines
Signed-off-by Liu Ping Fan <[email protected]>--- hw/core/qdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/core/qdev.c +4
-3@@ -768,6 +768,10 @@ static void device_initfn(Object *obj)static void device_finalize (Object *obj) {DeviceState *dev =DEVICE (obj); + +if (dev->realized) { +object_property_set_bool (obj, false,"realized" ,NULL ); + }if (dev->opts) {qemu_opts_del (dev->opts); }@@ -794,9 +798,6 @@ static void device_unparent(Object *obj) bus =QLIST_FIRST (&dev->child_bus);qbus_free (bus); } -if (dev->realized) { -object_property_set_bool (obj, false,"realized" ,NULL ); - }if (dev->parent_bus) {bus_remove_child (dev->parent_bus, dev);object_unref (OBJECT (dev->parent_bus));