diff options
author | Christoph Hellwig <hch@lst.de> | 2015-10-05 09:31:11 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.com> | 2015-11-01 03:48:28 +0100 |
commit | b349feb36cc2b7ed41a5222a0b681153f3525369 (patch) | |
tree | 072a780447b514d522c9d1ded35a1fe0e05f1d0e /drivers/md | |
parent | raid5-cache: clean up r5l_get_meta (diff) | |
download | linux-b349feb36cc2b7ed41a5222a0b681153f3525369.tar.xz linux-b349feb36cc2b7ed41a5222a0b681153f3525369.zip |
raid5-cache: refactor bio allocation
Split out a helper to allocate a bio for log writes.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Shaohua Li <shli@fb.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/raid5-cache.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c index 29db786557d9..59a4640f09e5 100644 --- a/drivers/md/raid5-cache.c +++ b/drivers/md/raid5-cache.c @@ -276,11 +276,25 @@ static void r5l_submit_current_io(struct r5l_log *log) } } +static struct bio *r5l_bio_alloc(struct r5l_log *log, struct r5l_io_unit *io) +{ + struct bio *bio = bio_kmalloc(GFP_NOIO | __GFP_NOFAIL, BIO_MAX_PAGES); + + bio->bi_rw = WRITE; + bio->bi_bdev = log->rdev->bdev; + bio->bi_iter.bi_sector = log->log_start; + bio->bi_end_io = r5l_log_endio; + bio->bi_private = io; + + bio_list_add(&io->bios, bio); + atomic_inc(&io->pending_io); + return bio; +} + static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log) { struct r5l_io_unit *io; struct r5l_meta_block *block; - struct bio *bio; io = r5l_alloc_io_unit(log); @@ -294,17 +308,8 @@ static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log) io->meta_offset = sizeof(struct r5l_meta_block); io->seq = log->seq; - bio = bio_kmalloc(GFP_NOIO | __GFP_NOFAIL, BIO_MAX_PAGES); - io->current_bio = bio; - bio->bi_rw = WRITE; - bio->bi_bdev = log->rdev->bdev; - bio->bi_iter.bi_sector = log->log_start; - bio_add_page(bio, io->meta_page, PAGE_SIZE, 0); - bio->bi_end_io = r5l_log_endio; - bio->bi_private = io; - - bio_list_add(&io->bios, bio); - atomic_inc(&io->pending_io); + io->current_bio = r5l_bio_alloc(log, io); + bio_add_page(io->current_bio, io->meta_page, PAGE_SIZE, 0); log->seq++; log->log_start = r5l_ring_add(log, log->log_start, BLOCK_SECTORS); @@ -358,19 +363,9 @@ static void r5l_append_payload_page(struct r5l_log *log, struct page *page) struct r5l_io_unit *io = log->current_io; alloc_bio: - if (!io->current_bio) { - struct bio *bio; - - bio = bio_kmalloc(GFP_NOIO | __GFP_NOFAIL, BIO_MAX_PAGES); - bio->bi_rw = WRITE; - bio->bi_bdev = log->rdev->bdev; - bio->bi_iter.bi_sector = log->log_start; - bio->bi_end_io = r5l_log_endio; - bio->bi_private = io; - bio_list_add(&io->bios, bio); - atomic_inc(&io->pending_io); - io->current_bio = bio; - } + if (!io->current_bio) + io->current_bio = r5l_bio_alloc(log, io); + if (!bio_add_page(io->current_bio, page, PAGE_SIZE, 0)) { io->current_bio = NULL; goto alloc_bio; |