Patchwork [RFC,2/3] qdev: Realize on machine creation done

login
register
mail settings
Submitter Andreas Färber
Date July 15, 2013, 1:40 p.m.
Message ID <1373895639-21476-3-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/259041/
State New
Headers show

Comments

Andreas Färber - July 15, 2013, 1:40 p.m.
As a preparation for Anthony's targetted late realization of devices,
iterate /machine children in qdev_machine_creation_done() and set
realized = true for devices.

Suggested-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/core/qdev.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Patch

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 33e874a..ec621cd 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -332,8 +332,37 @@  void qdev_free(DeviceState *dev)
     object_unparent(OBJECT(dev));
 }
 
+static int object_realize_one(Object *obj, void *opaque)
+{
+    Error **errp = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_DEVICE)) {
+        Error *err = NULL;
+
+        object_property_set_bool(obj, true, "realized", &err);
+        if (err != NULL) {
+            error_propagate(errp, err);
+            return -1;
+        }
+        return 0;
+    } else {
+        return object_child_foreach(obj, object_realize_one, opaque);
+    }
+}
+
 void qdev_machine_creation_done(void)
 {
+    Error *err = NULL;
+
+    object_child_foreach(qdev_get_machine(), object_realize_one, &err);
+    if (err != NULL) {
+        qerror_report_err(err);
+        error_free(err);
+        /* In the future we may want to let the user address any errors
+         * via QMP, but for now there's not much we can do here. */
+        exit(1);
+    }
+
     /*
      * ok, initial machine setup is done, starting from now we can
      * only create hotpluggable devices