Commit b349feb3 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by NeilBrown

raid5-cache: refactor bio allocation

Split out a helper to allocate a bio for log writes.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarShaohua Li <shli@fb.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
parent 22581f58
...@@ -276,11 +276,25 @@ static void r5l_submit_current_io(struct r5l_log *log) ...@@ -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) static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log)
{ {
struct r5l_io_unit *io; struct r5l_io_unit *io;
struct r5l_meta_block *block; struct r5l_meta_block *block;
struct bio *bio;
io = r5l_alloc_io_unit(log); io = r5l_alloc_io_unit(log);
...@@ -294,17 +308,8 @@ static struct r5l_io_unit *r5l_new_meta(struct r5l_log *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->meta_offset = sizeof(struct r5l_meta_block);
io->seq = log->seq; io->seq = log->seq;
bio = bio_kmalloc(GFP_NOIO | __GFP_NOFAIL, BIO_MAX_PAGES); io->current_bio = r5l_bio_alloc(log, io);
io->current_bio = bio; bio_add_page(io->current_bio, io->meta_page, PAGE_SIZE, 0);
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);
log->seq++; log->seq++;
log->log_start = r5l_ring_add(log, log->log_start, BLOCK_SECTORS); 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) ...@@ -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; struct r5l_io_unit *io = log->current_io;
alloc_bio: alloc_bio:
if (!io->current_bio) { if (!io->current_bio)
struct bio *bio; io->current_bio = r5l_bio_alloc(log, io);
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 (!bio_add_page(io->current_bio, page, PAGE_SIZE, 0)) { if (!bio_add_page(io->current_bio, page, PAGE_SIZE, 0)) {
io->current_bio = NULL; io->current_bio = NULL;
goto alloc_bio; goto alloc_bio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment