diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-09-10 17:03:28 -0400 |
---|---|---|
committer | Kent Overstreet <koverstreet@google.com> | 2013-03-23 17:26:31 -0400 |
commit | a07876064a0b73ab5ef1ebcf14b1cf0231c07858 (patch) | |
tree | 74a0567401bcdb60f5a8e65c76d5a3a21aeb548f /fs | |
parent | cb34e057ad22a1c2c6f2cb6cd1cbd05cc2f28f28 (diff) |
block: Add bio_alloc_pages()
More utility code to replace stuff that's getting open coded.
Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
CC: NeilBrown <neilb@suse.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bio.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -830,6 +830,34 @@ void bio_advance(struct bio *bio, unsigned bytes) | |||
830 | EXPORT_SYMBOL(bio_advance); | 830 | EXPORT_SYMBOL(bio_advance); |
831 | 831 | ||
832 | /** | 832 | /** |
833 | * bio_alloc_pages - allocates a single page for each bvec in a bio | ||
834 | * @bio: bio to allocate pages for | ||
835 | * @gfp_mask: flags for allocation | ||
836 | * | ||
837 | * Allocates pages up to @bio->bi_vcnt. | ||
838 | * | ||
839 | * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are | ||
840 | * freed. | ||
841 | */ | ||
842 | int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask) | ||
843 | { | ||
844 | int i; | ||
845 | struct bio_vec *bv; | ||
846 | |||
847 | bio_for_each_segment_all(bv, bio, i) { | ||
848 | bv->bv_page = alloc_page(gfp_mask); | ||
849 | if (!bv->bv_page) { | ||
850 | while (--bv >= bio->bi_io_vec) | ||
851 | __free_page(bv->bv_page); | ||
852 | return -ENOMEM; | ||
853 | } | ||
854 | } | ||
855 | |||
856 | return 0; | ||
857 | } | ||
858 | EXPORT_SYMBOL(bio_alloc_pages); | ||
859 | |||
860 | /** | ||
833 | * bio_copy_data - copy contents of data buffers from one chain of bios to | 861 | * bio_copy_data - copy contents of data buffers from one chain of bios to |
834 | * another | 862 | * another |
835 | * @src: source bio list | 863 | * @src: source bio list |