diff mbox series

[01/50] core: Introduce the blk_req() function

Message ID 20210514213356.5264-2-bvanassche@acm.org
State Superseded
Headers show
Series [01/50] core: Introduce the blk_req() function | expand

Commit Message

Bart Van Assche May 14, 2021, 9:32 p.m. UTC
The 'request' member of struct scsi_cmnd is superfluous. The struct
request and struct scsi_cmnd data structures are adjacent and hence the
request pointer can be derived easily from a scsi_cmnd pointer. Introduce
a helper function that performs that conversion in a type-safe way. This
patch is the first step towards removing the request member from struct
scsi_cmnd. Making that change has the following advantages:
- This is a performance optimization since adding an offset to a pointer
  takes less time than dereferencing a pointer.
- struct scsi_cmnd becomes smaller.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/scsi/scsi_cmnd.h | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Christoph Hellwig May 15, 2021, 6:47 a.m. UTC | #1
> +/* Variant of blk_mq_rq_from_pdu() that verifies the type of its argument. */

> +static inline struct request *blk_req(struct scsi_cmnd *scmd)


Please don't use a blk_ prefix for a SCSI funtion.  Why not scsi_scmd_to_rq
or something like that?
Bart Van Assche May 17, 2021, 4:07 p.m. UTC | #2
On 5/14/21 11:47 PM, Christoph Hellwig wrote:
>> +/* Variant of blk_mq_rq_from_pdu() that verifies the type of its argument. */

>> +static inline struct request *blk_req(struct scsi_cmnd *scmd)

> 

> Please don't use a blk_ prefix for a SCSI funtion.  Why not scsi_scmd_to_rq

> or something like that?


Hi Christoph,

Thanks for having taken a look. I will rename that function into
scsi_cmd_to_rq().

Bart.
diff mbox series

Patch

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index fed024f4c02a..f5825be7ee76 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -146,6 +146,12 @@  struct scsi_cmnd {
 	unsigned int extra_len;	/* length of alignment and padding */
 };
 
+/* Variant of blk_mq_rq_from_pdu() that verifies the type of its argument. */
+static inline struct request *blk_req(struct scsi_cmnd *scmd)
+{
+	return blk_mq_rq_from_pdu(scmd);
+}
+
 /*
  * Return the driver private allocation behind the command.
  * Only works if cmd_size is set in the host template.