qdev: Improve qdev_init_nofail()'s error reporting
authorMarkus Armbruster <armbru@redhat.com>
Wed, 4 Feb 2015 17:33:01 +0000 (18:33 +0100)
committerAndreas Färber <afaerber@suse.de>
Mon, 16 Feb 2015 15:17:57 +0000 (16:17 +0100)
We get two error messages: a specific one from qdev_init(), and a
generic one from qdev_init_nofail().  The specific one gets suppressed
in QMP context.  qdev_init_nofail() failing there is a bug, though.

Cut out the qdev_init() middle-man: realize the device, and on error
exit with a single error message.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
hw/core/qdev.c

index ff81f675da29dd2e35791dc4b4d05d7e5483fa75..10bf086a0af6c09878f3783acdae0b2dafc3baa2 100644 (file)
@@ -373,10 +373,15 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
    way is somewhat unclean, and best avoided.  */
 void qdev_init_nofail(DeviceState *dev)
 {
-    const char *typename = object_get_typename(OBJECT(dev));
+    Error *err = NULL;
+
+    assert(!dev->realized);
 
-    if (qdev_init(dev) < 0) {
-        error_report("Initialization of device %s failed", typename);
+    object_property_set_bool(OBJECT(dev), true, "realized", &err);
+    if (err) {
+        error_report("Initialization of device %s failed: %s",
+                     object_get_typename(OBJECT(dev)),
+                     error_get_pretty(err));
         exit(1);
     }
 }