Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp857894ybh; Tue, 10 Mar 2020 09:32:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvfiBR+7vaElJR+7P6JOuoQAqIyldR+gf0vvRQP1UKNVpuyOFOMknM6M9canqdt34Jjfqqe X-Received: by 2002:a9d:5cc8:: with SMTP id r8mr3029402oti.345.1583857944391; Tue, 10 Mar 2020 09:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583857944; cv=none; d=google.com; s=arc-20160816; b=levJ9mFSp+lOP2zjyMFq00wIiNxemHDxBUo2OyEynrjha9foMYOzAzt/vwR8L9/Ojs QwPt1kUWdvgErcc6KgPw32HtOrD2vj6+UdnVY3geMg70VzdpkZdMLIna/aUW1snp+oQV zJsoYAav9HiJR1ZDerfQFYxQGWb/zCFiIg3eS4Emtn7sICjfDEoRhuoh1zcsKbVVPmlw JzKqpTrYGnYyy1gnvr5F4H9L4gLkC1k+AO00TXZQ/NBgS32WJoy7ckB8pmOEhIEUsNxh CZuLUu5siCBC4iSfajRA2WN2fj1oljthnvZ0BBBpyD2r9yotNDMNFoXdbbpTNmZOEoVV AvKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=B+gNBbazvk990XZ3dk8v/RY4Gx3+u1ZxBQUAYpf9F2M=; b=mOCVZD+2+CB1NQ6/xPHYvgPqAaw2C5eSjzBwhis44E3wzdSGdLElofHgLSEJzWGgOs D16TNT26ugon9I9yQj3zynIBu/kQ5/oBFg6jKiCVBNZg7Ww7Zl1MPktQVZQn7K8o2OH4 M8ZDinyI3REZZ/F0qfUYoQANJzX4um10d9d/koQIzxNUrXrIzKGX/Hy1ZOF33DdvQmx8 MlWLtN6Ur/WCH3ZxQRYvDkWI97KZWvEYkhDYeD0F6J0Jtcizt410Arz6kTcKsD/aZQYV iQoLxMM2+5H94EzkCPMAefORHCwngzb/YDZoZKos/BtUiQwwaqkEp+Ul6vZ/QZUOVwgo SygQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si8377084otr.27.2020.03.10.09.32.12; Tue, 10 Mar 2020 09:32:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbgCJQaq (ORCPT + 99 others); Tue, 10 Mar 2020 12:30:46 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:35552 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726716AbgCJQap (ORCPT ); Tue, 10 Mar 2020 12:30:45 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D7DFA548D466147AF310; Wed, 11 Mar 2020 00:30:33 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Mar 2020 00:30:26 +0800 From: John Garry To: , , , , , , CC: , , , , , , Hannes Reinecke Subject: [PATCH RFC v2 08/24] scsi: add host tagset busy iterator Date: Wed, 11 Mar 2020 00:25:34 +0800 Message-ID: <1583857550-12049-9-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1583857550-12049-1-git-send-email-john.garry@huawei.com> References: <1583857550-12049-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hannes Reinecke Add an iterator scsi_host_tagset_busy_iter() to easily traverse all busy commands. No locking is done here; this need to be ensured by the caller. Signed-off-by: Hannes Reinecke --- drivers/scsi/hosts.c | 27 +++++++++++++++++++++++++++ include/scsi/scsi_host.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 1d669e47b692..97704a630f8e 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -650,3 +650,30 @@ void scsi_flush_work(struct Scsi_Host *shost) flush_workqueue(shost->work_q); } EXPORT_SYMBOL_GPL(scsi_flush_work); + +struct scsi_host_tagset_busy_iter_data { + scsi_host_busy_iter_fn *fn; + void *priv; +}; + +static bool scsi_host_tagset_busy_iter_fn(struct request *req, void *priv, + bool reserved) +{ + struct scsi_host_tagset_busy_iter_data *iter_data = priv; + struct scsi_cmnd *sc = blk_mq_rq_to_pdu(req); + + return iter_data->fn(sc, iter_data->priv, reserved); +} + +void scsi_host_tagset_busy_iter(struct Scsi_Host *shost, + scsi_host_busy_iter_fn *fn, void *priv) +{ + struct scsi_host_tagset_busy_iter_data iter_data = { + .fn = fn, + .priv = priv, + }; + + blk_mq_tagset_busy_iter(&shost->tag_set, scsi_host_tagset_busy_iter_fn, + &iter_data); +} +EXPORT_SYMBOL_GPL(scsi_host_tagset_busy_iter); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 2258a4f7b4d8..663aef22437a 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -767,6 +767,11 @@ static inline int scsi_host_scan_allowed(struct Scsi_Host *shost) extern void scsi_unblock_requests(struct Scsi_Host *); extern void scsi_block_requests(struct Scsi_Host *); +typedef bool (scsi_host_busy_iter_fn)(struct scsi_cmnd *, void *, bool); + +void scsi_host_tagset_busy_iter(struct Scsi_Host *, + scsi_host_busy_iter_fn *fn, void *priv); + struct class_container; /* -- 2.17.1