diff options
| -rw-r--r-- | fs/bio-integrity.c | 85 | ||||
| -rw-r--r-- | fs/bio.c | 9 | ||||
| -rw-r--r-- | include/linux/bio.h | 18 |
3 files changed, 32 insertions, 80 deletions
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c index fe2b1aa2464e..31c46a241bac 100644 --- a/fs/bio-integrity.c +++ b/fs/bio-integrity.c | |||
| @@ -26,23 +26,23 @@ | |||
| 26 | #include <linux/workqueue.h> | 26 | #include <linux/workqueue.h> |
| 27 | 27 | ||
| 28 | static struct kmem_cache *bio_integrity_slab __read_mostly; | 28 | static struct kmem_cache *bio_integrity_slab __read_mostly; |
| 29 | static mempool_t *bio_integrity_pool; | ||
| 30 | static struct bio_set *integrity_bio_set; | ||
| 29 | static struct workqueue_struct *kintegrityd_wq; | 31 | static struct workqueue_struct *kintegrityd_wq; |
| 30 | 32 | ||
| 31 | /** | 33 | /** |
| 32 | * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio | 34 | * bio_integrity_alloc - Allocate integrity payload and attach it to bio |
| 33 | * @bio: bio to attach integrity metadata to | 35 | * @bio: bio to attach integrity metadata to |
| 34 | * @gfp_mask: Memory allocation mask | 36 | * @gfp_mask: Memory allocation mask |
| 35 | * @nr_vecs: Number of integrity metadata scatter-gather elements | 37 | * @nr_vecs: Number of integrity metadata scatter-gather elements |
| 36 | * @bs: bio_set to allocate from | ||
| 37 | * | 38 | * |
| 38 | * Description: This function prepares a bio for attaching integrity | 39 | * Description: This function prepares a bio for attaching integrity |
| 39 | * metadata. nr_vecs specifies the maximum number of pages containing | 40 | * metadata. nr_vecs specifies the maximum number of pages containing |
| 40 | * integrity metadata that can be attached. | 41 | * integrity metadata that can be attached. |
| 41 | */ | 42 | */ |
| 42 | struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | 43 | struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, |
| 43 | gfp_t gfp_mask, | 44 | gfp_t gfp_mask, |
| 44 | unsigned int nr_vecs, | 45 | unsigned int nr_vecs) |
| 45 | struct bio_set *bs) | ||
| 46 | { | 46 | { |
| 47 | struct bio_integrity_payload *bip; | 47 | struct bio_integrity_payload *bip; |
| 48 | struct bio_vec *iv; | 48 | struct bio_vec *iv; |
| @@ -50,7 +50,7 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | |||
| 50 | 50 | ||
| 51 | BUG_ON(bio == NULL); | 51 | BUG_ON(bio == NULL); |
| 52 | 52 | ||
| 53 | bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask); | 53 | bip = mempool_alloc(bio_integrity_pool, gfp_mask); |
| 54 | if (unlikely(bip == NULL)) { | 54 | if (unlikely(bip == NULL)) { |
| 55 | printk(KERN_ERR "%s: could not alloc bip\n", __func__); | 55 | printk(KERN_ERR "%s: could not alloc bip\n", __func__); |
| 56 | return NULL; | 56 | return NULL; |
| @@ -58,10 +58,10 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | |||
| 58 | 58 | ||
| 59 | memset(bip, 0, sizeof(*bip)); | 59 | memset(bip, 0, sizeof(*bip)); |
| 60 | 60 | ||
| 61 | iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, bs); | 61 | iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, integrity_bio_set); |
| 62 | if (unlikely(iv == NULL)) { | 62 | if (unlikely(iv == NULL)) { |
| 63 | printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__); | 63 | printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__); |
| 64 | mempool_free(bip, bs->bio_integrity_pool); | 64 | mempool_free(bip, bio_integrity_pool); |
| 65 | return NULL; | 65 | return NULL; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -72,35 +72,16 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | |||
| 72 | 72 | ||
| 73 | return bip; | 73 | return bip; |
| 74 | } | 74 | } |
| 75 | EXPORT_SYMBOL(bio_integrity_alloc_bioset); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * bio_integrity_alloc - Allocate integrity payload and attach it to bio | ||
| 79 | * @bio: bio to attach integrity metadata to | ||
| 80 | * @gfp_mask: Memory allocation mask | ||
| 81 | * @nr_vecs: Number of integrity metadata scatter-gather elements | ||
| 82 | * | ||
| 83 | * Description: This function prepares a bio for attaching integrity | ||
| 84 | * metadata. nr_vecs specifies the maximum number of pages containing | ||
| 85 | * integrity metadata that can be attached. | ||
| 86 | */ | ||
| 87 | struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, | ||
| 88 | gfp_t gfp_mask, | ||
| 89 | unsigned int nr_vecs) | ||
| 90 | { | ||
| 91 | return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set); | ||
| 92 | } | ||
| 93 | EXPORT_SYMBOL(bio_integrity_alloc); | 75 | EXPORT_SYMBOL(bio_integrity_alloc); |
| 94 | 76 | ||
| 95 | /** | 77 | /** |
| 96 | * bio_integrity_free - Free bio integrity payload | 78 | * bio_integrity_free - Free bio integrity payload |
| 97 | * @bio: bio containing bip to be freed | 79 | * @bio: bio containing bip to be freed |
| 98 | * @bs: bio_set this bio was allocated from | ||
| 99 | * | 80 | * |
| 100 | * Description: Used to free the integrity portion of a bio. Usually | 81 | * Description: Used to free the integrity portion of a bio. Usually |
| 101 | * called from bio_free(). | 82 | * called from bio_free(). |
| 102 | */ | 83 | */ |
| 103 | void bio_integrity_free(struct bio *bio, struct bio_set *bs) | 84 | void bio_integrity_free(struct bio *bio) |
| 104 | { | 85 | { |
| 105 | struct bio_integrity_payload *bip = bio->bi_integrity; | 86 | struct bio_integrity_payload *bip = bio->bi_integrity; |
| 106 | 87 | ||
| @@ -111,8 +92,8 @@ void bio_integrity_free(struct bio *bio, struct bio_set *bs) | |||
| 111 | && bip->bip_buf != NULL) | 92 | && bip->bip_buf != NULL) |
| 112 | kfree(bip->bip_buf); | 93 | kfree(bip->bip_buf); |
| 113 | 94 | ||
| 114 | bvec_free_bs(bs, bip->bip_vec, bip->bip_pool); | 95 | bvec_free_bs(integrity_bio_set, bip->bip_vec, bip->bip_pool); |
| 115 | mempool_free(bip, bs->bio_integrity_pool); | 96 | mempool_free(bip, bio_integrity_pool); |
| 116 | 97 | ||
| 117 | bio->bi_integrity = NULL; | 98 | bio->bi_integrity = NULL; |
| 118 | } | 99 | } |
| @@ -686,19 +667,17 @@ EXPORT_SYMBOL(bio_integrity_split); | |||
| 686 | * @bio: New bio | 667 | * @bio: New bio |
| 687 | * @bio_src: Original bio | 668 | * @bio_src: Original bio |
| 688 | * @gfp_mask: Memory allocation mask | 669 | * @gfp_mask: Memory allocation mask |
| 689 | * @bs: bio_set to allocate bip from | ||
| 690 | * | 670 | * |
| 691 | * Description: Called to allocate a bip when cloning a bio | 671 | * Description: Called to allocate a bip when cloning a bio |
| 692 | */ | 672 | */ |
| 693 | int bio_integrity_clone(struct bio *bio, struct bio *bio_src, | 673 | int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask) |
| 694 | gfp_t gfp_mask, struct bio_set *bs) | ||
| 695 | { | 674 | { |
| 696 | struct bio_integrity_payload *bip_src = bio_src->bi_integrity; | 675 | struct bio_integrity_payload *bip_src = bio_src->bi_integrity; |
| 697 | struct bio_integrity_payload *bip; | 676 | struct bio_integrity_payload *bip; |
| 698 | 677 | ||
| 699 | BUG_ON(bip_src == NULL); | 678 | BUG_ON(bip_src == NULL); |
| 700 | 679 | ||
| 701 | bip = bio_integrity_alloc_bioset(bio, gfp_mask, bip_src->bip_vcnt, bs); | 680 | bip = bio_integrity_alloc(bio, gfp_mask, bip_src->bip_vcnt); |
| 702 | 681 | ||
| 703 | if (bip == NULL) | 682 | if (bip == NULL) |
| 704 | return -EIO; | 683 | return -EIO; |
| @@ -714,37 +693,25 @@ int bio_integrity_clone(struct bio *bio, struct bio *bio_src, | |||
| 714 | } | 693 | } |
| 715 | EXPORT_SYMBOL(bio_integrity_clone); | 694 | EXPORT_SYMBOL(bio_integrity_clone); |
| 716 | 695 | ||
| 717 | int bioset_integrity_create(struct bio_set *bs, int pool_size) | 696 | static int __init bio_integrity_init(void) |
| 718 | { | 697 | { |
| 719 | bs->bio_integrity_pool = mempool_create_slab_pool(pool_size, | 698 | kintegrityd_wq = create_workqueue("kintegrityd"); |
| 720 | bio_integrity_slab); | ||
| 721 | if (!bs->bio_integrity_pool) | ||
| 722 | return -1; | ||
| 723 | |||
| 724 | return 0; | ||
| 725 | } | ||
| 726 | EXPORT_SYMBOL(bioset_integrity_create); | ||
| 727 | 699 | ||
| 728 | void bioset_integrity_free(struct bio_set *bs) | 700 | if (!kintegrityd_wq) |
| 729 | { | 701 | panic("Failed to create kintegrityd\n"); |
| 730 | if (bs->bio_integrity_pool) | ||
| 731 | mempool_destroy(bs->bio_integrity_pool); | ||
| 732 | } | ||
| 733 | EXPORT_SYMBOL(bioset_integrity_free); | ||
| 734 | 702 | ||
| 735 | void __init bio_integrity_init_slab(void) | ||
| 736 | { | ||
| 737 | bio_integrity_slab = KMEM_CACHE(bio_integrity_payload, | 703 | bio_integrity_slab = KMEM_CACHE(bio_integrity_payload, |
| 738 | SLAB_HWCACHE_ALIGN|SLAB_PANIC); | 704 | SLAB_HWCACHE_ALIGN|SLAB_PANIC); |
| 739 | } | ||
| 740 | 705 | ||
| 741 | static int __init integrity_init(void) | 706 | bio_integrity_pool = mempool_create_slab_pool(BIO_POOL_SIZE, |
| 742 | { | 707 | bio_integrity_slab); |
| 743 | kintegrityd_wq = create_workqueue("kintegrityd"); | 708 | if (!bio_integrity_pool) |
| 709 | panic("bio_integrity: can't allocate bip pool\n"); | ||
| 744 | 710 | ||
| 745 | if (!kintegrityd_wq) | 711 | integrity_bio_set = bioset_create(BIO_POOL_SIZE, 0); |
| 746 | panic("Failed to create kintegrityd\n"); | 712 | if (!integrity_bio_set) |
| 713 | panic("bio_integrity: can't allocate bio_set\n"); | ||
| 747 | 714 | ||
| 748 | return 0; | 715 | return 0; |
| 749 | } | 716 | } |
| 750 | subsys_initcall(integrity_init); | 717 | subsys_initcall(bio_integrity_init); |
| @@ -248,7 +248,7 @@ void bio_free(struct bio *bio, struct bio_set *bs) | |||
| 248 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | 248 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); |
| 249 | 249 | ||
| 250 | if (bio_integrity(bio)) | 250 | if (bio_integrity(bio)) |
| 251 | bio_integrity_free(bio, bs); | 251 | bio_integrity_free(bio); |
| 252 | 252 | ||
| 253 | /* | 253 | /* |
| 254 | * If we have front padding, adjust the bio pointer before freeing | 254 | * If we have front padding, adjust the bio pointer before freeing |
| @@ -466,7 +466,7 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask) | |||
| 466 | if (bio_integrity(bio)) { | 466 | if (bio_integrity(bio)) { |
| 467 | int ret; | 467 | int ret; |
| 468 | 468 | ||
| 469 | ret = bio_integrity_clone(b, bio, gfp_mask, fs_bio_set); | 469 | ret = bio_integrity_clone(b, bio, gfp_mask); |
| 470 | 470 | ||
| 471 | if (ret < 0) { | 471 | if (ret < 0) { |
| 472 | bio_put(b); | 472 | bio_put(b); |
| @@ -1529,7 +1529,6 @@ void bioset_free(struct bio_set *bs) | |||
| 1529 | if (bs->bio_pool) | 1529 | if (bs->bio_pool) |
| 1530 | mempool_destroy(bs->bio_pool); | 1530 | mempool_destroy(bs->bio_pool); |
| 1531 | 1531 | ||
| 1532 | bioset_integrity_free(bs); | ||
| 1533 | biovec_free_pools(bs); | 1532 | biovec_free_pools(bs); |
| 1534 | bio_put_slab(bs); | 1533 | bio_put_slab(bs); |
| 1535 | 1534 | ||
| @@ -1570,9 +1569,6 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad) | |||
| 1570 | if (!bs->bio_pool) | 1569 | if (!bs->bio_pool) |
| 1571 | goto bad; | 1570 | goto bad; |
| 1572 | 1571 | ||
| 1573 | if (bioset_integrity_create(bs, pool_size)) | ||
| 1574 | goto bad; | ||
| 1575 | |||
| 1576 | if (!biovec_create_pools(bs, pool_size)) | 1572 | if (!biovec_create_pools(bs, pool_size)) |
| 1577 | return bs; | 1573 | return bs; |
| 1578 | 1574 | ||
| @@ -1610,7 +1606,6 @@ static int __init init_bio(void) | |||
| 1610 | if (!bio_slabs) | 1606 | if (!bio_slabs) |
| 1611 | panic("bio: can't allocate bios\n"); | 1607 | panic("bio: can't allocate bios\n"); |
| 1612 | 1608 | ||
| 1613 | bio_integrity_init_slab(); | ||
| 1614 | biovec_init_slabs(); | 1609 | biovec_init_slabs(); |
| 1615 | 1610 | ||
| 1616 | fs_bio_set = bioset_create(BIO_POOL_SIZE, 0); | 1611 | fs_bio_set = bioset_create(BIO_POOL_SIZE, 0); |
diff --git a/include/linux/bio.h b/include/linux/bio.h index d8bd43bfdcf5..b05b1d4d17d2 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
| @@ -426,9 +426,6 @@ struct bio_set { | |||
| 426 | unsigned int front_pad; | 426 | unsigned int front_pad; |
| 427 | 427 | ||
| 428 | mempool_t *bio_pool; | 428 | mempool_t *bio_pool; |
| 429 | #if defined(CONFIG_BLK_DEV_INTEGRITY) | ||
| 430 | mempool_t *bio_integrity_pool; | ||
| 431 | #endif | ||
| 432 | mempool_t *bvec_pool; | 429 | mempool_t *bvec_pool; |
| 433 | }; | 430 | }; |
| 434 | 431 | ||
| @@ -519,9 +516,8 @@ static inline int bio_has_data(struct bio *bio) | |||
| 519 | 516 | ||
| 520 | #define bio_integrity(bio) (bio->bi_integrity != NULL) | 517 | #define bio_integrity(bio) (bio->bi_integrity != NULL) |
| 521 | 518 | ||
| 522 | extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *); | ||
| 523 | extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); | 519 | extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); |
| 524 | extern void bio_integrity_free(struct bio *, struct bio_set *); | 520 | extern void bio_integrity_free(struct bio *); |
| 525 | extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int); | 521 | extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int); |
| 526 | extern int bio_integrity_enabled(struct bio *bio); | 522 | extern int bio_integrity_enabled(struct bio *bio); |
| 527 | extern int bio_integrity_set_tag(struct bio *, void *, unsigned int); | 523 | extern int bio_integrity_set_tag(struct bio *, void *, unsigned int); |
| @@ -531,27 +527,21 @@ extern void bio_integrity_endio(struct bio *, int); | |||
| 531 | extern void bio_integrity_advance(struct bio *, unsigned int); | 527 | extern void bio_integrity_advance(struct bio *, unsigned int); |
| 532 | extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int); | 528 | extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int); |
| 533 | extern void bio_integrity_split(struct bio *, struct bio_pair *, int); | 529 | extern void bio_integrity_split(struct bio *, struct bio_pair *, int); |
| 534 | extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t, struct bio_set *); | 530 | extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t); |
| 535 | extern int bioset_integrity_create(struct bio_set *, int); | ||
| 536 | extern void bioset_integrity_free(struct bio_set *); | ||
| 537 | extern void bio_integrity_init_slab(void); | ||
| 538 | 531 | ||
| 539 | #else /* CONFIG_BLK_DEV_INTEGRITY */ | 532 | #else /* CONFIG_BLK_DEV_INTEGRITY */ |
| 540 | 533 | ||
| 541 | #define bio_integrity(a) (0) | 534 | #define bio_integrity(a) (0) |
| 542 | #define bioset_integrity_create(a, b) (0) | ||
| 543 | #define bio_integrity_prep(a) (0) | 535 | #define bio_integrity_prep(a) (0) |
| 544 | #define bio_integrity_enabled(a) (0) | 536 | #define bio_integrity_enabled(a) (0) |
| 545 | #define bio_integrity_clone(a, b, c,d ) (0) | 537 | #define bio_integrity_clone(a, b, c) (0) |
| 546 | #define bioset_integrity_free(a) do { } while (0) | 538 | #define bio_integrity_free(a) do { } while (0) |
| 547 | #define bio_integrity_free(a, b) do { } while (0) | ||
| 548 | #define bio_integrity_endio(a, b) do { } while (0) | 539 | #define bio_integrity_endio(a, b) do { } while (0) |
| 549 | #define bio_integrity_advance(a, b) do { } while (0) | 540 | #define bio_integrity_advance(a, b) do { } while (0) |
| 550 | #define bio_integrity_trim(a, b, c) do { } while (0) | 541 | #define bio_integrity_trim(a, b, c) do { } while (0) |
| 551 | #define bio_integrity_split(a, b, c) do { } while (0) | 542 | #define bio_integrity_split(a, b, c) do { } while (0) |
| 552 | #define bio_integrity_set_tag(a, b, c) do { } while (0) | 543 | #define bio_integrity_set_tag(a, b, c) do { } while (0) |
| 553 | #define bio_integrity_get_tag(a, b, c) do { } while (0) | 544 | #define bio_integrity_get_tag(a, b, c) do { } while (0) |
| 554 | #define bio_integrity_init_slab(a) do { } while (0) | ||
| 555 | 545 | ||
| 556 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | 546 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
| 557 | 547 | ||
