From patchwork Mon Sep 17 20:11:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10603329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C979413AD for ; Mon, 17 Sep 2018 20:12:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD0122A681 for ; Mon, 17 Sep 2018 20:12:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAD0B2A62C; Mon, 17 Sep 2018 20:12:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36AA12A6B7 for ; Mon, 17 Sep 2018 20:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728869AbeIRBlC (ORCPT ); Mon, 17 Sep 2018 21:41:02 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:48891 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728644AbeIRBlC (ORCPT ); Mon, 17 Sep 2018 21:41:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=xLig21IL5FbhMNkkowLurnkpCGttEoC079qWL6zONgA=; b=iSDGViV3UOxJ 3X8/a1mV2JyvYQWuDBGPiRHv/P34nz9nAin+3r8eCWag4ejH+uBHFJNXLI5DDlfIFXW6xu0ANbTzT 5a01SXQImWTttruO0wB4nEMvs+AVTmdCmdXF95Bx9uxqACbXHmtxWmYJhHpI+YvbMqfj343IFzgJg 3it5ISLW162k7Nyn17G9g9m75E0ghO4iAb66LUbqPh3Gk/FozVbMXWTG+pvgmFVo7/rT0dsMmavKY /ZeGwcknh0LKs8zrKhB5cVC+LSI/zo+/JXGXbCHBSTnC3IRFFGf2iOsiJfQHpVP7Kdr/iMxFQtAEo sFjZDxKMfU+4nAk7H8abXg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g1zs9-000A4P-Ho; Mon, 17 Sep 2018 22:11:54 +0200 Received: from asus.hsd1.ca.comcast.net (c-174-62-111-89.hsd1.ca.comcast.net [174.62.111.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id BBDD0C05E8; Mon, 17 Sep 2018 22:11:50 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , "Martin K . Petersen" , Ming Lei , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v7 3/7] block, scsi: Introduce blk_pm_runtime_exit() Date: Mon, 17 Sep 2018 13:11:17 -0700 Message-Id: <20180917201124.26161-5-bvanassche@acm.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180917201124.26161-1-bvanassche@acm.org> References: <20180917201124.26161-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00826051391609) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5q35Vts5jgVdDX2YouG9e0F602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTaOqZpfO3PVJjdazu3l6Zm3CrxbKqqxVb1b/D8J7mjn9ilV cTJ2PzGYt6C/dLANFNC9eBrzwetNxEiSKDRqnfKMQkpuFrILVINAX/FRRdHr3yMkm/wiy60JYYB9 uF3NAa1Nk+QSW7RQzhAm/KStEkEjjSySmAlj1sIqwltPBEyYUVLTnxxOo8WXP45qj8D05F0GHXoj JzNBXYf7J9S/MLPJeew2ZFB8y+lVHOa/te45KxSlpp6gZ+aErQiqwMtUFszQVi7RanL0btaq9sjs zlKiU2Itm39BdCc4FEP6OrUewqv6w78MMfzJ6uM1Dx2pwT35pPd8EVnAHGc0OQ9kcA25gl8rTFVB NUayNYioUf/jaE247rv5gOouGP1S4LTxm4IZFA/pqiraPmJuCFYZ26hO7EGy2J9deH+T4rZSs7oC RIPDMAUwB3tfqejuvISV+XjlglRDk9cYQA7KMLDnGOJ56M3u8AeQ7v6DJmTHsjuH4LUFg/fIocum fy7nlHshc2SgmIw4GlBMUJ5tmacVuNcCPzQwTZWk0LJpbj+275alueD3JP1TZOF7xCxMWPmtOrbV 9PRhq/iu+/MOrSZMQFCZLKPFRdvGVz6FathkOrvSVbJku7mYuO6/u95MMzIDS/46LsQWSvXxCnap bJkXIiZFNXf0xLkfge9mzM1qtvMzGhxN0KJA0WTUTYKVWFtnCgPCyfAF5Ve27bZx8lNxHZrSz5UH bYcFdeza/19y+Oe5+XMcN6qoXPjenLhIOF1oeRaG59HzCM/CJu09YkfNS5lCkaaqKsJlzt0rFZVG km82wgglcpuiNUgtVLhVTUCFY11v+uXgXEYvArbO0oejeRZBMzfVS2F5zx6Xv1wYD5pggHFcqGMK FnJ9zhnN3PsOVCXTPpuFqUUQz+mM8JAD4ECWnX6cA2ykgwOGHlCIbiwD3zYqbw7K8wXfWEq4R5Sn byIzfZt3VRCJ2Pc7g4yo2a6xeoi18/keJzTtGsgipJycC1z1pRXWhjh9fdbl44I0Df07iMRMEtw5 FYVgwESjGj0CVM425AmTEBxNKcMF8mUuRzJjABkIOA15lSz/ApS5x7XBRBZgCikvOAMF/4pY8933 STgKuQTNWzD5ZtpFGGfySqrvT/6FxsCFB9XjB2O02ISQORcYm+eIaK9fUWr9RAN1VteFsHx6aV0g AKZg2G2C+vhR5z5mZ3U+Zxr6OCsiAcJi2vb4bFtfc2n16f62CAbv X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since it is possible to unbind a SCSI ULD and since unbinding removes the association between a request queue and struct device, the q->dev pointer has to be reset during unbind. Hence introduce a function in the block layer that clears request_queue.dev. Signed-off-by: Bart Van Assche Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-pm.c | 18 ++++++++++++++++++ drivers/scsi/sd.c | 9 ++++----- drivers/scsi/sr.c | 3 ++- include/linux/blk-pm.h | 2 ++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/block/blk-pm.c b/block/blk-pm.c index 9b636960d285..bf8532da952d 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -40,6 +40,24 @@ void blk_pm_runtime_init(struct request_queue *q, struct device *dev) } EXPORT_SYMBOL(blk_pm_runtime_init); +/** + * blk_pm_runtime_exit - runtime PM exit routine + * @q: the queue of the device + * + * This function should be called from the device_driver.remove() callback + * function to avoid that further calls to runtime power management functions + * occur. + */ +void blk_pm_runtime_exit(struct request_queue *q) +{ + if (!q->dev) + return; + + pm_runtime_get_sync(q->dev); + q->dev = NULL; +} +EXPORT_SYMBOL(blk_pm_runtime_exit); + /** * blk_pre_runtime_suspend - Pre runtime suspend check * @q: the queue of the device diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 64514e8359e4..956b918b6114 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3408,12 +3408,11 @@ static int sd_probe(struct device *dev) **/ static int sd_remove(struct device *dev) { - struct scsi_disk *sdkp; - dev_t devt; + struct scsi_disk *sdkp = dev_get_drvdata(dev); + struct scsi_device *sdp = sdkp->device; + dev_t devt = disk_devt(sdkp->disk); - sdkp = dev_get_drvdata(dev); - devt = disk_devt(sdkp->disk); - scsi_autopm_get_device(sdkp->device); + blk_pm_runtime_exit(sdp->request_queue); async_synchronize_full_domain(&scsi_sd_pm_domain); async_synchronize_full_domain(&scsi_sd_probe_domain); diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 4f07b3410595..111ad9f8b449 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -1015,8 +1015,9 @@ static void sr_kref_release(struct kref *kref) static int sr_remove(struct device *dev) { struct scsi_cd *cd = dev_get_drvdata(dev); + struct scsi_device *sdev = cd->device; - scsi_autopm_get_device(cd->device); + blk_pm_runtime_exit(sdev->request_queue); del_gendisk(cd->disk); dev_set_drvdata(dev, NULL); diff --git a/include/linux/blk-pm.h b/include/linux/blk-pm.h index b80c65aba249..6d654f41acbf 100644 --- a/include/linux/blk-pm.h +++ b/include/linux/blk-pm.h @@ -11,6 +11,7 @@ struct request_queue; */ #ifdef CONFIG_PM extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev); +extern void blk_pm_runtime_exit(struct request_queue *q); extern int blk_pre_runtime_suspend(struct request_queue *q); extern void blk_post_runtime_suspend(struct request_queue *q, int err); extern void blk_pre_runtime_resume(struct request_queue *q); @@ -19,6 +20,7 @@ extern void blk_set_runtime_active(struct request_queue *q); #else static inline void blk_pm_runtime_init(struct request_queue *q, struct device *dev) {} +static inline void blk_pm_runtime_exit(struct request_queue *q) {} #endif #endif /* _BLK_PM_H_ */