From patchwork Fri Jun 17 06:36:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 636806 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 3rW9jd3HByz9t1l for ; Fri, 17 Jun 2016 16:45:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b=d826lDrO; dkim-atps=neutral Received: from localhost ([::1]:54243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDnWd-0007VY-Et for incoming@patchwork.ozlabs.org; Fri, 17 Jun 2016 02:45:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDnN0-0005YM-Et for qemu-devel@nongnu.org; Fri, 17 Jun 2016 02:35:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDnMx-0008Ed-WC for qemu-devel@nongnu.org; Fri, 17 Jun 2016 02:35:09 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:43830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDnMx-0008AR-Ll; Fri, 17 Jun 2016 02:35:07 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3rW9Tt3f8zz9t26; Fri, 17 Jun 2016 16:34:58 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1466145298; bh=YxkO3eXtPCXYTWyb7awknBHwbOyu0FxQyjBH9FoqPTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d826lDrOaHpDcq0R7HR+BPEyLY9SmoH8B6wD66OpaNvKSeFj3kK8qxTyhb9sbH7iv /iJ5qldua0wTpeT/rJD8S4sEX7dwAWK3QcOxVxrV89gj54/Mu8QA765URaggjxVW5y xJDtkruH3N1a5axpnO2r7gd7uGjSvbRVEElb2KxA= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 17 Jun 2016 16:36:27 +1000 Message-Id: <1466145399-32209-7-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466145399-32209-1-git-send-email-david@gibson.dropbear.id.au> References: <1466145399-32209-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 06/18] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov pre_plug callback is to be called before device.realize() is executed. This would allow to check/set device's properties from HotplugHandler. Signed-off-by: Igor Mammedov Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c index 645cfca..17ac986 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -13,6 +13,17 @@ #include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp) +{ + HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler); + + if (hdc->pre_plug) { + hdc->pre_plug(plug_handler, plugged_dev, errp); + } +} + void hotplug_handler_plug(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index dcc00f8..6680089 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -902,6 +902,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp) g_free(name); } + hotplug_ctrl = qdev_get_hotplug_handler(dev); + if (hotplug_ctrl) { + hotplug_handler_pre_plug(hotplug_ctrl, dev, &local_err); + if (local_err != NULL) { + goto fail; + } + } + if (dc->realize) { dc->realize(dev, &local_err); } @@ -912,7 +920,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp) DEVICE_LISTENER_CALL(realize, Forward, dev); - hotplug_ctrl = qdev_get_hotplug_handler(dev); if (hotplug_ctrl) { hotplug_handler_plug(hotplug_ctrl, dev, &local_err); } diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index da1d0e4..c0db869 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -45,7 +45,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, * hardware (un)plug functions. * * @parent: Opaque parent interface. - * @plug: plug callback. + * @pre_plug: pre plug callback called at start of device.realize(true) + * @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -58,6 +59,7 @@ typedef struct HotplugHandlerClass { InterfaceClass parent; /* */ + hotplug_fn pre_plug; hotplug_fn plug; hotplug_fn unplug_request; hotplug_fn unplug; @@ -73,6 +75,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp); /** + * hotplug_handler_pre_plug: + * + * Call #HotplugHandlerClass.pre_plug callback of @plug_handler. + */ +void hotplug_handler_pre_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.