From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlYxy-0007zr-J2 for qemu-devel@nongnu.org; Mon, 12 Oct 2015 05:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlYxv-0006y0-TM for qemu-devel@nongnu.org; Mon, 12 Oct 2015 05:00:22 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:37006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlYxv-0006xo-Lh for qemu-devel@nongnu.org; Mon, 12 Oct 2015 05:00:19 -0400 Received: from localhost by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Oct 2015 10:00:18 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 9E030219005C for ; Mon, 12 Oct 2015 10:00:13 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t9C90FWx29163694 for ; Mon, 12 Oct 2015 09:00:15 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t9C80Fft021204 for ; Mon, 12 Oct 2015 02:00:15 -0600 From: Greg Kurz Date: Mon, 12 Oct 2015 11:00:13 +0200 Message-ID: <20151012090008.10877.13169.stgit@bahia.huguette.org> In-Reply-To: <20151012085708.10877.51489.stgit@bahia.huguette.org> References: <20151012085708.10877.51489.stgit@bahia.huguette.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v2 2/5] qdev: add the HotUnpluggable 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..2b2339c7c6ad 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->unpluggable && !dc->unpluggable(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 038b54d94b27..5df0db1a5b68 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 (*HotUnpluggable)(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. + * @unpluggable: 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 @@ -120,6 +123,7 @@ typedef struct DeviceClass { void (*reset)(DeviceState *dev); DeviceRealize realize; DeviceUnrealize unrealize; + HotUnpluggable unpluggable; /* device state */ const struct VMStateDescription *vmsd;