From patchwork Sun Jan 19 07:14:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 11340579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C070109A for ; Sun, 19 Jan 2020 07:15:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 299EF2073D for ; Sun, 19 Jan 2020 07:15:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fHtNGmSK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726451AbgASHPB (ORCPT ); Sun, 19 Jan 2020 02:15:01 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43919 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726744AbgASHPB (ORCPT ); Sun, 19 Jan 2020 02:15:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579418100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iybflM26WYMeoCRAkRYTW6uRVuVHivY05NfEWJZtDVs=; b=fHtNGmSKZkDQmyQzO2K4rMo3b2GIOnlqaobiwVBLVVx2pcMbn/+9Z7LqdJidlHd2jiAOt8 tLE0weSRyBFmqOq2BD6Eck1h7B4KDNjjbIPtWa1taveHPZ0D/kBQdUZF8w3zwC/4qPER3C +Y4MnoN16HPb5yuZP0Vqs6UzL6keotU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-3Eh3k-aQPU6VwzYAc0Cvkg-1; Sun, 19 Jan 2020 02:14:57 -0500 X-MC-Unique: 3Eh3k-aQPU6VwzYAc0Cvkg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AA47185432D; Sun, 19 Jan 2020 07:14:55 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E6E884BC8; Sun, 19 Jan 2020 07:14:51 +0000 (UTC) From: Ming Lei To: James Bottomley , linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: linux-block@vger.kernel.org, Jens Axboe , Ming Lei , Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , Kashyap Desai , Sumit Saxena , Shivasharan S , "Ewan D . Milne" , Hannes Reinecke , Bart Van Assche Subject: [PATCH 1/6] scsi: mpt3sas: don't use .device_busy in device reset routine Date: Sun, 19 Jan 2020 15:14:27 +0800 Message-Id: <20200119071432.18558-2-ming.lei@redhat.com> In-Reply-To: <20200119071432.18558-1-ming.lei@redhat.com> References: <20200119071432.18558-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org scsih_dev_reset() uses scsi_device->device_busy to check if there is inflight commands aimed to this LUN. Uses block layer's helper of blk_mq_tagset_busy_iter() to do that, so we can prepare for bypassing .device_busy for SSD since it is quite expensive to inc/dec the global atomic counter in IO path. With this change, no driver uses scsi_device->device_busy any more. Cc: Sathya Prakash Cc: Chaitra P B Cc: Suganath Prabu Subramani Cc: Kashyap Desai Cc: Sumit Saxena Cc: Shivasharan S Cc: Ewan D. Milne Cc: Hannes Reinecke Cc: Bart Van Assche Signed-off-by: Ming Lei --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index c597d544eb39..91766c172d8f 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -2994,6 +2994,36 @@ scsih_abort(struct scsi_cmnd *scmd) return r; } +struct device_busy { + struct scsi_device *dev; + unsigned int cnt; +}; + +static bool scsi_device_check_in_flight(struct request *rq, void *data, + bool reserved) +{ + struct device_busy *busy = data; + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); + + if (test_bit(SCMD_STATE_INFLIGHT, &cmd->state) && cmd->device == + busy->dev) + (busy->cnt)++; + + return true; +} + +static bool scsih_dev_busy(struct scsi_device *device) +{ + struct device_busy data = { + .dev = device, + .cnt = 0, + }; + + blk_mq_tagset_busy_iter(&device->host->tag_set, + scsi_device_check_in_flight, &data); + return data.cnt > 0; +} + /** * scsih_dev_reset - eh threads main device reset routine * @scmd: pointer to scsi command object @@ -3060,7 +3090,7 @@ scsih_dev_reset(struct scsi_cmnd *scmd) MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0, tr_timeout, tr_method); /* Check for busy commands after reset */ - if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) + if (r == SUCCESS && scsih_dev_busy(scmd->device)) r = FAILED; out: sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(0x%p)\n",