From patchwork Mon May 18 11:22:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 6428051 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 503BB9F318 for ; Mon, 18 May 2015 11:22:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6490B205DC for ; Mon, 18 May 2015 11:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5211F20602 for ; Mon, 18 May 2015 11:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753902AbbERLWa (ORCPT ); Mon, 18 May 2015 07:22:30 -0400 Received: from mail-bl2on0095.outbound.protection.outlook.com ([65.55.169.95]:16171 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753669AbbERLW2 (ORCPT ); Mon, 18 May 2015 07:22:28 -0400 Received: from BN1PR02CA0052.namprd02.prod.outlook.com (10.141.56.52) by BY1PR0201MB1032.namprd02.prod.outlook.com (25.161.203.15) with Microsoft SMTP Server (TLS) id 15.1.166.22; Mon, 18 May 2015 11:22:23 +0000 Received: from BY2FFO11FD008.protection.gbl (2a01:111:f400:7c0c::194) by BN1PR02CA0052.outlook.office365.com (2a01:111:e400:2a::52) with Microsoft SMTP Server (TLS) id 15.1.166.22 via Frontend Transport; Mon, 18 May 2015 11:22:23 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; redhat.com; dkim=none (message not signed) header.d=none; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BY2FFO11FD008.mail.protection.outlook.com (10.1.14.159) with Microsoft SMTP Server id 15.1.172.14 via Frontend Transport; Mon, 18 May 2015 11:22:22 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id A8.27.06265.E6BC9555; Mon, 18 May 2015 04:22:22 -0700 (PDT) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.224.2; Mon, 18 May 2015 04:22:21 -0700 X-AuditID: ac160a69-f790f6d000001879-f2-5559cb6e53f3 Received: from [10.50.231.56] ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id 31.E7.03643.C6BC9555; Mon, 18 May 2015 04:22:21 -0700 (PDT) Message-ID: <5559CB6B.1090508@sandisk.com> Date: Mon, 18 May 2015 13:22:19 +0200 From: Bart Van Assche User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Doug Ledford CC: James Bottomley , Sagi Grimberg , Sebastian Parschauer , linux-rdma , "linux-scsi@vger.kernel.org" Subject: [PATCH v2 01/12] scsi_transport_srp: Introduce srp_wait_for_queuecommand() References: <5559CB3A.6060102@sandisk.com> In-Reply-To: <5559CB3A.6060102@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnkeLIzCtJLcpLzFFi42JZI8azSDfvdGSoQd9xXouX5z+wWvxff5vF 4tmhXhaL7us72CxutD1gszh5m9+BzePZ9MNMHod//GD2+PPnM7PH+31X2Tw+b5ILYI3isklJ zcksSy3St0vgyli49glrwV+JigV3MxoYO0S7GDk5JARMJNYsO8oEYYtJXLi3nq2LkYtDSOAE o8SrWT+gnB2M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Faw9vfBNVUW3HO2XDzz//3pv/y1G3ZPA2tmLf ukDoAnuuC8OxF5Vnmhz4hSPV+S89f6Nwz6XZzLnn6uv5P5LteH5fj51Wd+XP9XeHn57yTHuW Wv/K8cHxuYIh3ybvFQmdrWjtWcm1Q7dXoODZqSRtplORZ3niHl5weZRwXHvpCWYlluKMREMt 5qLiRACK2eSQEQIAAA== X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD008; 1:7vuqdQ0V13y7St/QmNZ86wFPttVE5ZWLjSe+Lqfxit3PM6mR0f+wfVzCYo1OtAnUBxPity09rRm49MWPyN/PpgT69abPSjrsm8XxA6cy/zo5R35XfFMSZf32T2vjDh5tOJXbRBBFxT+GJJUO5AH4mxImlqeGkmCvB66BRwmzIhRfJLu7NbqO8QlDw740HI8+xeZ9czuh+bQfMEP2rCqTgUwd35a1FxNqnh/NC6WFe5f/HHuSvoPccHzhqbQ5g1H8QpIXvB6Nsg64EHqKuIxp0EDIriJP9J1uRSIxiS0TtW4= X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(199003)(189002)(59896002)(50986999)(229853001)(65816999)(110136002)(19580405001)(76176999)(36756003)(5001830100001)(87266999)(83506001)(5001860100001)(54356999)(189998001)(80316001)(33656002)(5001960100002)(87936001)(69596002)(92566002)(19580395003)(64706001)(47776003)(81156007)(4001540100001)(64126003)(4001350100001)(106466001)(97736004)(62966003)(50466002)(23676002)(86362001)(77156002)(46102003)(68736005)(65956001)(65806001)(77096005)(2950100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0201MB1032; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:ErrorRetry; A:1; MX:1; LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0201MB1032; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY1PR0201MB1032; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0201MB1032; X-Forefront-PRVS: 058043A388 X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2015 11:22:22.4212 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0201MB1032 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce the helper function srp_wait_for_queuecommand(). Move the definition of scsi_request_fn_active(). Add a comment above srp_wait_for_queuecommand() that support for scsi-mq needs to be added. This patch does not change any functionality. A second call to srp_wait_for_queuecommand() will be introduced in the next patch. Signed-off-by: Bart Van Assche Cc: James Bottomley Cc: Sagi Grimberg Cc: Sebastian Parschauer Cc: #v3.13 --- drivers/scsi/scsi_transport_srp.c | 54 ++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c index ae45bd9..e05cd7e 100644 --- a/drivers/scsi/scsi_transport_srp.c +++ b/drivers/scsi/scsi_transport_srp.c @@ -396,6 +396,36 @@ static void srp_reconnect_work(struct work_struct *work) } } +/** + * scsi_request_fn_active() - number of kernel threads inside scsi_request_fn() + * @shost: SCSI host for which to count the number of scsi_request_fn() callers. + * + * To do: add support for scsi-mq in this function. + */ +static int scsi_request_fn_active(struct Scsi_Host *shost) +{ + struct scsi_device *sdev; + struct request_queue *q; + int request_fn_active = 0; + + shost_for_each_device(sdev, shost) { + q = sdev->request_queue; + + spin_lock_irq(q->queue_lock); + request_fn_active += q->request_fn_active; + spin_unlock_irq(q->queue_lock); + } + + return request_fn_active; +} + +/* Wait until ongoing shost->hostt->queuecommand() calls have finished. */ +static void srp_wait_for_queuecommand(struct Scsi_Host *shost) +{ + while (scsi_request_fn_active(shost)) + msleep(20); +} + static void __rport_fail_io_fast(struct srp_rport *rport) { struct Scsi_Host *shost = rport_to_shost(rport); @@ -504,27 +534,6 @@ void srp_start_tl_fail_timers(struct srp_rport *rport) EXPORT_SYMBOL(srp_start_tl_fail_timers); /** - * scsi_request_fn_active() - number of kernel threads inside scsi_request_fn() - * @shost: SCSI host for which to count the number of scsi_request_fn() callers. - */ -static int scsi_request_fn_active(struct Scsi_Host *shost) -{ - struct scsi_device *sdev; - struct request_queue *q; - int request_fn_active = 0; - - shost_for_each_device(sdev, shost) { - q = sdev->request_queue; - - spin_lock_irq(q->queue_lock); - request_fn_active += q->request_fn_active; - spin_unlock_irq(q->queue_lock); - } - - return request_fn_active; -} - -/** * srp_reconnect_rport() - reconnect to an SRP target port * @rport: SRP target port. * @@ -559,8 +568,7 @@ int srp_reconnect_rport(struct srp_rport *rport) if (res) goto out; scsi_target_block(&shost->shost_gendev); - while (scsi_request_fn_active(shost)) - msleep(20); + srp_wait_for_queuecommand(shost); res = rport->state != SRP_RPORT_LOST ? i->f->reconnect(rport) : -ENODEV; pr_debug("%s (state %d): transport.reconnect() returned %d\n", dev_name(&shost->shost_gendev), rport->state, res);