Commit f0d6ca46 authored by Pankaj Raghav's avatar Pankaj Raghav Committed by Andrew Morton

mpage: split submit_bio and bio end_io handler for reads and writes

Split the submit_bio() and bio end_io handler for reads and writes similar
to other aops.

This is a prep patch before we convert end_io handlers to use folios.

Link: https://lkml.kernel.org/r/20230411122920.30134-3-p.raghav@samsung.comSigned-off-by: default avatarPankaj Raghav <p.raghav@samsung.com>
Suggested-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Martin Brandenburg <martin@omnibond.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Marshall <hubcap@omnibond.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent cd01049d
...@@ -43,23 +43,41 @@ ...@@ -43,23 +43,41 @@
* status of that page is hard. See end_buffer_async_read() for the details. * status of that page is hard. See end_buffer_async_read() for the details.
* There is no point in duplicating all that complexity. * There is no point in duplicating all that complexity.
*/ */
static void mpage_end_io(struct bio *bio) static void mpage_read_end_io(struct bio *bio)
{ {
struct bio_vec *bv; struct bio_vec *bv;
struct bvec_iter_all iter_all; struct bvec_iter_all iter_all;
bio_for_each_segment_all(bv, bio, iter_all) { bio_for_each_segment_all(bv, bio, iter_all)
struct page *page = bv->bv_page; page_endio(bv->bv_page, REQ_OP_READ,
page_endio(page, bio_op(bio),
blk_status_to_errno(bio->bi_status)); blk_status_to_errno(bio->bi_status));
}
bio_put(bio); bio_put(bio);
} }
static struct bio *mpage_bio_submit(struct bio *bio) static void mpage_write_end_io(struct bio *bio)
{
struct bio_vec *bv;
struct bvec_iter_all iter_all;
bio_for_each_segment_all(bv, bio, iter_all)
page_endio(bv->bv_page, REQ_OP_WRITE,
blk_status_to_errno(bio->bi_status));
bio_put(bio);
}
static struct bio *mpage_bio_submit_read(struct bio *bio)
{
bio->bi_end_io = mpage_read_end_io;
guard_bio_eod(bio);
submit_bio(bio);
return NULL;
}
static struct bio *mpage_bio_submit_write(struct bio *bio)
{ {
bio->bi_end_io = mpage_end_io; bio->bi_end_io = mpage_write_end_io;
guard_bio_eod(bio); guard_bio_eod(bio);
submit_bio(bio); submit_bio(bio);
return NULL; return NULL;
...@@ -265,7 +283,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) ...@@ -265,7 +283,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
* This folio will go to BIO. Do we need to send this BIO off first? * This folio will go to BIO. Do we need to send this BIO off first?
*/ */
if (args->bio && (args->last_block_in_bio != blocks[0] - 1)) if (args->bio && (args->last_block_in_bio != blocks[0] - 1))
args->bio = mpage_bio_submit(args->bio); args->bio = mpage_bio_submit_read(args->bio);
alloc_new: alloc_new:
if (args->bio == NULL) { if (args->bio == NULL) {
...@@ -278,7 +296,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) ...@@ -278,7 +296,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
length = first_hole << blkbits; length = first_hole << blkbits;
if (!bio_add_folio(args->bio, folio, length, 0)) { if (!bio_add_folio(args->bio, folio, length, 0)) {
args->bio = mpage_bio_submit(args->bio); args->bio = mpage_bio_submit_read(args->bio);
goto alloc_new; goto alloc_new;
} }
...@@ -286,7 +304,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) ...@@ -286,7 +304,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
nblocks = map_bh->b_size >> blkbits; nblocks = map_bh->b_size >> blkbits;
if ((buffer_boundary(map_bh) && relative_block == nblocks) || if ((buffer_boundary(map_bh) && relative_block == nblocks) ||
(first_hole != blocks_per_page)) (first_hole != blocks_per_page))
args->bio = mpage_bio_submit(args->bio); args->bio = mpage_bio_submit_read(args->bio);
else else
args->last_block_in_bio = blocks[blocks_per_page - 1]; args->last_block_in_bio = blocks[blocks_per_page - 1];
out: out:
...@@ -294,7 +312,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) ...@@ -294,7 +312,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
confused: confused:
if (args->bio) if (args->bio)
args->bio = mpage_bio_submit(args->bio); args->bio = mpage_bio_submit_read(args->bio);
if (!folio_test_uptodate(folio)) if (!folio_test_uptodate(folio))
block_read_full_folio(folio, args->get_block); block_read_full_folio(folio, args->get_block);
else else
...@@ -356,7 +374,7 @@ void mpage_readahead(struct readahead_control *rac, get_block_t get_block) ...@@ -356,7 +374,7 @@ void mpage_readahead(struct readahead_control *rac, get_block_t get_block)
args.bio = do_mpage_readpage(&args); args.bio = do_mpage_readpage(&args);
} }
if (args.bio) if (args.bio)
mpage_bio_submit(args.bio); mpage_bio_submit_read(args.bio);
} }
EXPORT_SYMBOL(mpage_readahead); EXPORT_SYMBOL(mpage_readahead);
...@@ -373,7 +391,7 @@ int mpage_read_folio(struct folio *folio, get_block_t get_block) ...@@ -373,7 +391,7 @@ int mpage_read_folio(struct folio *folio, get_block_t get_block)
args.bio = do_mpage_readpage(&args); args.bio = do_mpage_readpage(&args);
if (args.bio) if (args.bio)
mpage_bio_submit(args.bio); mpage_bio_submit_read(args.bio);
return 0; return 0;
} }
EXPORT_SYMBOL(mpage_read_folio); EXPORT_SYMBOL(mpage_read_folio);
...@@ -577,7 +595,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, ...@@ -577,7 +595,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
* This page will go to BIO. Do we need to send this BIO off first? * This page will go to BIO. Do we need to send this BIO off first?
*/ */
if (bio && mpd->last_block_in_bio != blocks[0] - 1) if (bio && mpd->last_block_in_bio != blocks[0] - 1)
bio = mpage_bio_submit(bio); bio = mpage_bio_submit_write(bio);
alloc_new: alloc_new:
if (bio == NULL) { if (bio == NULL) {
...@@ -596,7 +614,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, ...@@ -596,7 +614,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
wbc_account_cgroup_owner(wbc, &folio->page, folio_size(folio)); wbc_account_cgroup_owner(wbc, &folio->page, folio_size(folio));
length = first_unmapped << blkbits; length = first_unmapped << blkbits;
if (!bio_add_folio(bio, folio, length, 0)) { if (!bio_add_folio(bio, folio, length, 0)) {
bio = mpage_bio_submit(bio); bio = mpage_bio_submit_write(bio);
goto alloc_new; goto alloc_new;
} }
...@@ -606,7 +624,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, ...@@ -606,7 +624,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
folio_start_writeback(folio); folio_start_writeback(folio);
folio_unlock(folio); folio_unlock(folio);
if (boundary || (first_unmapped != blocks_per_page)) { if (boundary || (first_unmapped != blocks_per_page)) {
bio = mpage_bio_submit(bio); bio = mpage_bio_submit_write(bio);
if (boundary_block) { if (boundary_block) {
write_boundary_block(boundary_bdev, write_boundary_block(boundary_bdev,
boundary_block, 1 << blkbits); boundary_block, 1 << blkbits);
...@@ -618,7 +636,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, ...@@ -618,7 +636,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
confused: confused:
if (bio) if (bio)
bio = mpage_bio_submit(bio); bio = mpage_bio_submit_write(bio);
/* /*
* The caller has a ref on the inode, so *mapping is stable * The caller has a ref on the inode, so *mapping is stable
...@@ -652,7 +670,7 @@ mpage_writepages(struct address_space *mapping, ...@@ -652,7 +670,7 @@ mpage_writepages(struct address_space *mapping,
blk_start_plug(&plug); blk_start_plug(&plug);
ret = write_cache_pages(mapping, wbc, __mpage_writepage, &mpd); ret = write_cache_pages(mapping, wbc, __mpage_writepage, &mpd);
if (mpd.bio) if (mpd.bio)
mpage_bio_submit(mpd.bio); mpage_bio_submit_write(mpd.bio);
blk_finish_plug(&plug); blk_finish_plug(&plug);
return ret; return ret;
} }
......
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