[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/15] qdev: Fix QOM unrealize behavior
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 02/15] qdev: Fix QOM unrealize behavior |
Date: |
Tue, 14 May 2013 16:52:59 -0500 |
From: Andreas Färber <address@hidden>
Since commit 249d41720b7dfbb5951b430b9eefdbee7464f515 (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: address@hidden
Signed-off-by: Andreas Färber <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
Message-id: address@hidden
Signed-off-by: Anthony Liguori <address@hidden>
(cherry picked from commit fe6c211781f80ef4fc246269cecbbc21981089f0)
Signed-off-by: Michael Roth <address@hidden>
---
hw/qdev-core.h | 2 +-
hw/qdev.c | 25 ++++++++++++++++++-------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index 2486f36..cc5bb2a 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -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;
diff --git a/hw/qdev.c b/hw/qdev.c
index 689cd54..1cbd910 100644
--- a/hw/qdev.c
+++ b/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)
--
1.7.9.5
- [Qemu-devel] Patch Round-up for stable 1.4.2, freeze on Monday, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 01/15] nbd: unlock mutex in nbd_co_send_request() error path, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 02/15] qdev: Fix QOM unrealize behavior,
Michael Roth <=
- [Qemu-devel] [PATCH 03/15] rng random backend: check for -EAGAIN errors on read, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 04/15] tap: properly initialize vhostfds, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 05/15] virtio-ccw: Check indicators location., Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 06/15] configure: Pick up libseccomp include path, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 07/15] target-mips: Fix accumulator arguments to gen_helper_dmult(u), Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 08/15] tcg/optimize: fix setcond2 optimization, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 09/15] qga: set umask 0077 when daemonizing (CVE-2013-2007), Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 10/15] tcg: Document tcg_qemu_tb_exec() and provide constants for low bit uses, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 11/15] cpu-exec: wrap tcg_qemu_tb_exec() in a fn to restore the PC, Michael Roth, 2013/05/14
- [Qemu-devel] [PATCH 12/15] Handle CPU interrupts by inline checking of a flag, Michael Roth, 2013/05/14