[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 14/15] qdev_device_add(): push error handling/con
From: |
Laszlo Ersek |
Subject: |
[Qemu-devel] [PATCH v2 14/15] qdev_device_add(): push error handling/consumption to callers |
Date: |
Tue, 5 Feb 2013 21:39:27 +0100 |
Conversion status (call chains covered or substituted by error propagation
marked with square brackets):
do_device_add -> [qemu_find_opts -> error_report]
do_device_add -> [qdev_device_add -> qerror_report]
do_device_add -> [qdev_device_add -> qbus_find -> qbus_find_recursive
-> qerror_report]
do_device_add -> [qdev_device_add -> qbus_find -> qerror_report]
do_device_add -> [qdev_device_add -> set_property -> qdev_prop_parse
-> qerror_report_err]
Signed-off-by: Laszlo Ersek <address@hidden>
---
hw/qdev-monitor.c | 27 +++++++++++++--------------
vl.c | 8 ++++++--
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index a7f73dc..47b8e13 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -464,7 +464,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
driver = qemu_opt_get(opts, "driver");
if (!driver) {
- qerror_report(QERR_MISSING_PARAMETER, "driver");
+ error_set(errp, QERR_MISSING_PARAMETER, "driver");
return NULL;
}
@@ -480,7 +480,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
}
if (!obj) {
- qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
return NULL;
}
@@ -491,13 +491,12 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
if (path != NULL) {
bus = qbus_find(path, &local_err);
if (error_is_set(&local_err)) {
- qerror_report_err(local_err);
- error_free(local_err);
+ error_propagate(errp, local_err);
return NULL;
}
if (!object_dynamic_cast(OBJECT(bus), k->bus_type)) {
- qerror_report(QERR_BAD_BUS_FOR_DEVICE,
- driver, object_get_typename(OBJECT(bus)));
+ error_set(errp, QERR_BAD_BUS_FOR_DEVICE,
+ driver, object_get_typename(OBJECT(bus)));
return NULL;
}
} else {
@@ -505,13 +504,12 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
&local_err);
if (!bus) {
assert(!error_is_set(&local_err));
- qerror_report(QERR_NO_BUS_FOR_DEVICE,
- k->bus_type, driver);
+ error_set(errp, QERR_NO_BUS_FOR_DEVICE, k->bus_type, driver);
return NULL;
}
}
if (qdev_hotplug && !bus->allow_hotplug) {
- qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
+ error_set(errp, QERR_BUS_NO_HOTPLUG, bus->name);
return NULL;
}
@@ -532,8 +530,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
PropertyContext ctx = { .dev = qdev, .errp = &local_err };
if (qemu_opt_foreach(opts, set_property, &ctx, 1) != 0) {
- qerror_report_err(local_err);
- error_free(local_err);
+ error_propagate(errp, local_err);
qdev_free(qdev);
return NULL;
}
@@ -550,7 +547,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
g_free(name);
}
if (qdev_init(qdev) < 0) {
- qerror_report(QERR_DEVICE_INIT_FAILED, driver);
+ error_set(errp, QERR_DEVICE_INIT_FAILED, driver);
return NULL;
}
qdev->opts = opts;
@@ -666,8 +663,10 @@ int do_device_add(Monitor *mon, const QDict *qdict,
QObject **ret_data)
qemu_opts_del(opts);
return 0;
}
- dev = qdev_device_add(opts, NULL);
- if (!dev) {
+ dev = qdev_device_add(opts, &local_err);
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ error_free(local_err);
qemu_opts_del(opts);
return -1;
}
diff --git a/vl.c b/vl.c
index 1860662..dc75bbd 100644
--- a/vl.c
+++ b/vl.c
@@ -2279,10 +2279,14 @@ static int device_help_func(QemuOpts *opts, void
*opaque)
static int device_init_func(QemuOpts *opts, void *opaque)
{
DeviceState *dev;
+ Error *local_err = NULL;
- dev = qdev_device_add(opts, NULL);
- if (!dev)
+ dev = qdev_device_add(opts, &local_err);
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return -1;
+ }
object_unref(OBJECT(dev));
return 0;
}
--
1.7.1
- Re: [Qemu-devel] [PATCH v2 06/15] set_property(): extend signature with Error, (continued)
- [Qemu-devel] [PATCH v2 07/15] set_property(): push error handling to callers, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 12/15] qbus_find(): propagate error handling / consumption to callers, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 11/15] qbus_find(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 15/15] qdev_device_add(): beautify "driver not found" error message, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 09/15] qbus_find_recursive(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 08/15] qbus_find_recursive(): reorganize, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 13/15] qdev_device_add(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 14/15] qdev_device_add(): push error handling/consumption to callers,
Laszlo Ersek <=
- [Qemu-devel] [PATCH v2 10/15] qbus_find_recursive(): push Error and make it terminate a recursive search, Laszlo Ersek, 2013/02/05
- Re: [Qemu-devel] [PATCH v2 00/15] propagate Errors to do_device_add(), Luiz Capitulino, 2013/02/08