From patchwork Mon Oct 5 08:41:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 268028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA70AC4727D for ; Mon, 5 Oct 2020 08:41:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F95D20781 for ; Mon, 5 Oct 2020 08:41:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CyrhZMRD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725946AbgJEIlf (ORCPT ); Mon, 5 Oct 2020 04:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIle (ORCPT ); Mon, 5 Oct 2020 04:41:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC8B1C0613CE for ; Mon, 5 Oct 2020 01:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=tRj2uVRYSsJiToQXalM54LYRl8eqDwK4E1AusLHteSo=; b=CyrhZMRDmJeqJ8aiUk04pYYQHv 9aZ5iIuHayyVJ9bhC2aKe5Am6T2rLb0rpCHoAJg+OSyJAPevNbViigtwP6COzueeG0OINq1oMPr4b 5WXaTrMBJK+RItYoEK+wO73DQggS+qdXdrnsJ4MIzlKZ3feJrbR588GvpcptpizQqfBt1GDB4cWNH 0ZUtu2+Pk2MikMR1w6R44WycRVtFMtC7WoX46io4a0JQYYZeuheDKPBYqm6rnutnXDQLXQWIMufJs Ovk2Z5mbST3L+FdNTvsSV0DfQpWeA0uVSxBxIZQRozPK5bM6cCa+Pb0PPCdtknmdF+wjVMzIwLA/G ARH1oyVg==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3o-0000lQ-Vs; Mon, 05 Oct 2020 08:41:33 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 01/10] scsi: don't export scsi_device_from_queue Date: Mon, 5 Oct 2020 10:41:21 +0200 Message-Id: <20201005084130.143273-2-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This function is only used by code built into scsi_mod.ko. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index f0ee11dc07e4b0..b95e00ff346b09 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1959,7 +1959,6 @@ struct scsi_device *scsi_device_from_queue(struct request_queue *q) return sdev; } -EXPORT_SYMBOL_GPL(scsi_device_from_queue); /** * scsi_block_requests - Utility function used by low-level drivers to prevent From patchwork Mon Oct 5 08:41:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 267518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30740C4363A for ; Mon, 5 Oct 2020 08:41:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C288E2064C for ; Mon, 5 Oct 2020 08:41:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OVfRWjaS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725963AbgJEIlg (ORCPT ); Mon, 5 Oct 2020 04:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgJEIlg (ORCPT ); Mon, 5 Oct 2020 04:41:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2ACC0613CE for ; Mon, 5 Oct 2020 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=I+DmUprP4lyg/Mc50Hm6QFJUmH5nd0zGgX6GeT4Ag9U=; b=OVfRWjaSKwrwragCnth2IuNstu RiuEnJwYAco84zPhz84KBWDJW6WimYlWJvFcAlvORzEN5abULldm9Rdy30UPFoeljPJ2fN2zqPqmN Tid/mNLiR0H/l/rI5h9T8zpwmriCaUOtxhsfoDP+fhIDwzhgKFBfrRXZQNHNl4dobYgkBwltaKp7d drJ9t7+Pz7QQL8efY+PUFNHZaPr0kWsnEniiMZHnAseoOUcBO619odbcInyEPp8EE9FrQcHV58E8N C7phpw13gu1W13NcvvFqlVaLIfHv+cykKmWd6F/9K77pLHNnsXc3THNjd/UIYx0y8L0omyoPyegJD 45LmryqQ==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3q-0000lW-8C; Mon, 05 Oct 2020 08:41:34 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 02/10] scsi: remove scsi_init_cmd_errh Date: Mon, 5 Oct 2020 10:41:22 +0200 Message-Id: <20201005084130.143273-3-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There is no good reason to keep this functionality as a separate function, just merge it into the only caller. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b95e00ff346b09..8a7ae46b5943da 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -293,21 +293,6 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, } EXPORT_SYMBOL(__scsi_execute); -/** - * scsi_init_cmd_errh - Initialize cmd fields related to error handling. - * @cmd: command that is ready to be queued. - * - * This function has the job of initializing a number of fields related to error - * handling. Typically this will be called once for each command, as required. - */ -static void scsi_init_cmd_errh(struct scsi_cmnd *cmd) -{ - scsi_set_resid(cmd, 0); - memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); - if (cmd->cmd_len == 0) - cmd->cmd_len = scsi_command_size(cmd->cmnd); -} - /* * Wake up the error handler if necessary. Avoid as follows that the error * handler is not woken up if host in-flight requests number == @@ -1698,7 +1683,10 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, if (bd->last) cmd->flags |= SCMD_LAST; - scsi_init_cmd_errh(cmd); + scsi_set_resid(cmd, 0); + memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); + if (cmd->cmd_len == 0) + cmd->cmd_len = scsi_command_size(cmd->cmnd); cmd->scsi_done = scsi_mq_done; reason = scsi_dispatch_cmd(cmd); From patchwork Mon Oct 5 08:41:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 268027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F7AC4727D for ; Mon, 5 Oct 2020 08:41:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0422B20639 for ; Mon, 5 Oct 2020 08:41:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qSTeqvxY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725932AbgJEIlh (ORCPT ); Mon, 5 Oct 2020 04:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlh (ORCPT ); Mon, 5 Oct 2020 04:41:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C1DEC0613CE for ; Mon, 5 Oct 2020 01:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QYAtts78Sek2+pJOsJIZsIv3wT6qP5fShsl67p3Ykns=; b=qSTeqvxYJmu5bPRR6FTzO1KtBo IXoVJ/QNVTH16j9NFBxCJrdFj1nbrA4SyneLYERZBYBnWZoBeqBBKEunse2ND5NfdpFwP2H604RDa SMkcEN4PTyEbWHmKhqNCMfwpgCYLj3UpwltJNHHgmMQS72JfPwwFSTT2lmKxSVeBao/ZsVGkuYUXB WwDloAhlbzIpWJTeUxPo+zDaVlZM1k881T8lVY1ggrose0bS4NUxbL8i6hdO8WYcJR5qIKdJSxNl2 bSyy7LmuDdWeKJL5DzVLxvcyNAV5O1+HuZ/uIf9mpbPWEs3W1JQCoiihFaCeSPYe5EtBEHjLKBvhm k6UKCvwQ==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3r-0000lc-KB; Mon, 05 Oct 2020 08:41:35 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 03/10] scsi: move command size detection out of the fast path Date: Mon, 5 Oct 2020 10:41:23 +0200 Message-Id: <20201005084130.143273-4-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We only need to detect the command size for ioctl request from userspace, which is limited to the passthrough path. Move the check there instead of doing it for all queuecommand invocations. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8a7ae46b5943da..3c551f06ebe9be 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1166,6 +1166,8 @@ static blk_status_t scsi_setup_scsi_cmnd(struct scsi_device *sdev, } cmd->cmd_len = scsi_req(req)->cmd_len; + if (cmd->cmd_len == 0) + cmd->cmd_len = scsi_command_size(cmd->cmnd); cmd->cmnd = scsi_req(req)->cmd; cmd->transfersize = blk_rq_bytes(req); cmd->allowed = scsi_req(req)->retries; @@ -1685,8 +1687,6 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, scsi_set_resid(cmd, 0); memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); - if (cmd->cmd_len == 0) - cmd->cmd_len = scsi_command_size(cmd->cmnd); cmd->scsi_done = scsi_mq_done; reason = scsi_dispatch_cmd(cmd); From patchwork Mon Oct 5 08:41:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 267517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06F06C47095 for ; Mon, 5 Oct 2020 08:41:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B32852064C for ; Mon, 5 Oct 2020 08:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="B+eCSQXq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725967AbgJEIlj (ORCPT ); Mon, 5 Oct 2020 04:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlj (ORCPT ); Mon, 5 Oct 2020 04:41:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07145C0613CE for ; Mon, 5 Oct 2020 01:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=TKhNxLQUPbMqxLdH9p21zrAQJZyzC6dfZw+MHylrLZE=; b=B+eCSQXqkbGTjXyQSQtjxhWOPN 8Cyc1HAzrUqujTs7pMjppQM5J4JGn7NQxtTqKQ9ddLU/SfS++V1zmCU8FYDA5YpeZoJTX19qrI1RA 3SaMt32cxMGz3DlqAdsoUho5jBCSjm8ZlxTZXFbKqPWqxl3TQWYMnSI/VSct+dXrLWus3x4Uob6h4 Codx2zBHooBzykL1mxEuFNEwe1x+QT+crKpaSh/vqqamk2E/3YJEjkX+9Qqan7/doEF7b3h0kYr7x Sb6W7X/F5O/Ve0OF++86Ezj7wdE8btallhE/abA5aoHddC7A9/ZqFJzjwtHTjB1N9DfOhhNjkc7nf CEr49f7Q==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3s-0000lr-UB; Mon, 05 Oct 2020 08:41:37 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 04/10] scsi: simplify varlen CDB length checking Date: Mon, 5 Oct 2020 10:41:24 +0200 Message-Id: <20201005084130.143273-5-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Directly access the cdb array like we do everywhere else insted of overlaying a structure on top of it. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_logging.c | 2 +- include/scsi/scsi_common.h | 11 +++-------- include/scsi/scsi_proto.h | 10 ---------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c index 8ea44c6595efa7..b6222df7254a3a 100644 --- a/drivers/scsi/scsi_logging.c +++ b/drivers/scsi/scsi_logging.c @@ -111,7 +111,7 @@ static size_t scsi_format_opcode_name(char *buffer, size_t buf_len, cdb0 = cdbp[0]; if (cdb0 == VARIABLE_LENGTH_CMD) { - int len = scsi_varlen_cdb_length(cdbp); + int len = cdbp[7] + 8; if (len < 10) { off = scnprintf(buffer, buf_len, diff --git a/include/scsi/scsi_common.h b/include/scsi/scsi_common.h index 731ac09ed23135..297fc1881607b6 100644 --- a/include/scsi/scsi_common.h +++ b/include/scsi/scsi_common.h @@ -9,20 +9,15 @@ #include #include -static inline unsigned -scsi_varlen_cdb_length(const void *hdr) -{ - return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8; -} - extern const unsigned char scsi_command_size_tbl[8]; #define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7] static inline unsigned scsi_command_size(const unsigned char *cmnd) { - return (cmnd[0] == VARIABLE_LENGTH_CMD) ? - scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]); + if (cmnd[0] == VARIABLE_LENGTH_CMD) + return cmnd[7] + 8; + return COMMAND_SIZE(cmnd[0]); } /* Returns a human-readable name for the device */ diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index c3686011193224..c57f9cd8185526 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -176,16 +176,6 @@ #define SCSI_MAX_VARLEN_CDB_SIZE 260 -/* defined in T10 SCSI Primary Commands-2 (SPC2) */ -struct scsi_varlen_cdb_hdr { - __u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */ - __u8 control; - __u8 misc[5]; - __u8 additional_cdb_length; /* total cdb length - 8 */ - __be16 service_action; - /* service specific data follows */ -}; - /* * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft * T10/1561-D Revision 4 Draft dated 7th November 2002. From patchwork Mon Oct 5 08:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 268026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35903C4363A for ; Mon, 5 Oct 2020 08:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB5AB2064C for ; Mon, 5 Oct 2020 08:41:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UVJYui/8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725973AbgJEIlk (ORCPT ); Mon, 5 Oct 2020 04:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlk (ORCPT ); Mon, 5 Oct 2020 04:41:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38495C0613CE for ; Mon, 5 Oct 2020 01:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=THGc7HoQjObLGNgGriqHXUqM7fccgIra80Lxyex2gd8=; b=UVJYui/8GU6q13mQ0hk2Mh7f9h N46azw8tYgNLzaEVozCyrA43GZbwNs/mpHuY7HbANr9R7ZB2uL6tGvAzgAq8w5fTKmBusliepWXFV pEsCB1PcE4LVp3gARcQuvUp8wIaWpq637K8y2X6D1vw7ME4TNZK1URWWdB7CVxBSjuQy0FiUL/Gl8 WBuy8xR5XRV65VvN66IF11LNvRS0qQVwv4/9ugyUgOLKNHF1wi07XNjPbukqryNkUQThjhRzWLHsK SHs5YrlJoijOEj9l0h2Bgver0NfBwYJLcn9EtoeRFkdTNqAX2PeZnFOU0iGG902r8QBVk+xVmIoaB 9Bl0Ql/g==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3u-0000m6-Jc; Mon, 05 Oct 2020 08:41:38 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 05/10] scsi: use rq_dma_dir in scsi_setup_cmnd Date: Mon, 5 Oct 2020 10:41:25 +0200 Message-Id: <20201005084130.143273-6-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 3c551f06ebe9be..670ad06812b419 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1200,12 +1200,7 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); blk_status_t ret; - if (!blk_rq_bytes(req)) - cmd->sc_data_direction = DMA_NONE; - else if (rq_data_dir(req) == WRITE) - cmd->sc_data_direction = DMA_TO_DEVICE; - else - cmd->sc_data_direction = DMA_FROM_DEVICE; + cmd->sc_data_direction = rq_dma_dir(req); if (blk_rq_is_scsi(req)) ret = scsi_setup_scsi_cmnd(sdev, req); From patchwork Mon Oct 5 08:41:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 267516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70896C4727D for ; Mon, 5 Oct 2020 08:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C96020639 for ; Mon, 5 Oct 2020 08:41:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Kbck9aS+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725978AbgJEIll (ORCPT ); Mon, 5 Oct 2020 04:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIll (ORCPT ); Mon, 5 Oct 2020 04:41:41 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72F43C0613CE for ; Mon, 5 Oct 2020 01:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=tkBBgKCgCj4gIGCF/h0WCFwxiDkDI8aZTONywexT79U=; b=Kbck9aS+gTv98sJN/e9ZwzaGJw UIo1kOYYv0LhQ0m0jeX8bxjDaevcyzsqsR+DeOX3bEWyM3Tz18pVJkhxdGb/JhNY7C9QpQdeUxBo2 zusG/TpEwjvwxKzAWfBmX+aex+tJac6DC+9hEGhd6ObX2f1iki4j0Y3XJktL3J4sylF22bNw+PA6S j8ka3CghohypDoSJRgc5gEoZHH2Sr0phs/EuA/kipPWeNcLiMmyqUe5+QMPTZBGAfnu7RXJQbhON7 U7uqUtBDjZ5N+QIJa42KJGKS4If/yVoybVrYkanRAaTMgOqdaG0Rtn19Q0Co2u5mkPRRRuekCT8l2 9utuIGkw==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3v-0000mU-SH; Mon, 05 Oct 2020 08:41:40 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 06/10] scsi: rename scsi_prep_state_check to scsi_device_state_check Date: Mon, 5 Oct 2020 10:41:26 +0200 Message-Id: <20201005084130.143273-7-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The old name is rather confusing now that the the legacy prep_fn is gone. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 670ad06812b419..3940641052f90b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1214,7 +1214,7 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, } static blk_status_t -scsi_prep_state_check(struct scsi_device *sdev, struct request *req) +scsi_device_state_check(struct scsi_device *sdev, struct request *req) { switch (sdev->sdev_state) { case SDEV_OFFLINE: @@ -1653,7 +1653,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, * commands. */ if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { - ret = scsi_prep_state_check(sdev, req); + ret = scsi_device_state_check(sdev, req); if (ret != BLK_STS_OK) goto out_put_budget; } From patchwork Mon Oct 5 08:41:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 268025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8975C4363A for ; Mon, 5 Oct 2020 08:41:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7703C2064C for ; Mon, 5 Oct 2020 08:41:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="aSLmtaDu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725981AbgJEIln (ORCPT ); Mon, 5 Oct 2020 04:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlm (ORCPT ); Mon, 5 Oct 2020 04:41:42 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4977C0613CE for ; Mon, 5 Oct 2020 01:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=qwOFgI0tHXMNltyiAq/Y0XAEt/8cpzkQJcZbBFmsZD4=; b=aSLmtaDuZmong8V4Eii25U7SCJ CR7femZisyaLxEvpTbANfceYBv5/k5Xx8G3w1m/kc27pUny9zNFF5JZ8CJQujpKWOg9ntEJa44KUf 6bDcf54RgeKcpNW3szjij2sS2qCWsXLMLfLRk2Sw2/x/dLkQAXqlyqA3ogmpMBsEhGZRVdXUFA/7M zH8HMhOjHhQzn37qBJs+NL5XDOgUpn6NcjybWZTwhLnvc811m5CN7x9Z/5A13ZxDzKniV6S0QzkFQ EtPtf0j61za6LTpxI7V4nDCfWKp8mI8M+lm0Hv2y6eURaRyNpVqpBuyuyNuCC9hVR+rjk7CBjmKuu XIYEMmlQ==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3x-0000ma-27; Mon, 05 Oct 2020 08:41:41 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 07/10] scsi: rename scsi_mq_prep_fn to scsi_prepare_cmd Date: Mon, 5 Oct 2020 10:41:27 +0200 Message-Id: <20201005084130.143273-8-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The old name is rather confusing now that the the legacy prep_fn is gone. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 3940641052f90b..8420e42d618bb0 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1562,7 +1562,7 @@ static unsigned int scsi_mq_inline_sgl_size(struct Scsi_Host *shost) sizeof(struct scatterlist); } -static blk_status_t scsi_mq_prep_fn(struct request *req) +static blk_status_t scsi_prepare_cmd(struct request *req) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); struct scsi_device *sdev = req->q->queuedata; @@ -1665,7 +1665,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, goto out_dec_target_busy; if (!(req->rq_flags & RQF_DONTPREP)) { - ret = scsi_mq_prep_fn(req); + ret = scsi_prepare_cmd(req); if (ret != BLK_STS_OK) goto out_dec_host_busy; req->rq_flags |= RQF_DONTPREP; From patchwork Mon Oct 5 08:41:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 267515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07714C47095 for ; Mon, 5 Oct 2020 08:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA25220639 for ; Mon, 5 Oct 2020 08:41:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iDnVfUOx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725983AbgJEIlo (ORCPT ); Mon, 5 Oct 2020 04:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlo (ORCPT ); Mon, 5 Oct 2020 04:41:44 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2188AC0613CE for ; Mon, 5 Oct 2020 01:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=HHLPkXMY4viflT0SxFHqtPiJJ1Bz2VRsjqiBDUVadII=; b=iDnVfUOxK0e0p1MFNSRX3I4xk1 AxuR22FmmO5nrHVSFTxiNRjVrmepvA/SLDiMSurULWEW5ZemSkzHRXcAkFCpKq2aLCzrisd+CKiL1 l1/wDBAAf4mJqjSQgRm73JYQOyM20PCpaLiww9pwkuztxBzWWotc3lZp7AZp6uH5FI95gKoNyanlD To0wjFzj+/5FGV0A/fWF83vuXJnRG7M5/XlhZzb5/beYKppVgJoLMQuYUKXIJYjUDT8otpVbdt8zW 4FLme32j2xFDZ8uvl5En7nnlRt97VxtwdzMhV8lmnbBetlqfwTz/jWii0bB2V2dm7SBd3t2wXDiE0 G2Ya69IA==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3y-0000mp-9D; Mon, 05 Oct 2020 08:41:42 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 08/10] scsi: cleanup allocation and freeing of sgtables Date: Mon, 5 Oct 2020 10:41:28 +0200 Message-Id: <20201005084130.143273-9-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Rename scsi_init_io to scsi_alloc_sgtables, and ensure callers call scsi_free_sgtables to cleanup failures close to scsi_init_io instead of leaking it down the generic I/O submission path. Signed-off-by: Christoph Hellwig --- drivers/scsi/scsi_lib.c | 22 ++++++++-------------- drivers/scsi/sd.c | 27 +++++++++++++++------------ drivers/scsi/sr.c | 16 ++++++---------- include/scsi/scsi_cmnd.h | 3 ++- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8420e42d618bb0..c65ecb99c6994b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -515,7 +515,7 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd) } } -static void scsi_free_sgtables(struct scsi_cmnd *cmd) +void scsi_free_sgtables(struct scsi_cmnd *cmd) { if (cmd->sdb.table.nents) sg_free_table_chained(&cmd->sdb.table, @@ -524,6 +524,7 @@ static void scsi_free_sgtables(struct scsi_cmnd *cmd) sg_free_table_chained(&cmd->prot_sdb->table, SCSI_INLINE_PROT_SG_CNT); } +EXPORT_SYMBOL_GPL(scsi_free_sgtables); static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) { @@ -968,7 +969,7 @@ static inline bool scsi_cmd_needs_dma_drain(struct scsi_device *sdev, } /** - * scsi_init_io - SCSI I/O initialization function. + * scsi_alloc_sgtables - allocate S/G tables for a command * @cmd: command descriptor we wish to initialize * * Returns: @@ -976,7 +977,7 @@ static inline bool scsi_cmd_needs_dma_drain(struct scsi_device *sdev, * * BLK_STS_RESOURCE - if the failure is retryable * * BLK_STS_IOERR - if the failure is fatal */ -blk_status_t scsi_init_io(struct scsi_cmnd *cmd) +blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd) { struct scsi_device *sdev = cmd->device; struct request *rq = cmd->request; @@ -1068,7 +1069,7 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) scsi_free_sgtables(cmd); return ret; } -EXPORT_SYMBOL(scsi_init_io); +EXPORT_SYMBOL(scsi_alloc_sgtables); /** * scsi_initialize_rq - initialize struct scsi_cmnd partially @@ -1156,7 +1157,7 @@ static blk_status_t scsi_setup_scsi_cmnd(struct scsi_device *sdev, * submit a request without an attached bio. */ if (req->bio) { - blk_status_t ret = scsi_init_io(cmd); + blk_status_t ret = scsi_alloc_sgtables(cmd); if (unlikely(ret != BLK_STS_OK)) return ret; } else { @@ -1198,19 +1199,12 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); - blk_status_t ret; cmd->sc_data_direction = rq_dma_dir(req); if (blk_rq_is_scsi(req)) - ret = scsi_setup_scsi_cmnd(sdev, req); - else - ret = scsi_setup_fs_cmnd(sdev, req); - - if (ret != BLK_STS_OK) - scsi_free_sgtables(cmd); - - return ret; + return scsi_setup_scsi_cmnd(sdev, req); + return scsi_setup_fs_cmnd(sdev, req); } static blk_status_t diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 95018e650f2d0c..b29f4cbb4ee076 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -866,7 +866,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) cmd->transfersize = data_len; rq->timeout = SD_TIMEOUT; - return scsi_init_io(cmd); + return scsi_alloc_sgtables(cmd); } static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, @@ -897,7 +897,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; - return scsi_init_io(cmd); + return scsi_alloc_sgtables(cmd); } static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, @@ -928,7 +928,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->transfersize = data_len; rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; - return scsi_init_io(cmd); + return scsi_alloc_sgtables(cmd); } static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd) @@ -1069,7 +1069,7 @@ static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd) * knows how much to actually write. */ rq->__data_len = sdp->sector_size; - ret = scsi_init_io(cmd); + ret = scsi_alloc_sgtables(cmd); rq->__data_len = blk_rq_bytes(rq); return ret; @@ -1187,23 +1187,24 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) unsigned int dif; bool dix; - ret = scsi_init_io(cmd); + ret = scsi_alloc_sgtables(cmd); if (ret != BLK_STS_OK) return ret; + ret = BLK_STS_IOERR; if (!scsi_device_online(sdp) || sdp->changed) { scmd_printk(KERN_ERR, cmd, "device offline or changed\n"); - return BLK_STS_IOERR; + goto fail; } if (blk_rq_pos(rq) + blk_rq_sectors(rq) > get_capacity(rq->rq_disk)) { scmd_printk(KERN_ERR, cmd, "access beyond end of device\n"); - return BLK_STS_IOERR; + goto fail; } if ((blk_rq_pos(rq) & mask) || (blk_rq_sectors(rq) & mask)) { scmd_printk(KERN_ERR, cmd, "request not aligned to the logical block size\n"); - return BLK_STS_IOERR; + goto fail; } /* @@ -1225,7 +1226,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) if (req_op(rq) == REQ_OP_ZONE_APPEND) { ret = sd_zbc_prepare_zone_append(cmd, &lba, nr_blocks); if (ret) - return ret; + goto fail; } fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; @@ -1253,7 +1254,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) } if (unlikely(ret != BLK_STS_OK)) - return ret; + goto fail; /* * We shouldn't disconnect in the middle of a sector, so with a dumb @@ -1277,10 +1278,12 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) blk_rq_sectors(rq))); /* - * This indicates that the command is ready from our end to be - * queued. + * This indicates that the command is ready from our end to be queued. */ return BLK_STS_OK; +fail: + scsi_free_sgtables(cmd); + return ret; } static blk_status_t sd_init_command(struct scsi_cmnd *cmd) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 0c4aa4665a2f9d..b74dfd8dc1165e 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -392,15 +392,11 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt) struct request *rq = SCpnt->request; blk_status_t ret; - ret = scsi_init_io(SCpnt); + ret = scsi_alloc_sgtables(SCpnt); if (ret != BLK_STS_OK) - goto out; + return ret; cd = scsi_cd(rq->rq_disk); - /* from here on until we're complete, any goto out - * is used for a killable error condition */ - ret = BLK_STS_IOERR; - SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt, "Doing sr request, block = %d\n", block)); @@ -509,12 +505,12 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt) SCpnt->allowed = MAX_RETRIES; /* - * This indicates that the command is ready from our end to be - * queued. + * This indicates that the command is ready from our end to be queued. */ - ret = BLK_STS_OK; + return BLK_STS_OK; out: - return ret; + scsi_free_sgtables(SCpnt); + return BLK_STS_IOERR; } static int sr_block_open(struct block_device *bdev, fmode_t mode) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index e76bac4d14c51b..69ade4fb71aabf 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -165,7 +165,8 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, size_t *offset, size_t *len); extern void scsi_kunmap_atomic_sg(void *virt); -extern blk_status_t scsi_init_io(struct scsi_cmnd *cmd); +blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd); +void scsi_free_sgtables(struct scsi_cmnd *cmd); #ifdef CONFIG_SCSI_DMA extern int scsi_dma_map(struct scsi_cmnd *cmd); From patchwork Mon Oct 5 08:41:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 268024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B25C4363A for ; Mon, 5 Oct 2020 08:41:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D73220578 for ; Mon, 5 Oct 2020 08:41:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Qr5ttj+S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725930AbgJEIlp (ORCPT ); Mon, 5 Oct 2020 04:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlp (ORCPT ); Mon, 5 Oct 2020 04:41:45 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6105BC0613CE for ; Mon, 5 Oct 2020 01:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=HgrUTuTgW81PAafgziZ3ZRTQBuoILcBlvFrB07Hxu4w=; b=Qr5ttj+Sd9cABgjToA8k2LwD8W SNuqRh18u3ftMjeMxEvrZ5cqlj++4Y9btzC3ogkh8H3st+8YkbIu9Xa5F0GB3lvoxm24Qqrgc7BGI i1b7WZFvVtfLW2Hot7YHiju//XOO5n4aDqNTp4aM0wLIPhKnTPl/NVM1QBwbC21I1Fy3uChSJy+Bc TIzuu/fAb+RLtlrCFcbaSOr5cIEbeSqPKzywd1J1j1ScPty5YT0BGyUb+PjV4SVL+5GqhTkyh0Cb3 EKYVfGimlnez1+HYiBqllRZHdDPH/sb+/K0XD3b/O1T8VZbPNTm2MljlaKVHw9T8KYZ+1iN7CDVT/ r+ICViwg==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM3z-0000n4-OP; Mon, 05 Oct 2020 08:41:44 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 09/10] scsi: remove scsi_setup_cmnd and scsi_setup_fs_cmnd Date: Mon, 5 Oct 2020 10:41:29 +0200 Message-Id: <20201005084130.143273-10-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Move this trivial functionality into scsi_prepare_cmd instead of splitting it over multiple small functions, and update the comments to better document passthrough commands as the special case. Signed-off-by: Christoph Hellwig --- drivers/scsi/scsi_lib.c | 50 ++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index c65ecb99c6994b..f7b88d8cf975d5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1175,38 +1175,6 @@ static blk_status_t scsi_setup_scsi_cmnd(struct scsi_device *sdev, return BLK_STS_OK; } -/* - * Setup a normal block command. These are simple request from filesystems - * that still need to be translated to SCSI CDBs from the ULD. - */ -static blk_status_t scsi_setup_fs_cmnd(struct scsi_device *sdev, - struct request *req) -{ - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); - - if (unlikely(sdev->handler && sdev->handler->prep_fn)) { - blk_status_t ret = sdev->handler->prep_fn(sdev, req); - if (ret != BLK_STS_OK) - return ret; - } - - cmd->cmnd = scsi_req(req)->cmd = scsi_req(req)->__cmd; - memset(cmd->cmnd, 0, BLK_MAX_CDB); - return scsi_cmd_to_driver(cmd)->init_command(cmd); -} - -static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, - struct request *req) -{ - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); - - cmd->sc_data_direction = rq_dma_dir(req); - - if (blk_rq_is_scsi(req)) - return scsi_setup_scsi_cmnd(sdev, req); - return scsi_setup_fs_cmnd(sdev, req); -} - static blk_status_t scsi_device_state_check(struct scsi_device *sdev, struct request *req) { @@ -1568,6 +1536,7 @@ static blk_status_t scsi_prepare_cmd(struct request *req) cmd->request = req; cmd->tag = req->tag; cmd->prot_op = SCSI_PROT_NORMAL; + cmd->sc_data_direction = rq_dma_dir(req); sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size; cmd->sdb.table.sgl = sg; @@ -1581,7 +1550,22 @@ static blk_status_t scsi_prepare_cmd(struct request *req) blk_mq_start_request(req); - return scsi_setup_cmnd(sdev, req); + /* + * Special handling for passthrough commands, which don't go to the ULP + * at all: + */ + if (blk_rq_is_scsi(req)) + return scsi_setup_scsi_cmnd(sdev, req); + + if (sdev->handler && sdev->handler->prep_fn) { + blk_status_t ret = sdev->handler->prep_fn(sdev, req); + if (ret != BLK_STS_OK) + return ret; + } + + cmd->cmnd = scsi_req(req)->cmd = scsi_req(req)->__cmd; + memset(cmd->cmnd, 0, BLK_MAX_CDB); + return scsi_cmd_to_driver(cmd)->init_command(cmd); } static void scsi_mq_done(struct scsi_cmnd *cmd) From patchwork Mon Oct 5 08:41:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 267514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DE5BC4727D for ; Mon, 5 Oct 2020 08:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 390552064C for ; Mon, 5 Oct 2020 08:41:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="m+y1Adbc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725987AbgJEIlq (ORCPT ); Mon, 5 Oct 2020 04:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgJEIlq (ORCPT ); Mon, 5 Oct 2020 04:41:46 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98503C0613CE for ; Mon, 5 Oct 2020 01:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=j2ulpXvRV7rOIE5hH+Ev1iO0S//3dvCeaSPy6TCN+qE=; b=m+y1AdbcRZFIpN+mfD4iMPQ8K4 PetvSQGnOYq+xhcatH31YfvXM8fUuBuM6FYKzuTFPeJsJ/BOLLerzThPMil7DGaYkxpz01nfYdUEX kbBqBWClqoNsFeRc/YKzbCkCnjI6fJGo/GtOERwhdZf2oOOFlyTnfwvQ6rRTWsyHcA6F3WT7dNRO9 LSElnFbjV40xRv4CHLkBCot4AwNuf4xDp4y9lqJJ1/VuUlK/6zBe5ZtEuPCXXABHAvpqJMyxPxEpy HZ5FYPT741LhTH9ztNIINjR+X0cEZyPUpjwPxM10Ci0dFAuVDoqYyOyGIsKRFp1dtdI0PMX9KrwZk GZe31rhw==; Received: from [2001:4bb8:184:92a2:b8a4:f4a0:f053:4f06] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPM41-0000nJ-0V; Mon, 05 Oct 2020 08:41:45 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Subject: [PATCH 10/10] scsi: only start the request just before dispatching Date: Mon, 5 Oct 2020 10:41:30 +0200 Message-Id: <20201005084130.143273-11-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005084130.143273-1-hch@lst.de> References: <20201005084130.143273-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This has no change in behavior, but improves the accounting a bit. Signed-off-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index f7b88d8cf975d5..f0254f913b3e3f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1548,8 +1548,6 @@ static blk_status_t scsi_prepare_cmd(struct request *req) (struct scatterlist *)(cmd->prot_sdb + 1); } - blk_mq_start_request(req); - /* * Special handling for passthrough commands, which don't go to the ULP * at all: @@ -1649,7 +1647,6 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, req->rq_flags |= RQF_DONTPREP; } else { clear_bit(SCMD_STATE_COMPLETE, &cmd->state); - blk_mq_start_request(req); } cmd->flags &= SCMD_PRESERVED_FLAGS; @@ -1662,6 +1659,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); cmd->scsi_done = scsi_mq_done; + blk_mq_start_request(req); reason = scsi_dispatch_cmd(cmd); if (reason) { scsi_set_blocked(cmd, reason);