From patchwork Thu Apr 30 08:56:42 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: 6300801 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CAF2BBEEE1 for ; Thu, 30 Apr 2015 09:12:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9C90201CD for ; Thu, 30 Apr 2015 09:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF1A72015A for ; Thu, 30 Apr 2015 09:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750812AbbD3JMN (ORCPT ); Thu, 30 Apr 2015 05:12:13 -0400 Received: from mail-bn1bon0061.outbound.protection.outlook.com ([157.56.111.61]:44384 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750920AbbD3JMK (ORCPT ); Thu, 30 Apr 2015 05:12:10 -0400 X-Greylist: delayed 864 seconds by postgrey-1.27 at vger.kernel.org; Thu, 30 Apr 2015 05:12:10 EDT Received: from BY2PR02CA0035.namprd02.prod.outlook.com (10.141.216.25) by DM2PR02MB287.namprd02.prod.outlook.com (10.141.55.148) with Microsoft SMTP Server (TLS) id 15.1.148.16; Thu, 30 Apr 2015 08:56:50 +0000 Received: from BN1AFFO11FD010.protection.gbl (2a01:111:f400:7c10::168) by BY2PR02CA0035.outlook.office365.com (2a01:111:e400:2c40::25) with Microsoft SMTP Server (TLS) id 15.1.154.19 via Frontend Transport; Thu, 30 Apr 2015 08:56:50 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; odin.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 BN1AFFO11FD010.mail.protection.outlook.com (10.58.52.70) with Microsoft SMTP Server id 15.1.160.8 via Frontend Transport; Thu, 30 Apr 2015 08:56:46 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id D9.1A.14695.D4EE1455; Thu, 30 Apr 2015 01:56:45 -0700 (PDT) Received: from milsmgip12.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; Thu, 30 Apr 2015 01:56:44 -0700 X-AuditID: ac160a69-f79656d000003967-3c-5541ee4dd2e3 Received: from [10.50.231.61] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id C5.7A.04406.B4EE1455; Thu, 30 Apr 2015 01:56:45 -0700 (PDT) Message-ID: <5541EE4A.30803@sandisk.com> Date: Thu, 30 Apr 2015 10:56:42 +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 01/12] scsi_transport_srp: Introduce srp_wait_for_queuecommand() References: <5541EE21.3050809@sandisk.com> In-Reply-To: <5541EE21.3050809@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeLIzCtJLcpLzFFi42JZI8azSNf3nWOowbbXEhYvz39gtfi//jaL xbNDvSwW3dd3sFncaHvAZnHyNr8Dm8ez6YeZPA7/+MHs8efPZ2aP9/uusnl83i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5l1ihrDlJba/ncM8gZF/FpIds5CUzUJStoCReRWjWG5mTnFuemaBoZFecWJeSmZxtl5y fu4mRnAQc0btYLw+0fwQIxMHp1QDY//FyBC3N216x12cD/rcTb55gPd8luI73nXr+HMni+8v nKnlVMN5R2zarqd7Uw16rH2vq89eeGZTvp+xgbLQz21Biz/IVtcauLDu9bzjt+wbx5EHL8rO 90YdVDCWm/Cz0//albAK/k8xu++81jjmwPRnrdChLw8+e97PUrkrGj/76FWdazbH5JVYijMS DbWYi4oTARiMeywSAgAA X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(199003)(189002)(62966003)(19580405001)(54356999)(36756003)(77156002)(86362001)(110136002)(87936001)(92566002)(64126003)(47776003)(50466002)(19580395003)(65956001)(106466001)(76176999)(65816999)(77096005)(46102003)(229853001)(83506001)(2950100001)(23676002)(33656002)(65806001)(4001350100001)(5001960100002)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR02MB287; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR02MB287; 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:DM2PR02MB287; BCL:0; PCL:0; RULEID:; SRVR:DM2PR02MB287; X-Forefront-PRVS: 056297E276 X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2015 08:56:46.3206 (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: DM2PR02MB287 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(). This patch does not change any functionality. A second call to scsi_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 Reviewed-by: Sagi Grimberg --- drivers/scsi/scsi_transport_srp.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c index ae45bd9..6ce1c48 100644 --- a/drivers/scsi/scsi_transport_srp.c +++ b/drivers/scsi/scsi_transport_srp.c @@ -396,6 +396,34 @@ 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. + */ +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 +532,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 +566,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);