[PATCH 2/2] WRITE_SAME_* TL==0 means all blocks from LBA until the end of device.

Ronnie Sahlberg <[email protected]> Sun, 2 Oct 2016 09:04:02 -0700
Newsgroups org.kernel.vger.stgt
Message-ID <[email protected]>
Signed-off-by: Ronnie Sahlberg <[email protected]>
---
 usr/sbc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/usr/sbc.c b/usr/sbc.c
index e58a233..779dacd 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -260,6 +260,9 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 		goto sense;
 	}
 
+	lba = scsi_rw_offset(cmd->scb);
+	tl  = scsi_rw_count(cmd->scb);
+
 	switch (cmd->scb[0]) {
 	case READ_10:
 	case READ_12:
@@ -314,6 +317,10 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 			asc = ASC_PARAMETER_LIST_LENGTH_ERR;
 			goto sense;
 		}
+		/* TL == 0 means all LBAs until end of device */
+		if (tl == 0)
+			tl = (lu->size >> cmd->dev->blk_shift) - lba;
+
 		break;
 	}
 
@@ -339,9 +346,6 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 		}
 	}
 
-	lba = scsi_rw_offset(cmd->scb);
-	tl  = scsi_rw_count(cmd->scb);
-
 	/* Verify that we are not doing i/o beyond
 	   the end-of-lun */
 	if (tl) {
-- 
2.5.0