mirror of https://github.com/xqemu/xqemu.git
qdev-monitor: Propagate errors through qdev_device_add()
Also polish an error message while I'm touching the line anyway, Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
4caa489d13
commit
f006cf7fa9
|
@ -11,6 +11,6 @@ void hmp_info_qdm(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
|
void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
|
||||||
int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
|
||||||
int qdev_device_help(QemuOpts *opts);
|
int qdev_device_help(QemuOpts *opts);
|
||||||
DeviceState *qdev_device_add(QemuOpts *opts);
|
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -516,7 +516,7 @@ static BusState *qbus_find(const char *path, Error **errp)
|
||||||
return bus;
|
return bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceState *qdev_device_add(QemuOpts *opts)
|
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
|
||||||
{
|
{
|
||||||
DeviceClass *dc;
|
DeviceClass *dc;
|
||||||
const char *driver, *path, *id;
|
const char *driver, *path, *id;
|
||||||
|
@ -526,44 +526,38 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
|
|
||||||
driver = qemu_opt_get(opts, "driver");
|
driver = qemu_opt_get(opts, "driver");
|
||||||
if (!driver) {
|
if (!driver) {
|
||||||
qerror_report(QERR_MISSING_PARAMETER, "driver");
|
error_set(errp, QERR_MISSING_PARAMETER, "driver");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find driver */
|
/* find driver */
|
||||||
dc = qdev_get_device_class(&driver, &err);
|
dc = qdev_get_device_class(&driver, errp);
|
||||||
if (err) {
|
if (!dc) {
|
||||||
qerror_report_err(err);
|
|
||||||
error_free(err);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find bus */
|
/* find bus */
|
||||||
path = qemu_opt_get(opts, "bus");
|
path = qemu_opt_get(opts, "bus");
|
||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
bus = qbus_find(path, &err);
|
bus = qbus_find(path, errp);
|
||||||
if (!bus) {
|
if (!bus) {
|
||||||
qerror_report_err(err);
|
|
||||||
error_free(err);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!object_dynamic_cast(OBJECT(bus), dc->bus_type)) {
|
if (!object_dynamic_cast(OBJECT(bus), dc->bus_type)) {
|
||||||
qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
error_setg(errp, "Device '%s' can't go on %s bus",
|
||||||
"Device '%s' can't go on a %s bus",
|
driver, object_get_typename(OBJECT(bus)));
|
||||||
driver, object_get_typename(OBJECT(bus)));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (dc->bus_type != NULL) {
|
} else if (dc->bus_type != NULL) {
|
||||||
bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);
|
bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);
|
||||||
if (!bus || qbus_is_full(bus)) {
|
if (!bus || qbus_is_full(bus)) {
|
||||||
qerror_report(ERROR_CLASS_GENERIC_ERROR,
|
error_setg(errp, "No '%s' bus found for device '%s'",
|
||||||
"No '%s' bus found for device '%s'",
|
dc->bus_type, driver);
|
||||||
dc->bus_type, driver);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {
|
if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {
|
||||||
qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
|
error_set(errp, QERR_BUS_NO_HOTPLUG, bus->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +586,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
|
|
||||||
/* set properties */
|
/* set properties */
|
||||||
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
|
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
|
||||||
qerror_report_err(err);
|
error_propagate(errp, err);
|
||||||
object_unparent(OBJECT(dev));
|
object_unparent(OBJECT(dev));
|
||||||
object_unref(OBJECT(dev));
|
object_unref(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -601,12 +595,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
dev->opts = opts;
|
dev->opts = opts;
|
||||||
object_property_set_bool(OBJECT(dev), true, "realized", &err);
|
object_property_set_bool(OBJECT(dev), true, "realized", &err);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
qerror_report_err(err);
|
error_propagate(errp, err);
|
||||||
error_free(err);
|
|
||||||
dev->opts = NULL;
|
dev->opts = NULL;
|
||||||
object_unparent(OBJECT(dev));
|
object_unparent(OBJECT(dev));
|
||||||
object_unref(OBJECT(dev));
|
object_unref(OBJECT(dev));
|
||||||
qerror_report(QERR_DEVICE_INIT_FAILED, driver);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return dev;
|
return dev;
|
||||||
|
@ -779,8 +771,10 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dev = qdev_device_add(opts);
|
dev = qdev_device_add(opts, &local_err);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
7
vl.c
7
vl.c
|
@ -2276,11 +2276,14 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
|
||||||
|
|
||||||
static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
|
static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
|
||||||
{
|
{
|
||||||
|
Error *err = NULL;
|
||||||
DeviceState *dev;
|
DeviceState *dev;
|
||||||
|
|
||||||
dev = qdev_device_add(opts);
|
dev = qdev_device_add(opts, &err);
|
||||||
if (!dev)
|
if (!dev) {
|
||||||
|
error_report_err(err);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
object_unref(OBJECT(dev));
|
object_unref(OBJECT(dev));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue