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/pci-hotplug.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'hw/pci-hotplug.c') diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 5c6307f..c55d8b9 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -32,6 +32,7 @@ #include "virtio-blk.h" #include "qemu-config.h" #include "blockdev.h" +#include "error.h" #if defined(TARGET_I386) static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, @@ -191,7 +192,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, dev = NULL; if (dev && dinfo) { if (scsi_hot_add(mon, &dev->qdev, dinfo, 0) != 0) { - qdev_unplug(&dev->qdev); + qdev_unplug(&dev->qdev, NULL); dev = NULL; } } @@ -258,6 +259,7 @@ static int pci_device_hot_remove(Monitor *mon, const char *pci_addr) PCIDevice *d; int dom, bus; unsigned slot; + Error *local_err = NULL; if (pci_read_devaddr(mon, pci_addr, &dom, &bus, &slot)) { return -1; @@ -268,7 +270,15 @@ static int pci_device_hot_remove(Monitor *mon, const char *pci_addr) monitor_printf(mon, "slot %d empty\n", slot); return -1; } - return qdev_unplug(&d->qdev); + + qdev_unplug(&d->qdev, &local_err); + if (error_is_set(&local_err)) { + monitor_printf(mon, "%s\n", error_get_pretty(local_err)); + error_free(local_err); + return -1; + } + + return 0; } void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict) -- cgit v1.1