diff options
author | Ming Lei <ming.lei@redhat.com> | 2017-12-18 07:22:10 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-01-06 11:18:00 -0500 |
commit | 25d8be77e19224d8f21b363d77b5283c5dc21a57 (patch) | |
tree | 4a07629635d9e2109caca1c0418208fc167f8082 | |
parent | c2421edf5f9151d0eb28affbf76e9e4f8ddd03c6 (diff) |
block: move bio_alloc_pages() to bcache
bcache is the only user of bio_alloc_pages(), so move this function into
bcache, and avoid it being misused in the future.
Also rename it to bch_bio_allo_pages() since it is bcache only.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | block/bio.c | 28 | ||||
-rw-r--r-- | drivers/md/bcache/btree.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/debug.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/movinggc.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/request.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/util.c | 27 | ||||
-rw-r--r-- | drivers/md/bcache/util.h | 1 | ||||
-rw-r--r-- | drivers/md/bcache/writeback.c | 2 | ||||
-rw-r--r-- | include/linux/bio.h | 1 |
9 files changed, 33 insertions, 34 deletions
diff --git a/block/bio.c b/block/bio.c index 8bfdea58159b..fe1efbeaf4aa 100644 --- a/block/bio.c +++ b/block/bio.c | |||
@@ -969,34 +969,6 @@ void bio_advance(struct bio *bio, unsigned bytes) | |||
969 | EXPORT_SYMBOL(bio_advance); | 969 | EXPORT_SYMBOL(bio_advance); |
970 | 970 | ||
971 | /** | 971 | /** |
972 | * bio_alloc_pages - allocates a single page for each bvec in a bio | ||
973 | * @bio: bio to allocate pages for | ||
974 | * @gfp_mask: flags for allocation | ||
975 | * | ||
976 | * Allocates pages up to @bio->bi_vcnt. | ||
977 | * | ||
978 | * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are | ||
979 | * freed. | ||
980 | */ | ||
981 | int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask) | ||
982 | { | ||
983 | int i; | ||
984 | struct bio_vec *bv; | ||
985 | |||
986 | bio_for_each_segment_all(bv, bio, i) { | ||
987 | bv->bv_page = alloc_page(gfp_mask); | ||
988 | if (!bv->bv_page) { | ||
989 | while (--bv >= bio->bi_io_vec) | ||
990 | __free_page(bv->bv_page); | ||
991 | return -ENOMEM; | ||
992 | } | ||
993 | } | ||
994 | |||
995 | return 0; | ||
996 | } | ||
997 | EXPORT_SYMBOL(bio_alloc_pages); | ||
998 | |||
999 | /** | ||
1000 | * bio_copy_data - copy contents of data buffers from one chain of bios to | 972 | * bio_copy_data - copy contents of data buffers from one chain of bios to |
1001 | * another | 973 | * another |
1002 | * @src: source bio list | 974 | * @src: source bio list |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 02a4cf646fdc..ebb1874218e7 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -419,7 +419,7 @@ static void do_btree_node_write(struct btree *b) | |||
419 | SET_PTR_OFFSET(&k.key, 0, PTR_OFFSET(&k.key, 0) + | 419 | SET_PTR_OFFSET(&k.key, 0, PTR_OFFSET(&k.key, 0) + |
420 | bset_sector_offset(&b->keys, i)); | 420 | bset_sector_offset(&b->keys, i)); |
421 | 421 | ||
422 | if (!bio_alloc_pages(b->bio, __GFP_NOWARN|GFP_NOWAIT)) { | 422 | if (!bch_bio_alloc_pages(b->bio, __GFP_NOWARN|GFP_NOWAIT)) { |
423 | int j; | 423 | int j; |
424 | struct bio_vec *bv; | 424 | struct bio_vec *bv; |
425 | void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1)); | 425 | void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1)); |
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c index c7a02c4900da..879ab21074c6 100644 --- a/drivers/md/bcache/debug.c +++ b/drivers/md/bcache/debug.c | |||
@@ -116,7 +116,7 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio) | |||
116 | return; | 116 | return; |
117 | check->bi_opf = REQ_OP_READ; | 117 | check->bi_opf = REQ_OP_READ; |
118 | 118 | ||
119 | if (bio_alloc_pages(check, GFP_NOIO)) | 119 | if (bch_bio_alloc_pages(check, GFP_NOIO)) |
120 | goto out_put; | 120 | goto out_put; |
121 | 121 | ||
122 | submit_bio_wait(check); | 122 | submit_bio_wait(check); |
diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c index d50c1c97da68..a24c3a95b2c0 100644 --- a/drivers/md/bcache/movinggc.c +++ b/drivers/md/bcache/movinggc.c | |||
@@ -162,7 +162,7 @@ static void read_moving(struct cache_set *c) | |||
162 | bio_set_op_attrs(bio, REQ_OP_READ, 0); | 162 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
163 | bio->bi_end_io = read_moving_endio; | 163 | bio->bi_end_io = read_moving_endio; |
164 | 164 | ||
165 | if (bio_alloc_pages(bio, GFP_KERNEL)) | 165 | if (bch_bio_alloc_pages(bio, GFP_KERNEL)) |
166 | goto err; | 166 | goto err; |
167 | 167 | ||
168 | trace_bcache_gc_copy(&w->key); | 168 | trace_bcache_gc_copy(&w->key); |
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 643c3021624f..c493fb947dc9 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c | |||
@@ -841,7 +841,7 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s, | |||
841 | cache_bio->bi_private = &s->cl; | 841 | cache_bio->bi_private = &s->cl; |
842 | 842 | ||
843 | bch_bio_map(cache_bio, NULL); | 843 | bch_bio_map(cache_bio, NULL); |
844 | if (bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO)) | 844 | if (bch_bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO)) |
845 | goto out_put; | 845 | goto out_put; |
846 | 846 | ||
847 | if (reada) | 847 | if (reada) |
diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c index 61813d230015..a23cd6a14b74 100644 --- a/drivers/md/bcache/util.c +++ b/drivers/md/bcache/util.c | |||
@@ -283,6 +283,33 @@ start: bv->bv_len = min_t(size_t, PAGE_SIZE - bv->bv_offset, | |||
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | /** | ||
287 | * bch_bio_alloc_pages - allocates a single page for each bvec in a bio | ||
288 | * @bio: bio to allocate pages for | ||
289 | * @gfp_mask: flags for allocation | ||
290 | * | ||
291 | * Allocates pages up to @bio->bi_vcnt. | ||
292 | * | ||
293 | * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are | ||
294 | * freed. | ||
295 | */ | ||
296 | int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask) | ||
297 | { | ||
298 | int i; | ||
299 | struct bio_vec *bv; | ||
300 | |||
301 | bio_for_each_segment_all(bv, bio, i) { | ||
302 | bv->bv_page = alloc_page(gfp_mask); | ||
303 | if (!bv->bv_page) { | ||
304 | while (--bv >= bio->bi_io_vec) | ||
305 | __free_page(bv->bv_page); | ||
306 | return -ENOMEM; | ||
307 | } | ||
308 | } | ||
309 | |||
310 | return 0; | ||
311 | } | ||
312 | |||
286 | /* | 313 | /* |
287 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group (Any | 314 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group (Any |
288 | * use permitted, subject to terms of PostgreSQL license; see.) | 315 | * use permitted, subject to terms of PostgreSQL license; see.) |
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h index ed5e8a412eb8..4df4c5c1cab2 100644 --- a/drivers/md/bcache/util.h +++ b/drivers/md/bcache/util.h | |||
@@ -558,6 +558,7 @@ static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits) | |||
558 | } | 558 | } |
559 | 559 | ||
560 | void bch_bio_map(struct bio *bio, void *base); | 560 | void bch_bio_map(struct bio *bio, void *base); |
561 | int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask); | ||
561 | 562 | ||
562 | static inline sector_t bdev_sectors(struct block_device *bdev) | 563 | static inline sector_t bdev_sectors(struct block_device *bdev) |
563 | { | 564 | { |
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 56a37884ca8b..1ac2af6128b1 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c | |||
@@ -278,7 +278,7 @@ static void read_dirty(struct cached_dev *dc) | |||
278 | bio_set_dev(&io->bio, PTR_CACHE(dc->disk.c, &w->key, 0)->bdev); | 278 | bio_set_dev(&io->bio, PTR_CACHE(dc->disk.c, &w->key, 0)->bdev); |
279 | io->bio.bi_end_io = read_dirty_endio; | 279 | io->bio.bi_end_io = read_dirty_endio; |
280 | 280 | ||
281 | if (bio_alloc_pages(&io->bio, GFP_KERNEL)) | 281 | if (bch_bio_alloc_pages(&io->bio, GFP_KERNEL)) |
282 | goto err_free; | 282 | goto err_free; |
283 | 283 | ||
284 | trace_bcache_writeback(&w->key); | 284 | trace_bcache_writeback(&w->key); |
diff --git a/include/linux/bio.h b/include/linux/bio.h index 435ddf04e889..367a979fd4a6 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
@@ -500,7 +500,6 @@ static inline void bio_flush_dcache_pages(struct bio *bi) | |||
500 | #endif | 500 | #endif |
501 | 501 | ||
502 | extern void bio_copy_data(struct bio *dst, struct bio *src); | 502 | extern void bio_copy_data(struct bio *dst, struct bio *src); |
503 | extern int bio_alloc_pages(struct bio *bio, gfp_t gfp); | ||
504 | extern void bio_free_pages(struct bio *bio); | 503 | extern void bio_free_pages(struct bio *bio); |
505 | 504 | ||
506 | extern struct bio *bio_copy_user_iov(struct request_queue *, | 505 | extern struct bio *bio_copy_user_iov(struct request_queue *, |