Blob Blame History Raw
From: "Martin K. Petersen" <martin.petersen@oracle.com>
Date: Fri, 6 Aug 2021 00:00:19 -0400
Subject: scsi: core: Add helper to return number of logical blocks in a
 request
Patch-mainline: v5.15-rc1
Git-commit: 6a20e21ae1e25f73385cc248f53440e78dd3cb94
References: bsc#1190576

Link: https://lore.kernel.org/r/20210806040023.5355-2-martin.petersen@oracle.com
Cc: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Daniel Wagner <dwagner@suse.de>
---
 include/scsi/scsi_cmnd.h |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -240,6 +240,13 @@ static inline int scsi_sg_copy_to_buffer
 				 buf, buflen);
 }
 
+static inline unsigned int scsi_logical_block_count(struct scsi_cmnd *scmd)
+{
+	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+
+	return blk_rq_bytes(scsi_cmd_to_rq(scmd)) >> shift;
+}
+
 /*
  * The operations below are hints that tell the controller driver how
  * to handle I/Os with DIF or similar types of protection information.