From 56f9107e439c32aa00d58d117a9b664551328f1e Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Wed, 14 Mar 2012 17:37:38 -0300 Subject: qdev: qdev_unplug(): use error_set() It currently uses qerror_report(), but next commit will convert the drive_del command to the QAPI and this requires using error_set(). One particularity of qerror_report() is that it knows when it's running on monitor context or command-line context and prints the error message accordingly. error_set() doesn't do this, so we have to be careful not to drop error messages. qdev_unplug() has three kinds of usages: 1. It's called when hot adding a device fails, to undo anything that has been done before hitting the error 2. It's called by function monitor functions like device_del(), to unplug a device 3. It's used by xen_platform.c in a way that doesn't _seem_ to be in monitor context Only item 2 can print an error message to the user, this commit maintains that. Signed-off-by: Luiz Capitulino Reviewed-by: Stefan Hajnoczi --- hw/qdev-monitor.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'hw/qdev-monitor.c') diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 4783366cf4..fd56afed45 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -573,6 +573,7 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); + Error *local_err = NULL; DeviceState *dev; dev = qdev_find_recursive(sysbus_get_default(), id); @@ -580,7 +581,15 @@ int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data) qerror_report(QERR_DEVICE_NOT_FOUND, id); return -1; } - return qdev_unplug(dev); + + qdev_unplug(dev, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return 0; } void qdev_machine_init(void) -- cgit 1.4.1