Patchwork [RFC,3/3] qdev: Assert no new devices get created during realization

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

Comments

Andreas Färber - July 15, 2013, 1:40 p.m.
This is safe because current devices are already realized at this point
and busses are not devices.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/core/qdev.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index ec621cd..e86e72d 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -33,6 +33,7 @@ 
 #include "qapi/qmp/qjson.h"
 #include "monitor/monitor.h"
 
+static bool devices_realizing;
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
 static bool qdev_hot_removed = false;
@@ -354,7 +355,9 @@  void qdev_machine_creation_done(void)
 {
     Error *err = NULL;
 
+    devices_realizing = true;
     object_child_foreach(qdev_get_machine(), object_realize_one, &err);
+    devices_realizing = false;
     if (err != NULL) {
         qerror_report_err(err);
         error_free(err);
@@ -808,6 +811,8 @@  static void device_initfn(Object *obj)
     Property *prop;
     Error *err = NULL;
 
+    assert(!devices_realizing);
+
     if (qdev_hotplug) {
         dev->hotplugged = 1;
         qdev_hot_added = true;