Message ID | 20210609033929.3815-14-martin.petersen@oracle.com |
---|---|
State | New |
Headers | show |
Series | Subject: Protection information and block size cleanup | expand |
Hi Bart! > On 6/8/21 8:39 PM, Martin K. Petersen wrote: >> +static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd) >> +{ >> + unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT; >> + >> + return blk_rq_bytes(scmd->request) >> shift; >> +} > > I think we either need a comment above this function that explains that > the return value is a number of logical blocks or to change the function > name to make the meaning of the return value clear. I went with the scsi_get_ prefix to match the scsi_get_sectors() and scsi_get_lba() calls. Felt that "block" would suffice but I could make it scsi_logical_block_count() if you prefer? -- Martin K. Petersen Oracle Linux Engineering
On 6/9/21 8:19 PM, Martin K. Petersen wrote: >> On 6/8/21 8:39 PM, Martin K. Petersen wrote: >>> +static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd) >>> +{ >>> + unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT; >>> + >>> + return blk_rq_bytes(scmd->request) >> shift; >>> +} >> >> I think we either need a comment above this function that explains that >> the return value is a number of logical blocks or to change the function >> name to make the meaning of the return value clear. > > I went with the scsi_get_ prefix to match the scsi_get_sectors() and > scsi_get_lba() calls. Felt that "block" would suffice but I could make > it scsi_logical_block_count() if you prefer? The name scsi_logical_block_count() sounds fine to me :-) Thanks, Bart.
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 90da9617d28a..570719237f23 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -232,6 +232,13 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) return blk_rq_pos(scmd->request) >> shift; } +static inline unsigned int scsi_get_block_count(struct scsi_cmnd *scmd) +{ + unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT; + + return blk_rq_bytes(scmd->request) >> shift; +} + /* * The operations below are hints that tell the controller driver how * to handle I/Os with DIF or similar types of protection information.
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> --- include/scsi/scsi_cmnd.h | 7 +++++++ 1 file changed, 7 insertions(+)