diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2013-09-18 08:27:25 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-10-25 04:58:11 -0400 |
commit | bb8c063c6afcd930b8da944927144f2982609638 (patch) | |
tree | 2c056f02c74ac1965bd61b4d132c642782b4d7c5 | |
parent | 14faa944b6fa4c77a6f386806c33ce2c3c77b3a4 (diff) |
[SCSI] scsi_debug: factor out copying PI from dif_storep to prot_sglist
If data integrity support is enabled, prot_verify_read() is called in
response to READ commands and it verifies protection info from dif_storep
by comparing against fake_storep, and copies protection info to
prot_sglist.
This factors out the portion of copying protection info into a separate
function. It will also be reused in the next change after supporting
the opposite direction (copying prot_sglist to dif_storep).
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | drivers/scsi/scsi_debug.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f640b6b380bd..99e74d75cf08 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -1789,37 +1789,16 @@ static int dif_verify(struct sd_dif_tuple *sdt, const void *data, | |||
1789 | return 0; | 1789 | return 0; |
1790 | } | 1790 | } |
1791 | 1791 | ||
1792 | static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, | 1792 | static void dif_copy_prot(struct scsi_cmnd *SCpnt, sector_t sector, |
1793 | unsigned int sectors, u32 ei_lba) | 1793 | unsigned int sectors) |
1794 | { | 1794 | { |
1795 | unsigned int i, resid; | 1795 | unsigned int i, resid; |
1796 | struct scatterlist *psgl; | 1796 | struct scatterlist *psgl; |
1797 | struct sd_dif_tuple *sdt; | ||
1798 | sector_t sector; | ||
1799 | void *paddr; | 1797 | void *paddr; |
1800 | const void *dif_store_end = dif_storep + sdebug_store_sectors; | 1798 | const void *dif_store_end = dif_storep + sdebug_store_sectors; |
1801 | 1799 | ||
1802 | for (i = 0; i < sectors; i++) { | ||
1803 | int ret; | ||
1804 | |||
1805 | sector = start_sec + i; | ||
1806 | sdt = dif_store(sector); | ||
1807 | |||
1808 | if (sdt->app_tag == 0xffff) | ||
1809 | continue; | ||
1810 | |||
1811 | ret = dif_verify(sdt, fake_store(sector), sector, ei_lba); | ||
1812 | if (ret) { | ||
1813 | dif_errors++; | ||
1814 | return ret; | ||
1815 | } | ||
1816 | |||
1817 | ei_lba++; | ||
1818 | } | ||
1819 | |||
1820 | /* Bytes of protection data to copy into sgl */ | 1800 | /* Bytes of protection data to copy into sgl */ |
1821 | resid = sectors * sizeof(*dif_storep); | 1801 | resid = sectors * sizeof(*dif_storep); |
1822 | sector = start_sec; | ||
1823 | 1802 | ||
1824 | scsi_for_each_prot_sg(SCpnt, psgl, scsi_prot_sg_count(SCpnt), i) { | 1803 | scsi_for_each_prot_sg(SCpnt, psgl, scsi_prot_sg_count(SCpnt), i) { |
1825 | int len = min(psgl->length, resid); | 1804 | int len = min(psgl->length, resid); |
@@ -1839,7 +1818,34 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, | |||
1839 | resid -= len; | 1818 | resid -= len; |
1840 | kunmap_atomic(paddr); | 1819 | kunmap_atomic(paddr); |
1841 | } | 1820 | } |
1821 | } | ||
1822 | |||
1823 | static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, | ||
1824 | unsigned int sectors, u32 ei_lba) | ||
1825 | { | ||
1826 | unsigned int i; | ||
1827 | struct sd_dif_tuple *sdt; | ||
1828 | sector_t sector; | ||
1829 | |||
1830 | for (i = 0; i < sectors; i++) { | ||
1831 | int ret; | ||
1832 | |||
1833 | sector = start_sec + i; | ||
1834 | sdt = dif_store(sector); | ||
1835 | |||
1836 | if (sdt->app_tag == 0xffff) | ||
1837 | continue; | ||
1838 | |||
1839 | ret = dif_verify(sdt, fake_store(sector), sector, ei_lba); | ||
1840 | if (ret) { | ||
1841 | dif_errors++; | ||
1842 | return ret; | ||
1843 | } | ||
1844 | |||
1845 | ei_lba++; | ||
1846 | } | ||
1842 | 1847 | ||
1848 | dif_copy_prot(SCpnt, start_sec, sectors); | ||
1843 | dix_reads++; | 1849 | dix_reads++; |
1844 | 1850 | ||
1845 | return 0; | 1851 | return 0; |