From: John Garry <john.g.garry@oracle.com>
To: Bart Van Assche <bvanassche@acm.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Subject: Re: [PATCH v3 05/26] scsi: core: Add scsi_{get,put}_internal_cmd() helpers
Date: Thu, 4 Sep 2025 10:56:32 +0100 [thread overview]
Message-ID: <b9ebed12-0e89-495d-8aa2-a615603cec4f@oracle.com> (raw)
In-Reply-To: <20250827000816.2370150-6-bvanassche@acm.org>
On 27/08/2025 01:06, Bart Van Assche wrote:
> From: Hannes Reinecke <hare@suse.de>
>
> Add helper functions to allow LLDDs to allocate and free internal commands.
>
> Cc: John Garry <john.g.garry@oracle.com>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> [ bvanassche: changed the 'nowait' argument into a 'flags' argument /
> added scsi_get_internal_cmd_hctx(). See also
> https://lore.kernel.org/linux-scsi/20211125151048.103910-3-hare@suse.de/ ]
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
did you consider reusing/refactoring scsi_execute_cmd() here? I'm just
wondering if it is possible.
> ---
> drivers/scsi/scsi_lib.c | 80 ++++++++++++++++++++++++++++++++++++++
> include/scsi/scsi_cmnd.h | 2 +
> include/scsi/scsi_device.h | 7 ++++
> 3 files changed, 89 insertions(+)
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2d81fd837d47..c988e6f8194b 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1247,6 +1247,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
> @@ -2139,6 +2151,74 @@ void scsi_mq_free_tags(struct kref *kref)
> complete(&shost->tagset_freed);
> }
>
> +/**
> + * scsi_get_internal_cmd() - Allocate an internal SCSI command.
> + * @sdev: SCSI device from which to allocate the command
> + * @data_direction: Data direction for the allocated command
> + * @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or
> + * BLK_MQ_REQ_NOWAIT.
> + *
> + * Allocates a SCSI command for internal LLDD use.
> + */
> +struct scsi_cmnd *scsi_get_internal_cmd(struct scsi_device *sdev,
> + enum dma_data_direction data_direction,
> + blk_mq_req_flags_t flags)
> +{
> + enum req_op op = data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT :
> + REQ_OP_DRV_IN;
> + struct scsi_cmnd *scmd;
> + struct request *rq;
> +
> + rq = scsi_alloc_request(sdev->request_queue, op, flags);
> + if (IS_ERR(rq))
> + return NULL;
> + scmd = blk_mq_rq_to_pdu(rq);
> + scmd->device = sdev;
> +
> + return scmd;
> +}
> +EXPORT_SYMBOL_GPL(scsi_get_internal_cmd);
> +
> +/**
> + * scsi_get_internal_cmd_hctx() - Allocate an internal SCSI command from a given
> + * hardware queue.
> + * @sdev: SCSI device from which to allocate the command
> + * @data_direction: Data direction for the allocated command
> + * @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or
> + * BLK_MQ_REQ_NOWAIT.
> + * @hctx_idx: Hardware queue index.
> + *
> + * Allocates a SCSI command for internal LLDD use.
> + */
> +struct scsi_cmnd *scsi_get_internal_cmd_hctx(struct scsi_device *sdev,
> + enum dma_data_direction data_direction,
> + blk_mq_req_flags_t flags, unsigned int hctx_idx)
> +{
> + enum req_op op = data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT :
next prev parent reply other threads:[~2025-09-04 9:56 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 0:06 [PATCH v3 00/26] Optimize the hot path in the UFS driver Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 01/26] scsi: core: Support allocating reserved commands Bart Van Assche
2025-09-04 8:49 ` John Garry
2025-09-04 17:00 ` Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 02/26] scsi: core: Support allocating a pseudo SCSI device Bart Van Assche
2025-09-04 8:59 ` John Garry
2025-09-04 9:29 ` John Garry
2025-09-04 18:05 ` Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 03/26] scsi: core: Do not allocate a budget token for reserved commands Bart Van Assche
2025-09-04 9:41 ` John Garry
2025-09-04 18:17 ` Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 04/26] scsi: core: Bypass the queue limit checks " Bart Van Assche
2025-09-04 9:49 ` John Garry
2025-08-27 0:06 ` [PATCH v3 05/26] scsi: core: Add scsi_{get,put}_internal_cmd() helpers Bart Van Assche
2025-09-04 9:56 ` John Garry [this message]
2025-08-27 0:06 ` [PATCH v3 06/26] scsi_debug: Set .alloc_pseudo_sdev Bart Van Assche
2025-09-04 10:02 ` John Garry
2025-08-27 0:06 ` [PATCH v3 07/26] ufs: core: Move an assignment Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 08/26] ufs: core: Change the type of one ufshcd_add_cmd_upiu_trace() argument Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 09/26] ufs: core: Only call ufshcd_add_command_trace() for SCSI commands Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 10/26] ufs: core: Change the type of one ufshcd_add_command_trace() argument Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 11/26] ufs: core: Change the type of one ufshcd_send_command() argument Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 12/26] ufs: core: Only call ufshcd_should_inform_monitor() for SCSI commands Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 13/26] ufs: core: Change the monitor function argument types Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 14/26] ufs: core: Rework ufshcd_mcq_compl_pending_transfer() Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 15/26] ufs: core: Rework ufshcd_eh_device_reset_handler() Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 16/26] ufs: core: Allocate more commands for the SCSI host Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 17/26] ufs: core: Allocate the SCSI host earlier Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 18/26] ufs: core: Call ufshcd_init_lrb() later Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 19/26] ufs: core: Use hba->reserved_slot Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 20/26] ufs: core: Make the reserved slot a reserved request Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 21/26] ufs: core: Do not clear driver-private command data Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 22/26] ufs: core: Optimize the hot path Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 23/26] ufs: core: Pass a SCSI pointer instead of an LRB pointer Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 24/26] ufs: core: Remove the ufshcd_lrb task_tag member Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 25/26] ufs: core: Make blk_mq_tagset_busy_iter() skip reserved requests Bart Van Assche
2025-08-27 0:06 ` [PATCH v3 26/26] ufs: core: Switch to scsi_get_internal_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=b9ebed12-0e89-495d-8aa2-a615603cec4f@oracle.com \
--to=john.g.garry@oracle.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@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;
as well as URLs for NNTP newsgroup(s).