diff options
Diffstat (limited to 'fs/bio-integrity.c')
| -rw-r--r-- | fs/bio-integrity.c | 85 |
1 files changed, 26 insertions, 59 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); |
