diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-09-06 18:35:00 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-09-09 04:35:39 -0400 |
commit | 4254bba17d92d53822a56ebc2a0c1eb7e2a71155 (patch) | |
tree | 77668d39949a0751c5e9ef8d0fb47b96392e84e5 /fs | |
parent | ccc5c9ca6aac08218b1ba52afd07a1a9864c8c5d (diff) |
block: Kill bi_destructor
Now that we've got generic code for freeing bios allocated from bio
pools, this isn't needed anymore.
This patch also makes bio_free() static, since without bi_destructor
there should be no need for it to be called anywhere else.
bio_free() is now only called from bio_put, so we can refactor those a
bit - move some code from bio_put() to bio_free() and kill the redundant
bio->bi_next = NULL.
v5: Switch to BIO_KMALLOC_POOL ((void *)~0), per Boaz
v6: BIO_KMALLOC_POOL now NULL, drop bio_free's EXPORT_SYMBOL
v7: No #define BIO_KMALLOC_POOL anymore
Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bio.c | 64 |
1 files changed, 26 insertions, 38 deletions
@@ -233,26 +233,37 @@ fallback: | |||
233 | return bvl; | 233 | return bvl; |
234 | } | 234 | } |
235 | 235 | ||
236 | void bio_free(struct bio *bio, struct bio_set *bs) | 236 | static void __bio_free(struct bio *bio) |
237 | { | 237 | { |
238 | void *p; | 238 | bio_disassociate_task(bio); |
239 | |||
240 | if (bio_has_allocated_vec(bio)) | ||
241 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
242 | 239 | ||
243 | if (bio_integrity(bio)) | 240 | if (bio_integrity(bio)) |
244 | bio_integrity_free(bio); | 241 | bio_integrity_free(bio); |
242 | } | ||
245 | 243 | ||
246 | /* | 244 | static void bio_free(struct bio *bio) |
247 | * If we have front padding, adjust the bio pointer before freeing | 245 | { |
248 | */ | 246 | struct bio_set *bs = bio->bi_pool; |
249 | p = bio; | 247 | void *p; |
250 | if (bs->front_pad) | 248 | |
249 | __bio_free(bio); | ||
250 | |||
251 | if (bs) { | ||
252 | if (bio_has_allocated_vec(bio)) | ||
253 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
254 | |||
255 | /* | ||
256 | * If we have front padding, adjust the bio pointer before freeing | ||
257 | */ | ||
258 | p = bio; | ||
251 | p -= bs->front_pad; | 259 | p -= bs->front_pad; |
252 | 260 | ||
253 | mempool_free(p, bs->bio_pool); | 261 | mempool_free(p, bs->bio_pool); |
262 | } else { | ||
263 | /* Bio was allocated by bio_kmalloc() */ | ||
264 | kfree(bio); | ||
265 | } | ||
254 | } | 266 | } |
255 | EXPORT_SYMBOL(bio_free); | ||
256 | 267 | ||
257 | void bio_init(struct bio *bio) | 268 | void bio_init(struct bio *bio) |
258 | { | 269 | { |
@@ -276,10 +287,7 @@ void bio_reset(struct bio *bio) | |||
276 | { | 287 | { |
277 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); | 288 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); |
278 | 289 | ||
279 | if (bio_integrity(bio)) | 290 | __bio_free(bio); |
280 | bio_integrity_free(bio); | ||
281 | |||
282 | bio_disassociate_task(bio); | ||
283 | 291 | ||
284 | memset(bio, 0, BIO_RESET_BYTES); | 292 | memset(bio, 0, BIO_RESET_BYTES); |
285 | bio->bi_flags = flags|(1 << BIO_UPTODATE); | 293 | bio->bi_flags = flags|(1 << BIO_UPTODATE); |
@@ -362,13 +370,6 @@ struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) | |||
362 | } | 370 | } |
363 | EXPORT_SYMBOL(bio_alloc); | 371 | EXPORT_SYMBOL(bio_alloc); |
364 | 372 | ||
365 | static void bio_kmalloc_destructor(struct bio *bio) | ||
366 | { | ||
367 | if (bio_integrity(bio)) | ||
368 | bio_integrity_free(bio); | ||
369 | kfree(bio); | ||
370 | } | ||
371 | |||
372 | /** | 373 | /** |
373 | * bio_kmalloc - allocate a bio for I/O using kmalloc() | 374 | * bio_kmalloc - allocate a bio for I/O using kmalloc() |
374 | * @gfp_mask: the GFP_ mask given to the slab allocator | 375 | * @gfp_mask: the GFP_ mask given to the slab allocator |
@@ -395,7 +396,6 @@ struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs) | |||
395 | bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET; | 396 | bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET; |
396 | bio->bi_max_vecs = nr_iovecs; | 397 | bio->bi_max_vecs = nr_iovecs; |
397 | bio->bi_io_vec = bio->bi_inline_vecs; | 398 | bio->bi_io_vec = bio->bi_inline_vecs; |
398 | bio->bi_destructor = bio_kmalloc_destructor; | ||
399 | 399 | ||
400 | return bio; | 400 | return bio; |
401 | } | 401 | } |
@@ -431,20 +431,8 @@ void bio_put(struct bio *bio) | |||
431 | /* | 431 | /* |
432 | * last put frees it | 432 | * last put frees it |
433 | */ | 433 | */ |
434 | if (atomic_dec_and_test(&bio->bi_cnt)) { | 434 | if (atomic_dec_and_test(&bio->bi_cnt)) |
435 | bio_disassociate_task(bio); | 435 | bio_free(bio); |
436 | bio->bi_next = NULL; | ||
437 | |||
438 | /* | ||
439 | * This if statement is temporary - bi_pool is replacing | ||
440 | * bi_destructor, but bi_destructor will be taken out in another | ||
441 | * patch. | ||
442 | */ | ||
443 | if (bio->bi_pool) | ||
444 | bio_free(bio, bio->bi_pool); | ||
445 | else | ||
446 | bio->bi_destructor(bio); | ||
447 | } | ||
448 | } | 436 | } |
449 | EXPORT_SYMBOL(bio_put); | 437 | EXPORT_SYMBOL(bio_put); |
450 | 438 | ||