Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1765fe5e authored by Roland Dreier's avatar Roland Dreier Committed by Nicholas Bellinger
Browse files

target: Fix range calculation in WRITE SAME emulation when num blocks == 0



When NUMBER OF LOGICAL BLOCKS is 0, WRITE SAME is supposed to write
all the blocks from the specified LBA through the end of the device.
However, dev->transport->get_blocks(dev) (perhaps confusingly) returns
the last valid LBA rather than the number of blocks, so the correct
number of blocks to write starting with lba is

dev->transport->get_blocks(dev) - lba + 1

(nab: Backport roland's for-3.6 patch to for-3.5)

Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
Cc: Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent d35212f3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1095,7 +1095,7 @@ int target_emulate_write_same(struct se_cmd *cmd)
	if (num_blocks != 0)
		range = num_blocks;
	else
		range = (dev->transport->get_blocks(dev) - lba);
		range = (dev->transport->get_blocks(dev) - lba) + 1;

	pr_debug("WRITE_SAME UNMAP: LBA: %llu Range: %llu\n",
		 (unsigned long long)lba, (unsigned long long)range);