Skip to content

Commit 5616b0a

Browse files
martinkpetersenJames Bottomley
authored andcommitted
[SCSI] use the scsi data buffer length to extract transfer size
Commit 8846bab introduced a helper that can be used to query the wire transfer size for a SCSI command taking protection information into account. However, some commands do not have a 1:1 mapping between the block range they work on and the payload size (discard, write same). After the scatterlist has been set up these requests use __data_len to store the number of bytes to report completion on. This means that callers of scsi_transfer_length() would get the wrong byte count for these types of requests. To overcome this we make scsi_transfer_length() use the scatterlist length in the scsi_data_buffer as basis for the wire transfer calculation instead of __data_len. Reported-by: Christoph Hellwig <hch@infradead.org> Debugged-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Fixes: d77e653 Cc: stable@vger.kernel.org Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent a33c070 commit 5616b0a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/scsi/scsi_cmnd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
318318

319319
static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
320320
{
321-
unsigned int xfer_len = blk_rq_bytes(scmd->request);
321+
unsigned int xfer_len = scsi_out(scmd)->length;
322322
unsigned int prot_op = scsi_get_prot_op(scmd);
323323
unsigned int sector_size = scmd->device->sector_size;
324324

0 commit comments

Comments
 (0)