Commit e18d8bea authored by Akinobu Mita's avatar Akinobu Mita Committed by James Bottomley

[SCSI] scsi_debug: simplify offset calculation for dif_storep

dif_storep is declared as pointer to unsigned char type.  But it is
actually used to store vmalloced array of struct sd_dif_tuple.

This changes the type of dif_storep to the pointer to struct sd_dif_tuple.
It simplifies offset calculation for dif_storep and enables to remove
hardcoded size of struct sd_dif_tuple.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
Acked-by: default avatar"Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: default avatarJames Bottomley <JBottomley@Parallels.com>
parent e9926b43
...@@ -258,7 +258,7 @@ struct sdebug_queued_cmd { ...@@ -258,7 +258,7 @@ struct sdebug_queued_cmd {
static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE]; static struct sdebug_queued_cmd queued_arr[SCSI_DEBUG_CANQUEUE];
static unsigned char * fake_storep; /* ramdisk storage */ static unsigned char * fake_storep; /* ramdisk storage */
static unsigned char *dif_storep; /* protection info */ static struct sd_dif_tuple *dif_storep; /* protection info */
static void *map_storep; /* provisioning map */ static void *map_storep; /* provisioning map */
static unsigned long map_size; static unsigned long map_size;
...@@ -277,11 +277,6 @@ static char sdebug_proc_name[] = "scsi_debug"; ...@@ -277,11 +277,6 @@ static char sdebug_proc_name[] = "scsi_debug";
static struct bus_type pseudo_lld_bus; static struct bus_type pseudo_lld_bus;
static inline sector_t dif_offset(sector_t sector)
{
return sector << 3;
}
static struct device_driver sdebug_driverfs_driver = { static struct device_driver sdebug_driverfs_driver = {
.name = sdebug_proc_name, .name = sdebug_proc_name,
.bus = &pseudo_lld_bus, .bus = &pseudo_lld_bus,
...@@ -1727,7 +1722,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, ...@@ -1727,7 +1722,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
start_sec = do_div(tmp_sec, sdebug_store_sectors); start_sec = do_div(tmp_sec, sdebug_store_sectors);
sdt = (struct sd_dif_tuple *)(dif_storep + dif_offset(start_sec)); sdt = dif_storep + start_sec;
for (i = 0 ; i < sectors ; i++) { for (i = 0 ; i < sectors ; i++) {
u16 csum; u16 csum;
...@@ -1782,16 +1777,17 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, ...@@ -1782,16 +1777,17 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
ei_lba++; ei_lba++;
} }
resid = sectors * 8; /* Bytes of protection data to copy into sgl */ /* Bytes of protection data to copy into sgl */
resid = sectors * sizeof(*dif_storep);
sector = start_sec; sector = start_sec;
scsi_for_each_prot_sg(SCpnt, psgl, scsi_prot_sg_count(SCpnt), i) { scsi_for_each_prot_sg(SCpnt, psgl, scsi_prot_sg_count(SCpnt), i) {
int len = min(psgl->length, resid); int len = min(psgl->length, resid);
paddr = kmap_atomic(sg_page(psgl)) + psgl->offset; paddr = kmap_atomic(sg_page(psgl)) + psgl->offset;
memcpy(paddr, dif_storep + dif_offset(sector), len); memcpy(paddr, dif_storep + sector, len);
sector += len >> 3; sector += len / sizeof(*dif_storep);
if (sector >= sdebug_store_sectors) { if (sector >= sdebug_store_sectors) {
/* Force wrap */ /* Force wrap */
tmp_sec = sector; tmp_sec = sector;
...@@ -1968,7 +1964,7 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, ...@@ -1968,7 +1964,7 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
* correctness we need to verify each sector * correctness we need to verify each sector
* before writing it to "stable" storage * before writing it to "stable" storage
*/ */
memcpy(dif_storep + dif_offset(sector), sdt, 8); memcpy(dif_storep + sector, sdt, sizeof(*sdt));
sector++; sector++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment