From patchwork Thu Mar 29 16:56:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 149431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D7E1B6EF3 for ; Fri, 30 Mar 2012 03:57:02 +1100 (EST) Received: from localhost ([::1]:52336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDIei-00066Z-2Q for incoming@patchwork.ozlabs.org; Thu, 29 Mar 2012 12:57:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDIeT-00063X-A7 for qemu-devel@nongnu.org; Thu, 29 Mar 2012 12:56:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SDIeR-0004gn-6r for qemu-devel@nongnu.org; Thu, 29 Mar 2012 12:56:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12245) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SDIeQ-0004ga-Ul for qemu-devel@nongnu.org; Thu, 29 Mar 2012 12:56:43 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2TGudeD029155 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Mar 2012 12:56:39 -0400 Received: from localhost (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2TGucYe020962; Thu, 29 Mar 2012 12:56:39 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 29 Mar 2012 13:56:41 -0300 Message-Id: <1333040202-11225-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1333040202-11225-1-git-send-email-lcapitulino@redhat.com> References: <1333040202-11225-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 1/2] qdev: qdev_unplug(): use error_set() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/pci-hotplug.c | 14 ++++++++++++-- hw/qdev-monitor.c | 11 ++++++++++- hw/qdev.c | 12 ++++++++---- hw/qdev.h | 3 ++- hw/usb/dev-storage.c | 2 +- hw/xen_platform.c | 4 ++-- 6 files changed, 35 insertions(+), 11 deletions(-) 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) diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index a310cc7..e952238 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -577,6 +577,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); @@ -584,7 +585,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) diff --git a/hw/qdev.c b/hw/qdev.c index ee21d90..8b0ad19 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -28,6 +28,7 @@ #include "net.h" #include "qdev.h" #include "sysemu.h" +#include "error.h" int qdev_hotplug = 0; static bool qdev_hot_added = false; @@ -172,19 +173,22 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, dev->alias_required_for_version = required_for_version; } -int qdev_unplug(DeviceState *dev) +void qdev_unplug(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); if (!dev->parent_bus->allow_hotplug) { - qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); - return -1; + error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); + return; } assert(dc->unplug != NULL); qdev_hot_removed = true; - return dc->unplug(dev); + if (dc->unplug(dev) < 0) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } } static int qdev_reset_one(DeviceState *dev, void *opaque) diff --git a/hw/qdev.h b/hw/qdev.h index 9cc3f98..11f77cf 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -7,6 +7,7 @@ #include "qemu-option.h" #include "qapi/qapi-visit-core.h" #include "qemu/object.h" +#include "error.h" typedef struct Property Property; @@ -148,7 +149,7 @@ int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; void qdev_init_nofail(DeviceState *dev); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version); -int qdev_unplug(DeviceState *dev); +void qdev_unplug(DeviceState *dev, Error **errp); void qdev_free(DeviceState *dev); int qdev_simple_unplug_cb(DeviceState *dev); void qdev_machine_creation_done(void); diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index bdbe7bd..d865a5e 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -499,7 +499,7 @@ static void usb_msd_password_cb(void *opaque, int err) err = usb_device_attach(&s->dev); if (err) - qdev_unplug(&s->dev.qdev); + qdev_unplug(&s->dev.qdev, NULL); } static const struct SCSIBusInfo usb_msd_scsi_info = { diff --git a/hw/xen_platform.c b/hw/xen_platform.c index 5a7c4cc..a9c52a6 100644 --- a/hw/xen_platform.c +++ b/hw/xen_platform.c @@ -87,7 +87,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d) { if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_NETWORK_ETHERNET) { - qdev_unplug(&(d->qdev)); + qdev_unplug(&(d->qdev), NULL); } } @@ -100,7 +100,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d) { if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_STORAGE_IDE) { - qdev_unplug(&(d->qdev)); + qdev_unplug(&(d->qdev), NULL); } }