From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Anthony Liguori" <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH RFC 1/3] qdev: Add support for recursive realization
Date: Mon, 15 Jul 2013 15:40:37 +0200 [thread overview]
Message-ID: <1373895639-21476-2-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1373895639-21476-1-git-send-email-afaerber@suse.de>
Add realize_children and unrealize_children QOM methods to DeviceClass.
Call them after realized = true and before realized = false respectively.
The default implementation walks busses and realizes their devices.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[AF: Transferred from Object to DeviceState]
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/core/qdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----
include/hw/qdev-core.h | 4 ++++
2 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 9190a7e..33e874a 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -183,6 +183,29 @@ static void device_realize(DeviceState *dev, Error **err)
}
}
+static int device_realize_one(DeviceState *dev, void *opaque)
+{
+ Error **errp = opaque;
+ Error *err = NULL;
+
+ object_property_set_bool(OBJECT(dev), true, "realized", &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ return -1;
+ }
+ return 0;
+}
+
+static int bus_realize_children(BusState *bus, void *opaque)
+{
+ return qbus_walk_children(bus, device_realize_one, NULL, opaque);
+}
+
+static void device_realize_children(DeviceState *dev, Error **errp)
+{
+ qdev_walk_children(dev, NULL, bus_realize_children, errp);
+}
+
static void device_unrealize(DeviceState *dev, Error **errp)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -196,6 +219,29 @@ static void device_unrealize(DeviceState *dev, Error **errp)
}
}
+static int device_unrealize_one(DeviceState *dev, void *opaque)
+{
+ Error **errp = opaque;
+ Error *err = NULL;
+
+ object_property_set_bool(OBJECT(dev), false, "realized", &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ return -1;
+ }
+ return 0;
+}
+
+static int bus_unrealize_children(BusState *bus, void *opaque)
+{
+ return qbus_walk_children(bus, device_unrealize_one, NULL, opaque);
+}
+
+static void device_unrealize_children(DeviceState *dev, Error **errp)
+{
+ qdev_walk_children(dev, NULL, bus_unrealize_children, errp);
+}
+
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version)
{
@@ -678,7 +724,7 @@ static bool device_get_realized(Object *obj, Error **err)
return dev->realized;
}
-static void device_set_realized(Object *obj, bool value, Error **err)
+static void device_set_realized(Object *obj, bool value, Error **errp)
{
DeviceState *dev = DEVICE(obj);
DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -704,24 +750,26 @@ static void device_set_realized(Object *obj, bool value, Error **err)
dev->instance_id_alias,
dev->alias_required_for_version);
}
+ dev->realized = true;
+ dc->realize_children(dev, errp);
if (dev->hotplugged && local_err == NULL) {
device_reset(dev);
}
} else if (!value && dev->realized) {
+ dc->unrealize_children(dev, errp);
if (qdev_get_vmsd(dev)) {
vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
}
if (dc->unrealize) {
dc->unrealize(dev, &local_err);
}
+ dev->realized = false;
}
if (local_err != NULL) {
- error_propagate(err, local_err);
+ error_propagate(errp, local_err);
return;
}
-
- dev->realized = value;
}
static void device_initfn(Object *obj)
@@ -825,7 +873,9 @@ static void device_class_init(ObjectClass *class, void *data)
class->unparent = device_unparent;
dc->realize = device_realize;
+ dc->realize_children = device_realize_children;
dc->unrealize = device_unrealize;
+ dc->unrealize_children = device_unrealize_children;
}
void device_reset(DeviceState *dev)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 7fbffcb..81dc2f3 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -21,7 +21,9 @@ typedef int (*qdev_initfn)(DeviceState *dev);
typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
+typedef void (*DeviceRealizeChildren)(DeviceState *dev, Error **errp);
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
+typedef void (*DeviceUnrealizeChildren)(DeviceState *dev, Error **errp);
struct VMStateDescription;
@@ -88,7 +90,9 @@ typedef struct DeviceClass {
/* callbacks */
void (*reset)(DeviceState *dev);
DeviceRealize realize;
+ DeviceRealizeChildren realize_children;
DeviceUnrealize unrealize;
+ DeviceUnrealizeChildren unrealize_children;
/* device state */
const struct VMStateDescription *vmsd;
--
1.8.1.4
next prev parent reply other threads:[~2013-07-15 13:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-15 13:40 [Qemu-devel] [PATCH RFC 0/3] Recursive QOM realize Andreas Färber
2013-07-15 13:40 ` Andreas Färber [this message]
2013-07-15 13:40 ` [Qemu-devel] [PATCH RFC 2/3] qdev: Realize on machine creation done Andreas Färber
2013-07-15 13:40 ` [Qemu-devel] [PATCH RFC 3/3] qdev: Assert no new devices get created during realization Andreas Färber
2013-07-15 14:43 ` [Qemu-devel] [PATCH RFC 0/3] Recursive QOM realize Paolo Bonzini
2013-07-15 15:06 ` Andreas Färber
2013-07-15 15:37 ` Paolo Bonzini
2013-07-16 12:19 ` Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1373895639-21476-2-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).