aboutsummaryrefslogtreecommitdiffstats
path: root/fs/bio-integrity.c
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-11-23 20:20:16 -0500
committerKent Overstreet <kmo@daterainc.com>2013-11-24 01:33:50 -0500
commitd57a5f7c6605f15f3b5134837e68b448a7cea88e (patch)
tree95088fe201493ff655fc4da1fe159aca0e8f53dc /fs/bio-integrity.c
parent1cb9dda4f4332aa560a2db39f92a96e1a8273cf8 (diff)
bio-integrity: Convert to bvec_iter
The bio integrity is also stored in a bvec array, so if we use the bvec iter code we just added, the integrity code won't need to implement its own iteration stuff (bio_integrity_mark_head(), bio_integrity_mark_tail()) Signed-off-by: Kent Overstreet <kmo@daterainc.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: "Martin K. Petersen" <martin.petersen@oracle.com> Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Diffstat (limited to 'fs/bio-integrity.c')
-rw-r--r--fs/bio-integrity.c108
1 files changed, 26 insertions, 82 deletions
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 9127db86f315..fed744b8c9e5 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -134,8 +134,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
134 return 0; 134 return 0;
135 } 135 }
136 136
137 iv = bip_vec_idx(bip, bip->bip_vcnt); 137 iv = bip->bip_vec + bip->bip_vcnt;
138 BUG_ON(iv == NULL);
139 138
140 iv->bv_page = page; 139 iv->bv_page = page;
141 iv->bv_len = len; 140 iv->bv_len = len;
@@ -203,6 +202,12 @@ static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
203 return sectors; 202 return sectors;
204} 203}
205 204
205static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
206 unsigned int sectors)
207{
208 return bio_integrity_hw_sectors(bi, sectors) * bi->tuple_size;
209}
210
206/** 211/**
207 * bio_integrity_tag_size - Retrieve integrity tag space 212 * bio_integrity_tag_size - Retrieve integrity tag space
208 * @bio: bio to inspect 213 * @bio: bio to inspect
@@ -235,9 +240,9 @@ int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len, int set)
235 nr_sectors = bio_integrity_hw_sectors(bi, 240 nr_sectors = bio_integrity_hw_sectors(bi,
236 DIV_ROUND_UP(len, bi->tag_size)); 241 DIV_ROUND_UP(len, bi->tag_size));
237 242
238 if (nr_sectors * bi->tuple_size > bip->bip_size) { 243 if (nr_sectors * bi->tuple_size > bip->bip_iter.bi_size) {
239 printk(KERN_ERR "%s: tag too big for bio: %u > %u\n", 244 printk(KERN_ERR "%s: tag too big for bio: %u > %u\n", __func__,
240 __func__, nr_sectors * bi->tuple_size, bip->bip_size); 245 nr_sectors * bi->tuple_size, bip->bip_iter.bi_size);
241 return -1; 246 return -1;
242 } 247 }
243 248
@@ -322,7 +327,7 @@ static void bio_integrity_generate(struct bio *bio)
322 sector += sectors; 327 sector += sectors;
323 prot_buf += sectors * bi->tuple_size; 328 prot_buf += sectors * bi->tuple_size;
324 total += sectors * bi->tuple_size; 329 total += sectors * bi->tuple_size;
325 BUG_ON(total > bio->bi_integrity->bip_size); 330 BUG_ON(total > bio->bi_integrity->bip_iter.bi_size);
326 331
327 kunmap_atomic(kaddr); 332 kunmap_atomic(kaddr);
328 } 333 }
@@ -387,8 +392,8 @@ int bio_integrity_prep(struct bio *bio)
387 392
388 bip->bip_owns_buf = 1; 393 bip->bip_owns_buf = 1;
389 bip->bip_buf = buf; 394 bip->bip_buf = buf;
390 bip->bip_size = len; 395 bip->bip_iter.bi_size = len;
391 bip->bip_sector = bio->bi_iter.bi_sector; 396 bip->bip_iter.bi_sector = bio->bi_iter.bi_sector;
392 397
393 /* Map it */ 398 /* Map it */
394 offset = offset_in_page(buf); 399 offset = offset_in_page(buf);
@@ -444,7 +449,7 @@ static int bio_integrity_verify(struct bio *bio)
444 struct blk_integrity_exchg bix; 449 struct blk_integrity_exchg bix;
445 struct bio_vec bv; 450 struct bio_vec bv;
446 struct bvec_iter iter; 451 struct bvec_iter iter;
447 sector_t sector = bio->bi_integrity->bip_sector; 452 sector_t sector = bio->bi_integrity->bip_iter.bi_sector;
448 unsigned int sectors, total, ret; 453 unsigned int sectors, total, ret;
449 void *prot_buf = bio->bi_integrity->bip_buf; 454 void *prot_buf = bio->bi_integrity->bip_buf;
450 455
@@ -470,7 +475,7 @@ static int bio_integrity_verify(struct bio *bio)
470 sector += sectors; 475 sector += sectors;
471 prot_buf += sectors * bi->tuple_size; 476 prot_buf += sectors * bi->tuple_size;
472 total += sectors * bi->tuple_size; 477 total += sectors * bi->tuple_size;
473 BUG_ON(total > bio->bi_integrity->bip_size); 478 BUG_ON(total > bio->bi_integrity->bip_iter.bi_size);
474 479
475 kunmap_atomic(kaddr); 480 kunmap_atomic(kaddr);
476 } 481 }
@@ -535,56 +540,6 @@ void bio_integrity_endio(struct bio *bio, int error)
535EXPORT_SYMBOL(bio_integrity_endio); 540EXPORT_SYMBOL(bio_integrity_endio);
536 541
537/** 542/**
538 * bio_integrity_mark_head - Advance bip_vec skip bytes
539 * @bip: Integrity vector to advance
540 * @skip: Number of bytes to advance it
541 */
542void bio_integrity_mark_head(struct bio_integrity_payload *bip,
543 unsigned int skip)
544{
545 struct bio_vec *iv;
546 unsigned int i;
547
548 bip_for_each_vec(iv, bip, i) {
549 if (skip == 0) {
550 bip->bip_idx = i;
551 return;
552 } else if (skip >= iv->bv_len) {
553 skip -= iv->bv_len;
554 } else { /* skip < iv->bv_len) */
555 iv->bv_offset += skip;
556 iv->bv_len -= skip;
557 bip->bip_idx = i;
558 return;
559 }
560 }
561}
562
563/**
564 * bio_integrity_mark_tail - Truncate bip_vec to be len bytes long
565 * @bip: Integrity vector to truncate
566 * @len: New length of integrity vector
567 */
568void bio_integrity_mark_tail(struct bio_integrity_payload *bip,
569 unsigned int len)
570{
571 struct bio_vec *iv;
572 unsigned int i;
573
574 bip_for_each_vec(iv, bip, i) {
575 if (len == 0) {
576 bip->bip_vcnt = i;
577 return;
578 } else if (len >= iv->bv_len) {
579 len -= iv->bv_len;
580 } else { /* len < iv->bv_len) */
581 iv->bv_len = len;
582 len = 0;
583 }
584 }
585}
586
587/**
588 * bio_integrity_advance - Advance integrity vector 543 * bio_integrity_advance - Advance integrity vector
589 * @bio: bio whose integrity vector to update 544 * @bio: bio whose integrity vector to update
590 * @bytes_done: number of data bytes that have been completed 545 * @bytes_done: number of data bytes that have been completed
@@ -597,13 +552,9 @@ void bio_integrity_advance(struct bio *bio, unsigned int bytes_done)
597{ 552{
598 struct bio_integrity_payload *bip = bio->bi_integrity; 553 struct bio_integrity_payload *bip = bio->bi_integrity;
599 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 554 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
600 unsigned int nr_sectors; 555 unsigned bytes = bio_integrity_bytes(bi, bytes_done >> 9);
601 556
602 BUG_ON(bip == NULL); 557 bvec_iter_advance(bip->bip_vec, &bip->bip_iter, bytes);
603 BUG_ON(bi == NULL);
604
605 nr_sectors = bio_integrity_hw_sectors(bi, bytes_done >> 9);
606 bio_integrity_mark_head(bip, nr_sectors * bi->tuple_size);
607} 558}
608EXPORT_SYMBOL(bio_integrity_advance); 559EXPORT_SYMBOL(bio_integrity_advance);
609 560
@@ -623,16 +574,9 @@ void bio_integrity_trim(struct bio *bio, unsigned int offset,
623{ 574{
624 struct bio_integrity_payload *bip = bio->bi_integrity; 575 struct bio_integrity_payload *bip = bio->bi_integrity;
625 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 576 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
626 unsigned int nr_sectors;
627 577
628 BUG_ON(bip == NULL); 578 bio_integrity_advance(bio, offset << 9);
629 BUG_ON(bi == NULL); 579 bip->bip_iter.bi_size = bio_integrity_bytes(bi, sectors);
630 BUG_ON(!bio_flagged(bio, BIO_CLONED));
631
632 nr_sectors = bio_integrity_hw_sectors(bi, sectors);
633 bip->bip_sector = bip->bip_sector + offset;
634 bio_integrity_mark_head(bip, offset * bi->tuple_size);
635 bio_integrity_mark_tail(bip, sectors * bi->tuple_size);
636} 580}
637EXPORT_SYMBOL(bio_integrity_trim); 581EXPORT_SYMBOL(bio_integrity_trim);
638 582
@@ -662,8 +606,8 @@ void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
662 bp->bio1.bi_integrity = &bp->bip1; 606 bp->bio1.bi_integrity = &bp->bip1;
663 bp->bio2.bi_integrity = &bp->bip2; 607 bp->bio2.bi_integrity = &bp->bip2;
664 608
665 bp->iv1 = bip->bip_vec[bip->bip_idx]; 609 bp->iv1 = bip->bip_vec[bip->bip_iter.bi_idx];
666 bp->iv2 = bip->bip_vec[bip->bip_idx]; 610 bp->iv2 = bip->bip_vec[bip->bip_iter.bi_idx];
667 611
668 bp->bip1.bip_vec = &bp->iv1; 612 bp->bip1.bip_vec = &bp->iv1;
669 bp->bip2.bip_vec = &bp->iv2; 613 bp->bip2.bip_vec = &bp->iv2;
@@ -672,11 +616,12 @@ void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
672 bp->iv2.bv_offset += sectors * bi->tuple_size; 616 bp->iv2.bv_offset += sectors * bi->tuple_size;
673 bp->iv2.bv_len -= sectors * bi->tuple_size; 617 bp->iv2.bv_len -= sectors * bi->tuple_size;
674 618
675 bp->bip1.bip_sector = bio->bi_integrity->bip_sector; 619 bp->bip1.bip_iter.bi_sector = bio->bi_integrity->bip_iter.bi_sector;
676 bp->bip2.bip_sector = bio->bi_integrity->bip_sector + nr_sectors; 620 bp->bip2.bip_iter.bi_sector =
621 bio->bi_integrity->bip_iter.bi_sector + nr_sectors;
677 622
678 bp->bip1.bip_vcnt = bp->bip2.bip_vcnt = 1; 623 bp->bip1.bip_vcnt = bp->bip2.bip_vcnt = 1;
679 bp->bip1.bip_idx = bp->bip2.bip_idx = 0; 624 bp->bip1.bip_iter.bi_idx = bp->bip2.bip_iter.bi_idx = 0;
680} 625}
681EXPORT_SYMBOL(bio_integrity_split); 626EXPORT_SYMBOL(bio_integrity_split);
682 627
@@ -704,9 +649,8 @@ int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
704 memcpy(bip->bip_vec, bip_src->bip_vec, 649 memcpy(bip->bip_vec, bip_src->bip_vec,
705 bip_src->bip_vcnt * sizeof(struct bio_vec)); 650 bip_src->bip_vcnt * sizeof(struct bio_vec));
706 651
707 bip->bip_sector = bip_src->bip_sector;
708 bip->bip_vcnt = bip_src->bip_vcnt; 652 bip->bip_vcnt = bip_src->bip_vcnt;
709 bip->bip_idx = bip_src->bip_idx; 653 bip->bip_iter = bip_src->bip_iter;
710 654
711 return 0; 655 return 0;
712} 656}