Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp859114ybh; Tue, 10 Mar 2020 09:33:42 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsB8YXDYPCY2PSYVbca5yxxznsvt07goITI9bnbQ0CukqfhP7+hcvXK33xyqVmx9qApY36v X-Received: by 2002:a9d:7695:: with SMTP id j21mr17883155otl.157.1583858022273; Tue, 10 Mar 2020 09:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583858022; cv=none; d=google.com; s=arc-20160816; b=pVzwVusKeRyR4RIJNRd3awKSMEo3oo3LfisJKOuQQw4CT/PjQUKTcl554AHQKsghT8 yJF6sD6bJUbHR1xf9oexTzgcbm4BDn7WM1JgsK5Rspoz4LNzoaIxXumjcgCByXj57mxe aWCsQfUw49Gq7tQsCncFHXo5xm0qXp2eb7o7tRjgfW2bp3TUNoR/1HAVkifuKfrmntwf r27+pteXehZhwoKlS4GzIk8YQKl4yLlm1j7oMMWXhYHyoN6oP6kBrY5XaPJcoj5XuMtH Y6W6e6jbh0T15H2WVR4IdcZl4pd3X21NztssA7u768+mQbA80dSmLfGHyt2NrlPkKiFO GJ7A== 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=H1fkVaAxMVerbmIYuRzbMetCzmM4YhN7UebHpUy1qqg=; b=xsn+5KwrpF0CzPeOSUgO91pMJ3U5hdxGpcAkMDp5m6B9tSn80w8O+Vc5KQWs0S/e4s dP7lifrWB3Pyw6gce9QxyYwR8cO50egPjAXwk7RvEvYgel+piknNT9cs82+aGAe4EBqf YIOiO1JkYNd6qfRmwKmUTeVrUUYpB5kQKoIwJA3g/NBM87TYt9BC/KO8IVa0vpe0EUEJ 20Wgsp/up6/NsxuPyE8X1QLzrekVDLBiPfDzWxScKISXSoPDoA1HiCB2CdbL5cYD19dO pzOEp3jhOVgp+kkYd7+JozzJUTdsTJwc8maw+8B093b/0sY0Xv0Ygv+YUy3M96C+XqKo NSYA== 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 s1si526416oij.237.2020.03.10.09.33.30; Tue, 10 Mar 2020 09:33:42 -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 S1727576AbgCJQbm (ORCPT + 99 others); Tue, 10 Mar 2020 12:31:42 -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 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 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); -- 2.17.1