提交 3be91c4a 编写于 作者: M Martin K. Petersen 提交者: Jens Axboe

block: Deprecate the use of the term sector in the context of block integrity

The protection interval is not necessarily tied to the logical block
size of a block device. Stop using the terms "sector" and "sectors".

Going forward we will use the term "seed" to describe the initial
reference tag value for a given I/O. "Interval" will be used to describe
the portion of the data buffer that a given piece of protection
information is associated with.
Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NSagi Grimberg <sagig@mellanox.com>
Signed-off-by: NJens Axboe <axboe@fb.com>
上级 5f9378fa
...@@ -185,20 +185,20 @@ bool bio_integrity_enabled(struct bio *bio) ...@@ -185,20 +185,20 @@ bool bio_integrity_enabled(struct bio *bio)
EXPORT_SYMBOL(bio_integrity_enabled); EXPORT_SYMBOL(bio_integrity_enabled);
/** /**
* bio_integrity_hw_sectors - Convert 512b sectors to hardware ditto * bio_integrity_intervals - Return number of integrity intervals for a bio
* @bi: blk_integrity profile for device * @bi: blk_integrity profile for device
* @sectors: Number of 512 sectors to convert * @sectors: Size of the bio in 512-byte sectors
* *
* Description: The block layer calculates everything in 512 byte * Description: The block layer calculates everything in 512 byte
* sectors but integrity metadata is done in terms of the hardware * sectors but integrity metadata is done in terms of the data integrity
* sector size of the storage device. Convert the block layer sectors * interval size of the storage device. Convert the block layer sectors
* to physical sectors. * to the appropriate number of integrity intervals.
*/ */
static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi, static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi,
unsigned int sectors) unsigned int sectors)
{ {
/* At this point there are only 512b or 4096b DIF/EPP devices */ /* At this point there are only 512b or 4096b DIF/EPP devices */
if (bi->sector_size == 4096) if (bi->interval == 4096)
return sectors >>= 3; return sectors >>= 3;
return sectors; return sectors;
...@@ -207,7 +207,7 @@ static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi, ...@@ -207,7 +207,7 @@ static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
unsigned int sectors) unsigned int sectors)
{ {
return bio_integrity_hw_sectors(bi, sectors) * bi->tuple_size; return bio_integrity_intervals(bi, sectors) * bi->tuple_size;
} }
/** /**
...@@ -221,25 +221,25 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate) ...@@ -221,25 +221,25 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate)
struct blk_integrity_exchg bix; struct blk_integrity_exchg bix;
struct bio_vec *bv; struct bio_vec *bv;
struct bio_integrity_payload *bip = bio_integrity(bio); struct bio_integrity_payload *bip = bio_integrity(bio);
sector_t sector; sector_t seed;
unsigned int sectors, ret = 0, i; unsigned int intervals, ret = 0, i;
void *prot_buf = page_address(bip->bip_vec->bv_page) + void *prot_buf = page_address(bip->bip_vec->bv_page) +
bip->bip_vec->bv_offset; bip->bip_vec->bv_offset;
if (operate) if (operate)
sector = bio->bi_iter.bi_sector; seed = bio->bi_iter.bi_sector;
else else
sector = bip->bip_iter.bi_sector; seed = bip->bip_iter.bi_sector;
bix.disk_name = bio->bi_bdev->bd_disk->disk_name; bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
bix.sector_size = bi->sector_size; bix.interval = bi->interval;
bio_for_each_segment_all(bv, bio, i) { bio_for_each_segment_all(bv, bio, i) {
void *kaddr = kmap_atomic(bv->bv_page); void *kaddr = kmap_atomic(bv->bv_page);
bix.data_buf = kaddr + bv->bv_offset; bix.data_buf = kaddr + bv->bv_offset;
bix.data_size = bv->bv_len; bix.data_size = bv->bv_len;
bix.prot_buf = prot_buf; bix.prot_buf = prot_buf;
bix.sector = sector; bix.seed = seed;
if (operate) if (operate)
bi->generate_fn(&bix); bi->generate_fn(&bix);
...@@ -251,9 +251,9 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate) ...@@ -251,9 +251,9 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate)
} }
} }
sectors = bv->bv_len / bi->sector_size; intervals = bv->bv_len / bi->interval;
sector += sectors; seed += intervals;
prot_buf += sectors * bi->tuple_size; prot_buf += intervals * bi->tuple_size;
kunmap_atomic(kaddr); kunmap_atomic(kaddr);
} }
...@@ -294,17 +294,17 @@ int bio_integrity_prep(struct bio *bio) ...@@ -294,17 +294,17 @@ int bio_integrity_prep(struct bio *bio)
unsigned long start, end; unsigned long start, end;
unsigned int len, nr_pages; unsigned int len, nr_pages;
unsigned int bytes, offset, i; unsigned int bytes, offset, i;
unsigned int sectors; unsigned int intervals;
bi = bdev_get_integrity(bio->bi_bdev); bi = bdev_get_integrity(bio->bi_bdev);
q = bdev_get_queue(bio->bi_bdev); q = bdev_get_queue(bio->bi_bdev);
BUG_ON(bi == NULL); BUG_ON(bi == NULL);
BUG_ON(bio_integrity(bio)); BUG_ON(bio_integrity(bio));
sectors = bio_integrity_hw_sectors(bi, bio_sectors(bio)); intervals = bio_integrity_intervals(bi, bio_sectors(bio));
/* Allocate kernel buffer for protection data */ /* Allocate kernel buffer for protection data */
len = sectors * bi->tuple_size; len = intervals * bi->tuple_size;
buf = kmalloc(len, GFP_NOIO | q->bounce_gfp); buf = kmalloc(len, GFP_NOIO | q->bounce_gfp);
if (unlikely(buf == NULL)) { if (unlikely(buf == NULL)) {
printk(KERN_ERR "could not allocate integrity buffer\n"); printk(KERN_ERR "could not allocate integrity buffer\n");
......
...@@ -154,10 +154,10 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2) ...@@ -154,10 +154,10 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
if (!b1 || !b2) if (!b1 || !b2)
return -1; return -1;
if (b1->sector_size != b2->sector_size) { if (b1->interval != b2->interval) {
printk(KERN_ERR "%s: %s/%s sector sz %u != %u\n", __func__, pr_err("%s: %s/%s protection interval %u != %u\n",
gd1->disk_name, gd2->disk_name, __func__, gd1->disk_name, gd2->disk_name,
b1->sector_size, b2->sector_size); b1->interval, b2->interval);
return -1; return -1;
} }
...@@ -407,7 +407,7 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template) ...@@ -407,7 +407,7 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
kobject_uevent(&bi->kobj, KOBJ_ADD); kobject_uevent(&bi->kobj, KOBJ_ADD);
bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE; bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
bi->sector_size = queue_logical_block_size(disk->queue); bi->interval = queue_logical_block_size(disk->queue);
disk->integrity = bi; disk->integrity = bi;
} else } else
bi = disk->integrity; bi = disk->integrity;
......
...@@ -57,16 +57,16 @@ static void sd_dif_type1_generate(struct blk_integrity_exchg *bix, csum_fn *fn) ...@@ -57,16 +57,16 @@ static void sd_dif_type1_generate(struct blk_integrity_exchg *bix, csum_fn *fn)
{ {
void *buf = bix->data_buf; void *buf = bix->data_buf;
struct sd_dif_tuple *sdt = bix->prot_buf; struct sd_dif_tuple *sdt = bix->prot_buf;
sector_t sector = bix->sector; sector_t seed = bix->seed;
unsigned int i; unsigned int i;
for (i = 0 ; i < bix->data_size ; i += bix->sector_size, sdt++) { for (i = 0 ; i < bix->data_size ; i += bix->interval, sdt++) {
sdt->guard_tag = fn(buf, bix->sector_size); sdt->guard_tag = fn(buf, bix->interval);
sdt->ref_tag = cpu_to_be32(sector & 0xffffffff); sdt->ref_tag = cpu_to_be32(seed & 0xffffffff);
sdt->app_tag = 0; sdt->app_tag = 0;
buf += bix->sector_size; buf += bix->interval;
sector++; seed++;
} }
} }
...@@ -84,35 +84,35 @@ static int sd_dif_type1_verify(struct blk_integrity_exchg *bix, csum_fn *fn) ...@@ -84,35 +84,35 @@ static int sd_dif_type1_verify(struct blk_integrity_exchg *bix, csum_fn *fn)
{ {
void *buf = bix->data_buf; void *buf = bix->data_buf;
struct sd_dif_tuple *sdt = bix->prot_buf; struct sd_dif_tuple *sdt = bix->prot_buf;
sector_t sector = bix->sector; sector_t seed = bix->seed;
unsigned int i; unsigned int i;
__u16 csum; __u16 csum;
for (i = 0 ; i < bix->data_size ; i += bix->sector_size, sdt++) { for (i = 0 ; i < bix->data_size ; i += bix->interval, sdt++) {
/* Unwritten sectors */ /* Unwritten sectors */
if (sdt->app_tag == 0xffff) if (sdt->app_tag == 0xffff)
return 0; return 0;
if (be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { if (be32_to_cpu(sdt->ref_tag) != (seed & 0xffffffff)) {
printk(KERN_ERR printk(KERN_ERR
"%s: ref tag error on sector %lu (rcvd %u)\n", "%s: ref tag error on sector %lu (rcvd %u)\n",
bix->disk_name, (unsigned long)sector, bix->disk_name, (unsigned long)seed,
be32_to_cpu(sdt->ref_tag)); be32_to_cpu(sdt->ref_tag));
return -EIO; return -EIO;
} }
csum = fn(buf, bix->sector_size); csum = fn(buf, bix->interval);
if (sdt->guard_tag != csum) { if (sdt->guard_tag != csum) {
printk(KERN_ERR "%s: guard tag error on sector %lu " \ printk(KERN_ERR "%s: guard tag error on sector %lu " \
"(rcvd %04x, data %04x)\n", bix->disk_name, "(rcvd %04x, data %04x)\n", bix->disk_name,
(unsigned long)sector, (unsigned long)seed,
be16_to_cpu(sdt->guard_tag), be16_to_cpu(csum)); be16_to_cpu(sdt->guard_tag), be16_to_cpu(csum));
return -EIO; return -EIO;
} }
buf += bix->sector_size; buf += bix->interval;
sector++; seed++;
} }
return 0; return 0;
...@@ -155,12 +155,12 @@ static void sd_dif_type3_generate(struct blk_integrity_exchg *bix, csum_fn *fn) ...@@ -155,12 +155,12 @@ static void sd_dif_type3_generate(struct blk_integrity_exchg *bix, csum_fn *fn)
struct sd_dif_tuple *sdt = bix->prot_buf; struct sd_dif_tuple *sdt = bix->prot_buf;
unsigned int i; unsigned int i;
for (i = 0 ; i < bix->data_size ; i += bix->sector_size, sdt++) { for (i = 0 ; i < bix->data_size ; i += bix->interval, sdt++) {
sdt->guard_tag = fn(buf, bix->sector_size); sdt->guard_tag = fn(buf, bix->interval);
sdt->ref_tag = 0; sdt->ref_tag = 0;
sdt->app_tag = 0; sdt->app_tag = 0;
buf += bix->sector_size; buf += bix->interval;
} }
} }
...@@ -178,27 +178,27 @@ static int sd_dif_type3_verify(struct blk_integrity_exchg *bix, csum_fn *fn) ...@@ -178,27 +178,27 @@ static int sd_dif_type3_verify(struct blk_integrity_exchg *bix, csum_fn *fn)
{ {
void *buf = bix->data_buf; void *buf = bix->data_buf;
struct sd_dif_tuple *sdt = bix->prot_buf; struct sd_dif_tuple *sdt = bix->prot_buf;
sector_t sector = bix->sector; sector_t seed = bix->seed;
unsigned int i; unsigned int i;
__u16 csum; __u16 csum;
for (i = 0 ; i < bix->data_size ; i += bix->sector_size, sdt++) { for (i = 0 ; i < bix->data_size ; i += bix->interval, sdt++) {
/* Unwritten sectors */ /* Unwritten sectors */
if (sdt->app_tag == 0xffff && sdt->ref_tag == 0xffffffff) if (sdt->app_tag == 0xffff && sdt->ref_tag == 0xffffffff)
return 0; return 0;
csum = fn(buf, bix->sector_size); csum = fn(buf, bix->interval);
if (sdt->guard_tag != csum) { if (sdt->guard_tag != csum) {
printk(KERN_ERR "%s: guard tag error on sector %lu " \ printk(KERN_ERR "%s: guard tag error on sector %lu " \
"(rcvd %04x, data %04x)\n", bix->disk_name, "(rcvd %04x, data %04x)\n", bix->disk_name,
(unsigned long)sector, (unsigned long)seed,
be16_to_cpu(sdt->guard_tag), be16_to_cpu(csum)); be16_to_cpu(sdt->guard_tag), be16_to_cpu(csum));
return -EIO; return -EIO;
} }
buf += bix->sector_size; buf += bix->interval;
sector++; seed++;
} }
return 0; return 0;
......
...@@ -1464,9 +1464,9 @@ static inline uint64_t rq_io_start_time_ns(struct request *req) ...@@ -1464,9 +1464,9 @@ static inline uint64_t rq_io_start_time_ns(struct request *req)
struct blk_integrity_exchg { struct blk_integrity_exchg {
void *prot_buf; void *prot_buf;
void *data_buf; void *data_buf;
sector_t sector; sector_t seed;
unsigned int data_size; unsigned int data_size;
unsigned short sector_size; unsigned short interval;
const char *disk_name; const char *disk_name;
}; };
...@@ -1479,7 +1479,7 @@ struct blk_integrity { ...@@ -1479,7 +1479,7 @@ struct blk_integrity {
unsigned short flags; unsigned short flags;
unsigned short tuple_size; unsigned short tuple_size;
unsigned short sector_size; unsigned short interval;
unsigned short tag_size; unsigned short tag_size;
const char *name; const char *name;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册