Skip to content

Commit

Permalink
[SCSI] scsi_debug: fix logical block provisioning support when unmap_…
Browse files Browse the repository at this point in the history
…alignment != 0

Commit b90ebc3 ("[SCSI] scsi_debug:
fix logical block provisioning support") fixed several issues with
logical block provisioning support, but it still doesn't properly fix
the cases when unmap_alignment > 0.

For example, load scsi_debug module with the following module parameters
and make all blocks mapped by filling the storage with zero.

        # modprobe scsi_debug lbpu=1 unmap_alignment=1 unmap_granularity=4
        # dd if=/dev/zero of=$DEV

Then, try to unmap the first unmappable blocks at lba=1, but GET LBA STATUS
unexpectedly reports that the last UNMAP has done nothing.

        # sg_unmap --lba=1 --num=4 $DEV
        # sg_get_lba_status --lba=1 $DEV
        descriptor LBA: 0x0000000000000001  blocks: 16383  mapped

The problem is in map_index_to_lba(), which should return the first
LBA which is corresponding to a given index of provisioning map
(map_storep).

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: "Martin K. Petersen" <martin.petersen@oracle.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
  • Loading branch information
Akinobu Mita authored and James Bottomley committed Sep 3, 2013
1 parent 150c354 commit a027b5b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/scsi/scsi_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,8 +1997,14 @@ static unsigned long lba_to_map_index(sector_t lba)

static sector_t map_index_to_lba(unsigned long index)
{
return index * scsi_debug_unmap_granularity -
scsi_debug_unmap_alignment;
sector_t lba = index * scsi_debug_unmap_granularity;

if (scsi_debug_unmap_alignment) {
lba -= scsi_debug_unmap_granularity -
scsi_debug_unmap_alignment;
}

return lba;
}

static unsigned int map_state(sector_t lba, unsigned int *num)
Expand Down

0 comments on commit a027b5b

Please sign in to comment.