The translation from LBA to index of provisioning map (map_storep) is used in various places (map_state(), map_region(), and unmap_region()). But it is not correctly calculated if scsi_debug_unmap_alignment is zero. This introduces correct translation functions between LBA and index of provisioning map: static unsigned long lba_to_map_index(sector_t lba); static sector_t map_index_to_lba(unsigned long index); Actual bug fixes with using these functions will be done by forthcoming patches. Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx> Cc: "James E.J. Bottomley" <JBottomley@xxxxxxxxxxxxx> Cc: Douglas Gilbert <dgilbert@xxxxxxxxxxxx> Cc: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx> Cc: linux-scsi@xxxxxxxxxxxxxxx --- drivers/scsi/scsi_debug.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 4b5d388..c6de36c 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1997,6 +1997,23 @@ out: return ret; } +static unsigned long lba_to_map_index(sector_t lba) +{ + if (scsi_debug_unmap_alignment) { + lba += scsi_debug_unmap_granularity - + scsi_debug_unmap_alignment; + } + do_div(lba, scsi_debug_unmap_granularity); + + return lba; +} + +static sector_t map_index_to_lba(unsigned long index) +{ + return index * scsi_debug_unmap_granularity - + scsi_debug_unmap_alignment; +} + static unsigned int map_state(sector_t lba, unsigned int *num) { unsigned int granularity, alignment, mapped; -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html