aboutsummaryrefslogtreecommitdiffstats
path: root/fs/bio-integrity.c
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2014-02-21 05:10:59 -0500
committerJens Axboe <axboe@fb.com>2014-02-21 18:28:30 -0500
commitbf36f9cfa6d3d129387b9d62f495d978ed4ade7c (patch)
treee50b3eefcc3d908d033e6ae6d4e432e01ee430e7 /fs/bio-integrity.c
parentec6c676a08b0779a32c9cec9fae7532add32fe15 (diff)
fs/bio-integrity: remove duplicate code
Most code of function bio_integrity_verify and bio_integrity_generate is the same, so introduce a help function bio_integrity_generate_verify() to remove the duplicate code. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'fs/bio-integrity.c')
-rw-r--r--fs/bio-integrity.c86
1 files changed, 37 insertions, 49 deletions
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 0129b78a6908..413312f2b295 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -301,25 +301,26 @@ int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
301EXPORT_SYMBOL(bio_integrity_get_tag); 301EXPORT_SYMBOL(bio_integrity_get_tag);
302 302
303/** 303/**
304 * bio_integrity_generate - Generate integrity metadata for a bio 304 * bio_integrity_generate_verify - Generate/verify integrity metadata for a bio
305 * @bio: bio to generate integrity metadata for 305 * @bio: bio to generate/verify integrity metadata for
306 * 306 * @operate: operate number, 1 for generate, 0 for verify
307 * Description: Generates integrity metadata for a bio by calling the
308 * block device's generation callback function. The bio must have a
309 * bip attached with enough room to accommodate the generated
310 * integrity metadata.
311 */ 307 */
312static void bio_integrity_generate(struct bio *bio) 308static int bio_integrity_generate_verify(struct bio *bio, int operate)
313{ 309{
314 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 310 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
315 struct blk_integrity_exchg bix; 311 struct blk_integrity_exchg bix;
316 struct bio_vec bv; 312 struct bio_vec bv;
317 struct bvec_iter iter; 313 struct bvec_iter iter;
318 sector_t sector = bio->bi_iter.bi_sector; 314 sector_t sector;
319 unsigned int sectors, total; 315 unsigned int sectors, total, ret;
320 void *prot_buf = bio->bi_integrity->bip_buf; 316 void *prot_buf = bio->bi_integrity->bip_buf;
321 317
322 total = 0; 318 if (operate)
319 sector = bio->bi_iter.bi_sector;
320 else
321 sector = bio->bi_integrity->bip_iter.bi_sector;
322
323 total = ret = 0;
323 bix.disk_name = bio->bi_bdev->bd_disk->disk_name; 324 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
324 bix.sector_size = bi->sector_size; 325 bix.sector_size = bi->sector_size;
325 326
@@ -330,7 +331,15 @@ static void bio_integrity_generate(struct bio *bio)
330 bix.prot_buf = prot_buf; 331 bix.prot_buf = prot_buf;
331 bix.sector = sector; 332 bix.sector = sector;
332 333
333 bi->generate_fn(&bix); 334 if (operate) {
335 bi->generate_fn(&bix);
336 } else {
337 ret = bi->verify_fn(&bix);
338 if (ret) {
339 kunmap_atomic(kaddr);
340 return ret;
341 }
342 }
334 343
335 sectors = bv.bv_len / bi->sector_size; 344 sectors = bv.bv_len / bi->sector_size;
336 sector += sectors; 345 sector += sectors;
@@ -340,6 +349,21 @@ static void bio_integrity_generate(struct bio *bio)
340 349
341 kunmap_atomic(kaddr); 350 kunmap_atomic(kaddr);
342 } 351 }
352 return ret;
353}
354
355/**
356 * bio_integrity_generate - Generate integrity metadata for a bio
357 * @bio: bio to generate integrity metadata for
358 *
359 * Description: Generates integrity metadata for a bio by calling the
360 * block device's generation callback function. The bio must have a
361 * bip attached with enough room to accommodate the generated
362 * integrity metadata.
363 */
364static void bio_integrity_generate(struct bio *bio)
365{
366 bio_integrity_generate_verify(bio, 1);
343} 367}
344 368
345static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi) 369static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi)
@@ -454,43 +478,7 @@ EXPORT_SYMBOL(bio_integrity_prep);
454 */ 478 */
455static int bio_integrity_verify(struct bio *bio) 479static int bio_integrity_verify(struct bio *bio)
456{ 480{
457 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 481 return bio_integrity_generate_verify(bio, 0);
458 struct blk_integrity_exchg bix;
459 struct bio_vec *bv;
460 sector_t sector = bio->bi_integrity->bip_iter.bi_sector;
461 unsigned int sectors, total, ret;
462 void *prot_buf = bio->bi_integrity->bip_buf;
463 int i;
464
465 ret = total = 0;
466 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
467 bix.sector_size = bi->sector_size;
468
469 bio_for_each_segment_all(bv, bio, i) {
470 void *kaddr = kmap_atomic(bv->bv_page);
471
472 bix.data_buf = kaddr + bv->bv_offset;
473 bix.data_size = bv->bv_len;
474 bix.prot_buf = prot_buf;
475 bix.sector = sector;
476
477 ret = bi->verify_fn(&bix);
478
479 if (ret) {
480 kunmap_atomic(kaddr);
481 return ret;
482 }
483
484 sectors = bv->bv_len / bi->sector_size;
485 sector += sectors;
486 prot_buf += sectors * bi->tuple_size;
487 total += sectors * bi->tuple_size;
488 BUG_ON(total > bio->bi_integrity->bip_iter.bi_size);
489
490 kunmap_atomic(kaddr);
491 }
492
493 return ret;
494} 482}
495 483
496/** 484/**