qdev: Fix QOM unrealize behavior
Since commit249d41720b
(qdev: Prepare "realized" property) setting realized = true would register the device's VMStateDescription, but realized = false would not unregister it. Fix that. Moving the code from unparenting also revealed that we were calling DeviceClass::init through DeviceClass::realize as interim solution but DeviceClass::exit still at unparenting time with a realized check. Make this symmetrical by implementing DeviceClass::unrealize to call it, while we're setting realized = false in the unparenting path. The only other unrealize user is mac_nvram, which can safely override it. Thus, mark DeviceClass::exit as obsolete, new devices should implement DeviceClass::unrealize instead. Cc: qemu-stable@nongnu.org Signed-off-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Andreas Färber <afaerber@suse.de> Message-id: 1366043650-9719-1-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commitfe6c211781
) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
0486c27a36
commit
4d7f4556fc
|
@ -96,7 +96,7 @@ typedef struct DeviceClass {
|
|||
/* Private to qdev / bus. */
|
||||
qdev_initfn init; /* TODO remove, once users are converted to realize */
|
||||
qdev_event unplug;
|
||||
qdev_event exit;
|
||||
qdev_event exit; /* TODO remove, once users are converted to unrealize */
|
||||
const char *bus_type;
|
||||
} DeviceClass;
|
||||
|
||||
|
|
25
hw/qdev.c
25
hw/qdev.c
|
@ -180,6 +180,19 @@ static void device_realize(DeviceState *dev, Error **err)
|
|||
}
|
||||
}
|
||||
|
||||
static void device_unrealize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_GET_CLASS(dev);
|
||||
|
||||
if (dc->exit) {
|
||||
int rc = dc->exit(dev);
|
||||
if (rc < 0) {
|
||||
error_setg(errp, "Device exit failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
|
||||
int required_for_version)
|
||||
{
|
||||
|
@ -692,6 +705,9 @@ static void device_set_realized(Object *obj, bool value, Error **err)
|
|||
device_reset(dev);
|
||||
}
|
||||
} else if (!value && dev->realized) {
|
||||
if (qdev_get_vmsd(dev)) {
|
||||
vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
|
||||
}
|
||||
if (dc->unrealize) {
|
||||
dc->unrealize(dev, &local_err);
|
||||
}
|
||||
|
@ -758,7 +774,6 @@ static void device_class_base_init(ObjectClass *class, void *data)
|
|||
static void device_unparent(Object *obj)
|
||||
{
|
||||
DeviceState *dev = DEVICE(obj);
|
||||
DeviceClass *dc = DEVICE_GET_CLASS(dev);
|
||||
BusState *bus;
|
||||
|
||||
while (dev->num_child_bus) {
|
||||
|
@ -766,12 +781,7 @@ static void device_unparent(Object *obj)
|
|||
qbus_free(bus);
|
||||
}
|
||||
if (dev->realized) {
|
||||
if (qdev_get_vmsd(dev)) {
|
||||
vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
|
||||
}
|
||||
if (dc->exit) {
|
||||
dc->exit(dev);
|
||||
}
|
||||
object_property_set_bool(obj, false, "realized", NULL);
|
||||
}
|
||||
if (dev->parent_bus) {
|
||||
bus_remove_child(dev->parent_bus, dev);
|
||||
|
@ -786,6 +796,7 @@ static void device_class_init(ObjectClass *class, void *data)
|
|||
|
||||
class->unparent = device_unparent;
|
||||
dc->realize = device_realize;
|
||||
dc->unrealize = device_unrealize;
|
||||
}
|
||||
|
||||
void device_reset(DeviceState *dev)
|
||||
|
|
Loading…
Reference in New Issue