Received: from eggs.gnu.org ([2001:4830:134:3::10]:49205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoT2X-0002AV-UZ for qemu-devel@nongnu.org; Tue, 20 Oct 2015 05:17:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoT2S-0005NQ-9H for qemu-devel@nongnu.org; Tue, 20 Oct 2015 05:17:05 -0400 Received: from e06smtp08.uk.ibm.com ([195.75.94.104]:42987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoT2S-0005NM-0K for qemu-devel@nongnu.org; Tue, 20 Oct 2015 05:17:00 -0400 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Oct 2015 10:16:58 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6BB20219005E for ; Tue, 20 Oct 2015 10:16:55 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t9K9Gvc835193072 for ; Tue, 20 Oct 2015 09:16:57 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t9K9GuNh007181 for ; Tue, 20 Oct 2015 03:16:57 -0600 From: Greg Kurz Date: Tue, 20 Oct 2015 11:16:53 +0200 Message-ID: <20151020091653.25419.99271.stgit@bahia.huguette.org> In-Reply-To: <20151020091640.25419.99985.stgit@bahia.huguette.org> References: <20151020091640.25419.99985.stgit@bahia.huguette.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v3 2/5] qdev: add the @unplug_is_blocked handler List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cornelia Huck , "Michael S. Tsirkin" , Alexander Graf , Andreas =?utf-8?q?F=C3=A4rber?= , aneesh.kumar@linux.vnet.ibm.com This handler allows to ask a device instance if it can be hot-unplugged. It is to be defined in device classes where hot-unpluggability depends on the device state (for example, virtio-9p devices cannot be unplugged if the 9p share is mounted in the guest). Signed-off-by: Greg Kurz --- hw/core/qdev.c | 4 ++++ include/hw/qdev-core.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 4ab04aa31e78..b37a3801117a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -287,6 +287,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) return; } + if (dc->unplug_is_blocked && !dc->unplug_is_blocked(dev, errp)) { + return; + } + qdev_hot_removed = true; hotplug_ctrl = qdev_get_hotplug_handler(dev); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 8057aedaa6c0..a65d2be6f39b 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -38,6 +38,7 @@ typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); typedef void (*BusRealize)(BusState *bus, Error **errp); typedef void (*BusUnrealize)(BusState *bus, Error **errp); +typedef bool (*HotUnplugBlocked)(DeviceState *dev, Error **errp); struct VMStateDescription; @@ -48,6 +49,8 @@ struct VMStateDescription; * property is changed to %true. The default invokes @init if not %NULL. * @unrealize: Callback function invoked when the #DeviceState:realized * property is changed to %false. + * @unplug_is_blocked: Callback function invoked by qdev_unplug(). Return %false + * to block hotunplug. * @init: Callback function invoked when the #DeviceState::realized property * is changed to %true. Deprecated, new types inheriting directly from * TYPE_DEVICE should use @realize instead, new leaf types should consult @@ -133,6 +136,7 @@ typedef struct DeviceClass { void (*reset)(DeviceState *dev); DeviceRealize realize; DeviceUnrealize unrealize; + HotUnplugBlocked unplug_is_blocked; /* device state */ const struct VMStateDescription *vmsd;