aboutsummaryrefslogtreecommitdiffstats
path: root/fs/bio.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/bio.c')
-rw-r--r--fs/bio.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/fs/bio.c b/fs/bio.c
index e49cf7dd2e92..a7d4fd3a3299 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -105,18 +105,22 @@ static inline struct bio_vec *bvec_alloc_bs(unsigned int __nocast gfp_mask, int
105 return bvl; 105 return bvl;
106} 106}
107 107
108/* 108void bio_free(struct bio *bio, struct bio_set *bio_set)
109 * default destructor for a bio allocated with bio_alloc_bioset()
110 */
111static void bio_destructor(struct bio *bio)
112{ 109{
113 const int pool_idx = BIO_POOL_IDX(bio); 110 const int pool_idx = BIO_POOL_IDX(bio);
114 struct bio_set *bs = bio->bi_set;
115 111
116 BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS); 112 BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS);
117 113
118 mempool_free(bio->bi_io_vec, bs->bvec_pools[pool_idx]); 114 mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]);
119 mempool_free(bio, bs->bio_pool); 115 mempool_free(bio, bio_set->bio_pool);
116}
117
118/*
119 * default destructor for a bio allocated with bio_alloc_bioset()
120 */
121static void bio_fs_destructor(struct bio *bio)
122{
123 bio_free(bio, fs_bio_set);
120} 124}
121 125
122inline void bio_init(struct bio *bio) 126inline void bio_init(struct bio *bio)
@@ -172,8 +176,6 @@ struct bio *bio_alloc_bioset(unsigned int __nocast gfp_mask, int nr_iovecs, stru
172 bio->bi_max_vecs = bvec_slabs[idx].nr_vecs; 176 bio->bi_max_vecs = bvec_slabs[idx].nr_vecs;
173 } 177 }
174 bio->bi_io_vec = bvl; 178 bio->bi_io_vec = bvl;
175 bio->bi_destructor = bio_destructor;
176 bio->bi_set = bs;
177 } 179 }
178out: 180out:
179 return bio; 181 return bio;
@@ -181,7 +183,12 @@ out:
181 183
182struct bio *bio_alloc(unsigned int __nocast gfp_mask, int nr_iovecs) 184struct bio *bio_alloc(unsigned int __nocast gfp_mask, int nr_iovecs)
183{ 185{
184 return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set); 186 struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
187
188 if (bio)
189 bio->bi_destructor = bio_fs_destructor;
190
191 return bio;
185} 192}
186 193
187void zero_fill_bio(struct bio *bio) 194void zero_fill_bio(struct bio *bio)
@@ -274,8 +281,10 @@ struct bio *bio_clone(struct bio *bio, unsigned int __nocast gfp_mask)
274{ 281{
275 struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set); 282 struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set);
276 283
277 if (b) 284 if (b) {
285 b->bi_destructor = bio_fs_destructor;
278 __bio_clone(b, bio); 286 __bio_clone(b, bio);
287 }
279 288
280 return b; 289 return b;
281} 290}
@@ -1211,6 +1220,7 @@ subsys_initcall(init_bio);
1211 1220
1212EXPORT_SYMBOL(bio_alloc); 1221EXPORT_SYMBOL(bio_alloc);
1213EXPORT_SYMBOL(bio_put); 1222EXPORT_SYMBOL(bio_put);
1223EXPORT_SYMBOL(bio_free);
1214EXPORT_SYMBOL(bio_endio); 1224EXPORT_SYMBOL(bio_endio);
1215EXPORT_SYMBOL(bio_init); 1225EXPORT_SYMBOL(bio_init);
1216EXPORT_SYMBOL(__bio_clone); 1226EXPORT_SYMBOL(__bio_clone);