From patchwork Tue Mar 10 16:25:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 11429839 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 515AD139A for ; Tue, 10 Mar 2020 16:31:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AD1121D7E for ; Tue, 10 Mar 2020 16:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726633AbgCJQbl (ORCPT ); Tue, 10 Mar 2020 12:31:41 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:35778 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727092AbgCJQap (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 00CF6BD5A10424B2E4AA; Wed, 11 Mar 2020 00:30:34 +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:25 +0800 From: John Garry To: , , , , , , CC: , , , , , , Hannes Reinecke Subject: [PATCH RFC v2 04/24] scsi: Add scsi_{get, put}_reserved_cmd() Date: Wed, 11 Mar 2020 00:25:30 +0800 Message-ID: <1583857550-12049-5-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 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Hannes Reinecke Implement a function to allocate a SCSI command from the reserved tag pool using the host-wide reserved command queue. Signed-off-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 30 ++++++++++++++++++++++++++++++ include/scsi/scsi_cmnd.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index e809b0e30a11..af4f56cd0093 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1927,6 +1927,36 @@ void scsi_mq_destroy_tags(struct Scsi_Host *shost) blk_mq_free_tag_set(&shost->tag_set); } +struct scsi_cmnd *scsi_get_reserved_cmd(struct Scsi_Host *shost) +{ + struct scsi_cmnd *scmd; + struct request *rq; + + if (WARN_ON(!shost->reserved_cmd_q)) + return NULL; + + rq = blk_mq_alloc_request(shost->reserved_cmd_q, + REQ_OP_DRV_OUT | REQ_NOWAIT, + BLK_MQ_REQ_RESERVED); + if (IS_ERR(rq)) + return NULL; + WARN_ON(rq->tag == -1); + scmd = blk_mq_rq_to_pdu(rq); + scmd->request = rq; + + return scmd; +} +EXPORT_SYMBOL_GPL(scsi_get_reserved_cmd); + +void scsi_put_reserved_cmd(struct scsi_cmnd *scmd) +{ + struct request *rq = blk_mq_rq_from_pdu(scmd); + + if (blk_mq_rq_is_reserved(rq)) + blk_mq_free_request(rq); +} +EXPORT_SYMBOL_GPL(scsi_put_reserved_cmd); + /** * scsi_device_from_queue - return sdev associated with a request_queue * @q: The request queue to return the sdev from diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index a2849bb9cd19..82a4499539b3 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -159,6 +159,9 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd) return *(struct scsi_driver **)cmd->request->rq_disk->private_data; } +struct scsi_cmnd *scsi_get_reserved_cmd(struct Scsi_Host *shost); +void scsi_put_reserved_cmd(struct scsi_cmnd *); + extern void scsi_put_command(struct scsi_cmnd *); extern void scsi_finish_command(struct scsi_cmnd *cmd);