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

[SCSI] scsi_debug: reduce duplication between prot_verify_read and prot_verify_write

In order to reduce code duplication between prot_verify_read() and
prot_verify_write(), this moves common code into the new functions.

[jejb: fix unitialised variable warning]
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 e18d8bea
...@@ -1710,69 +1710,79 @@ static int do_device_access(struct scsi_cmnd *scmd, ...@@ -1710,69 +1710,79 @@ static int do_device_access(struct scsi_cmnd *scmd,
return ret; return ret;
} }
static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, static u16 dif_compute_csum(const void *buf, int len)
unsigned int sectors, u32 ei_lba)
{ {
unsigned int i, resid;
struct scatterlist *psgl;
struct sd_dif_tuple *sdt;
sector_t sector;
sector_t tmp_sec = start_sec;
void *paddr;
start_sec = do_div(tmp_sec, sdebug_store_sectors);
sdt = dif_storep + start_sec;
for (i = 0 ; i < sectors ; i++) {
u16 csum; u16 csum;
if (sdt[i].app_tag == 0xffff)
continue;
sector = start_sec + i;
switch (scsi_debug_guard) { switch (scsi_debug_guard) {
case 1: case 1:
csum = ip_compute_csum(fake_storep + csum = ip_compute_csum(buf, len);
sector * scsi_debug_sector_size,
scsi_debug_sector_size);
break; break;
case 0: case 0:
csum = crc_t10dif(fake_storep + csum = cpu_to_be16(crc_t10dif(buf, len));
sector * scsi_debug_sector_size,
scsi_debug_sector_size);
csum = cpu_to_be16(csum);
break; break;
default:
BUG();
} }
return csum;
}
if (sdt[i].guard_tag != csum) { static int dif_verify(struct sd_dif_tuple *sdt, const void *data,
printk(KERN_ERR "%s: GUARD check failed on sector %lu" \ sector_t sector, u32 ei_lba)
" rcvd 0x%04x, data 0x%04x\n", __func__, {
u16 csum = dif_compute_csum(data, scsi_debug_sector_size);
if (sdt->guard_tag != csum) {
pr_err("%s: GUARD check failed on sector %lu rcvd 0x%04x, data 0x%04x\n",
__func__,
(unsigned long)sector, (unsigned long)sector,
be16_to_cpu(sdt[i].guard_tag), be16_to_cpu(sdt->guard_tag),
be16_to_cpu(csum)); be16_to_cpu(csum));
dif_errors++;
return 0x01; return 0x01;
} }
if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION && if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION &&
be32_to_cpu(sdt[i].ref_tag) != (sector & 0xffffffff)) { be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) {
printk(KERN_ERR "%s: REF check failed on sector %lu\n", pr_err("%s: REF check failed on sector %lu\n",
__func__, (unsigned long)sector); __func__, (unsigned long)sector);
dif_errors++;
return 0x03; return 0x03;
} }
if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION && if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
be32_to_cpu(sdt[i].ref_tag) != ei_lba) { be32_to_cpu(sdt->ref_tag) != ei_lba) {
printk(KERN_ERR "%s: REF check failed on sector %lu\n", pr_err("%s: REF check failed on sector %lu\n",
__func__, (unsigned long)sector); __func__, (unsigned long)sector);
dif_errors++; dif_errors++;
return 0x03; return 0x03;
} }
return 0;
}
static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
unsigned int sectors, u32 ei_lba)
{
unsigned int i, resid;
struct scatterlist *psgl;
struct sd_dif_tuple *sdt;
sector_t sector;
sector_t tmp_sec = start_sec;
void *paddr;
start_sec = do_div(tmp_sec, sdebug_store_sectors);
sdt = dif_storep + start_sec;
for (i = 0 ; i < sectors ; i++) {
int ret;
if (sdt[i].app_tag == 0xffff)
continue;
sector = start_sec + i;
ret = dif_verify(&sdt[i],
fake_storep + sector * scsi_debug_sector_size,
sector, ei_lba);
if (ret) {
dif_errors++;
return ret;
}
ei_lba++; ei_lba++;
} }
...@@ -1880,7 +1890,6 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, ...@@ -1880,7 +1890,6 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
sector_t tmp_sec = start_sec; sector_t tmp_sec = start_sec;
sector_t sector; sector_t sector;
int ppage_offset; int ppage_offset;
unsigned short csum;
sector = do_div(tmp_sec, sdebug_store_sectors); sector = do_div(tmp_sec, sdebug_store_sectors);
...@@ -1911,50 +1920,8 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec, ...@@ -1911,50 +1920,8 @@ static int prot_verify_write(struct scsi_cmnd *SCpnt, sector_t start_sec,
sdt = paddr + ppage_offset; sdt = paddr + ppage_offset;
switch (scsi_debug_guard) { ret = dif_verify(sdt, daddr + j, start_sec, ei_lba);
case 1: if (ret) {
csum = ip_compute_csum(daddr + j,
scsi_debug_sector_size);
break;
case 0:
csum = cpu_to_be16(crc_t10dif(daddr + j,
scsi_debug_sector_size));
break;
default:
BUG();
ret = 0;
goto out;
}
if (sdt->guard_tag != csum) {
printk(KERN_ERR
"%s: GUARD check failed on sector %lu " \
"rcvd 0x%04x, calculated 0x%04x\n",
__func__, (unsigned long)sector,
be16_to_cpu(sdt->guard_tag),
be16_to_cpu(csum));
ret = 0x01;
dump_sector(daddr + j, scsi_debug_sector_size);
goto out;
}
if (scsi_debug_dif == SD_DIF_TYPE1_PROTECTION &&
be32_to_cpu(sdt->ref_tag)
!= (start_sec & 0xffffffff)) {
printk(KERN_ERR
"%s: REF check failed on sector %lu\n",
__func__, (unsigned long)sector);
ret = 0x03;
dump_sector(daddr + j, scsi_debug_sector_size);
goto out;
}
if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
be32_to_cpu(sdt->ref_tag) != ei_lba) {
printk(KERN_ERR
"%s: REF check failed on sector %lu\n",
__func__, (unsigned long)sector);
ret = 0x03;
dump_sector(daddr + j, scsi_debug_sector_size); dump_sector(daddr + j, scsi_debug_sector_size);
goto out; goto out;
} }
......
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