From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
John Garry <john.g.garry@oracle.com>,
Hannes Reinecke <hare@suse.de>,
Mike Christie <michael.christie@oracle.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: [PATCH v4 06/29] scsi: core: Extend the scsi_execute_cmd() functionality
Date: Fri, 12 Sep 2025 11:21:27 -0700 [thread overview]
Message-ID: <20250912182340.3487688-7-bvanassche@acm.org> (raw)
In-Reply-To: <20250912182340.3487688-1-bvanassche@acm.org>
Make the @cmd argument optional. Add .init_cmd() and .copy_result()
callbacks in struct scsi_exec_args. Support allocating from a specific
hardware queue. This patch prepares for submitting reserved commands
with scsi_execute_cmd().
Cc: John Garry <john.g.garry@oracle.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_lib.c | 28 +++++++++++++++++++++++++---
include/scsi/scsi_cmnd.h | 2 ++
include/scsi/scsi_device.h | 37 +++++++++++++++++++++++++++++--------
3 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 5e636e015352..022cd454d658 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -308,7 +308,10 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
return -EINVAL;
retry:
- req = scsi_alloc_request(sdev->request_queue, opf, args->req_flags);
+ req = args->specify_hctx ?
+ scsi_alloc_request_hctx(sdev->request_queue, opf,
+ args->req_flags, args->hctx_idx) :
+ scsi_alloc_request(sdev->request_queue, opf, args->req_flags);
if (IS_ERR(req))
return PTR_ERR(req);
@@ -318,8 +321,12 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
goto out;
}
scmd = blk_mq_rq_to_pdu(req);
- scmd->cmd_len = COMMAND_SIZE(cmd[0]);
- memcpy(scmd->cmnd, cmd, scmd->cmd_len);
+ if (cmd) {
+ scmd->cmd_len = COMMAND_SIZE(cmd[0]);
+ memcpy(scmd->cmnd, cmd, scmd->cmd_len);
+ }
+ if (args->init_cmd)
+ args->init_cmd(scmd, args);
scmd->allowed = ml_retries;
scmd->flags |= args->scmd_flags;
req->timeout = timeout;
@@ -353,6 +360,9 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
args->sshdr);
ret = scmd->result;
+ if (ret == 0 && args->copy_result)
+ args->copy_result(scmd, args);
+
out:
blk_mq_free_request(req);
@@ -1247,6 +1257,18 @@ struct request *scsi_alloc_request(struct request_queue *q, blk_opf_t opf,
}
EXPORT_SYMBOL_GPL(scsi_alloc_request);
+struct request *scsi_alloc_request_hctx(struct request_queue *q, blk_opf_t opf,
+ blk_mq_req_flags_t flags, unsigned int hctx_idx)
+{
+ struct request *rq;
+
+ rq = blk_mq_alloc_request_hctx(q, opf, flags, hctx_idx);
+ if (!IS_ERR(rq))
+ scsi_initialize_rq(rq);
+ return rq;
+}
+EXPORT_SYMBOL_GPL(scsi_alloc_request_hctx);
+
/*
* Only called when the request isn't completed by SCSI, and not freed by
* SCSI
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 8ecfb94049db..a4cb836809df 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -396,5 +396,7 @@ extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc,
struct request *scsi_alloc_request(struct request_queue *q, blk_opf_t opf,
blk_mq_req_flags_t flags);
+struct request *scsi_alloc_request_hctx(struct request_queue *q, blk_opf_t opf,
+ blk_mq_req_flags_t flags, unsigned int hctx_idx);
#endif /* _SCSI_SCSI_CMND_H */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 3846f5dfc51c..2b2dc08962a2 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -541,15 +541,36 @@ struct scsi_failures {
struct scsi_failure *failure_definitions;
};
-/* Optional arguments to scsi_execute_cmd */
+/**
+ * struct scsi_exec_args - Optional arguments to scsi_execute_cmd()
+ * @init_cmd: called before the command is executed.
+ * @copy_result: called after the command has been executed.
+ * @sense: sense buffer.
+ * @sense_len: sense buffer len
+ * @sshdr: decoded sense header
+ * @req_flags: BLK_MQ_REQ flags
+ * @scmd_flags: SCMD flags.
+ * @resid: residual length.
+ * @failures: which failures to retry.
+ * @specify_hctx: call scsi_alloc_request_hctx() if %true or
+ scsi_alloc_request() otherwise.
+ * @hctx_idx: Passed as fourth argument for scsi_alloc_request_hctx() if
+ @specify_hctx is %true.
+ */
struct scsi_exec_args {
- unsigned char *sense; /* sense buffer */
- unsigned int sense_len; /* sense buffer len */
- struct scsi_sense_hdr *sshdr; /* decoded sense header */
- blk_mq_req_flags_t req_flags; /* BLK_MQ_REQ flags */
- int scmd_flags; /* SCMD flags */
- int *resid; /* residual length */
- struct scsi_failures *failures; /* failures to retry */
+ int (*init_cmd)(struct scsi_cmnd *cmd,
+ const struct scsi_exec_args *args);
+ void (*copy_result)(struct scsi_cmnd *cmd,
+ const struct scsi_exec_args *args);
+ unsigned char *sense;
+ unsigned int sense_len;
+ struct scsi_sense_hdr *sshdr;
+ blk_mq_req_flags_t req_flags;
+ int scmd_flags;
+ int *resid;
+ struct scsi_failures *failures;
+ bool specify_hctx;
+ int hctx_idx;
};
int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
next prev parent reply other threads:[~2025-09-12 18:25 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 18:21 [PATCH v4 00/29] Optimize the hot path in the UFS driver Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 01/29] scsi: core: Support allocating reserved commands Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 02/29] scsi: core: Move two statements Bart Van Assche
2025-09-16 8:03 ` John Garry
2025-09-16 8:28 ` Hannes Reinecke
2025-09-12 18:21 ` [PATCH v4 03/29] scsi: core: Make the budget map optional Bart Van Assche
2025-09-16 8:34 ` Hannes Reinecke
2025-09-16 15:45 ` Bart Van Assche
2025-09-16 20:38 ` Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 04/29] scsi: core: Support allocating a pseudo SCSI device Bart Van Assche
2025-09-16 8:21 ` John Garry
2025-09-16 8:44 ` Hannes Reinecke
2025-09-16 9:21 ` John Garry
2025-09-12 18:21 ` [PATCH v4 05/29] scsi: core: Introduce .queue_reserved_command() Bart Van Assche
2025-09-16 9:33 ` John Garry
2025-09-12 18:21 ` Bart Van Assche [this message]
2025-09-12 20:03 ` [PATCH v4 06/29] scsi: core: Extend the scsi_execute_cmd() functionality michael.christie
2025-09-12 20:14 ` Bart Van Assche
2025-09-16 9:09 ` John Garry
2025-09-16 15:44 ` Bart Van Assche
2025-09-17 13:08 ` John Garry
2025-09-17 18:21 ` Bart Van Assche
2025-09-17 23:42 ` Bart Van Assche
2025-09-18 8:01 ` John Garry
2025-09-18 19:49 ` Bart Van Assche
2025-09-19 7:45 ` John Garry
2025-09-12 18:21 ` [PATCH v4 07/29] scsi_debug: Allocate a pseudo SCSI device Bart Van Assche
2025-09-17 12:09 ` John Garry
2025-09-17 21:37 ` Bart Van Assche
2025-09-18 7:30 ` John Garry
2025-09-12 18:21 ` [PATCH v4 08/29] ufs: core: Move an assignment in ufshcd_mcq_process_cqe() Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 09/29] ufs: core: Change the type of one ufshcd_add_cmd_upiu_trace() argument Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 10/29] ufs: core: Only call ufshcd_add_command_trace() for SCSI commands Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 11/29] ufs: core: Change the type of one ufshcd_add_command_trace() argument Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 12/29] ufs: core: Change the type of one ufshcd_send_command() argument Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 13/29] ufs: core: Only call ufshcd_should_inform_monitor() for SCSI commands Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 14/29] ufs: core: Change the monitor function argument types Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 15/29] ufs: core: Rework ufshcd_mcq_compl_pending_transfer() Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 16/29] ufs: core: Rework ufshcd_eh_device_reset_handler() Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 17/29] ufs: core: Rework the SCSI host queue depth calculation code Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 18/29] ufs: core: Allocate the SCSI host earlier Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 19/29] ufs: core: Call ufshcd_init_lrb() later Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 20/29] ufs: core: Use hba->reserved_slot Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 21/29] ufs: core: Make the reserved slot a reserved request Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 22/29] ufs: core: Do not clear driver-private command data Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 23/29] ufs: core: Optimize the hot path Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 24/29] ufs: core: Pass a SCSI pointer instead of an LRB pointer Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 25/29] ufs: core: Remove the ufshcd_lrb task_tag member Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 26/29] ufs: core: Make blk_mq_tagset_busy_iter() skip reserved requests Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 27/29] ufs: core: Move code out of ufshcd_wait_for_dev_cmd() Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 28/29] ufs: core: Rework the ufshcd_issue_dev_cmd() callers Bart Van Assche
2025-09-12 18:21 ` [PATCH v4 29/29] ufs: core: Switch to scsi_execute_cmd() Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250912182340.3487688-7-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=hare@suse.de \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox