From patchwork Wed Oct 15 03:08:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 399716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3D3B71400B6 for ; Wed, 15 Oct 2014 14:24:44 +1100 (EST) Received: from localhost ([::1]:41528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeFCb-0004G1-RG for incoming@patchwork.ozlabs.org; Tue, 14 Oct 2014 23:24:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeEy1-0005zb-5Z for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeExu-0004mY-3d for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:36 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49329 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeExt-0004lp-Hq for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:29 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2D886AD59; Wed, 15 Oct 2014 03:09:29 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Wed, 15 Oct 2014 05:08:54 +0200 Message-Id: <1413342561-4754-21-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1413342561-4754-1-git-send-email-afaerber@suse.de> References: <1413342561-4754-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PULL 20/47] qdev: HotplugHandler: Provide unplug callback 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 From: Igor Mammedov It is to be called for actual device removal and will allow to separate request and removal handling phases of x86-CPU devices and also it's a handler to be called for synchronously removable devices. Signed-off-by: Igor Mammedov Reviewed-by: Paolo Bonzini Signed-off-by: Andreas Färber --- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 13 +++++++++++-- include/hw/hotplug.h | 12 ++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c index 2ec4736..4e01074 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -34,6 +34,17 @@ void hotplug_handler_unplug_request(HotplugHandler *plug_handler, } } +void hotplug_handler_unplug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp) +{ + HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler); + + if (hdc->unplug) { + hdc->unplug(plug_handler, plugged_dev, errp); + } +} + static const TypeInfo hotplug_handler_info = { .name = TYPE_HOTPLUG_HANDLER, .parent = TYPE_INTERFACE, diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 87ed438..6479194 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -227,8 +227,17 @@ void qdev_unplug(DeviceState *dev, Error **errp) qdev_hot_removed = true; if (dev->parent_bus && dev->parent_bus->hotplug_handler) { - hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, - dev, errp); + HotplugHandlerClass *hdc; + + /* If device supports async unplug just request it to be done, + * otherwise just remove it synchronously */ + hdc = HOTPLUG_HANDLER_GET_CLASS(dev->parent_bus->hotplug_handler); + if (hdc->unplug_request) { + hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, + dev, errp); + } else { + hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, errp); + } } else { assert(dc->unplug != NULL); if (dc->unplug(dev) < 0) { /* legacy handler */ diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index e397d08..050d2f0 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -50,6 +50,9 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. + * @unplug: unplug callback. + * Used for device removal with devices that implement + * asynchronous and synchronous (suprise) removal. */ typedef struct HotplugHandlerClass { /* */ @@ -58,6 +61,7 @@ typedef struct HotplugHandlerClass { /* */ hotplug_fn plug; hotplug_fn unplug_request; + hotplug_fn unplug; } HotplugHandlerClass; /** @@ -77,4 +81,12 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, void hotplug_handler_unplug_request(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp); +/** + * hotplug_handler_unplug: + * + * Calls #HotplugHandlerClass.unplug callback of @plug_handler. + */ +void hotplug_handler_unplug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp); #endif