Commit bc29835a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jaegeuk Kim

f2fs: split __submit_bio

Split __submit_bio into one function each for reads and writes, and a
helper for aligning writes.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent da8c7fec
...@@ -1070,7 +1070,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ...@@ -1070,7 +1070,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
if (ret) if (ret)
goto out; goto out;
if (bio) if (bio)
f2fs_submit_bio(sbi, bio, DATA); f2fs_submit_read_bio(sbi, bio, DATA);
ret = f2fs_init_compress_ctx(cc); ret = f2fs_init_compress_ctx(cc);
if (ret) if (ret)
......
...@@ -507,65 +507,66 @@ static bool f2fs_crypt_mergeable_bio(struct bio *bio, const struct inode *inode, ...@@ -507,65 +507,66 @@ static bool f2fs_crypt_mergeable_bio(struct bio *bio, const struct inode *inode,
return fscrypt_mergeable_bio(bio, inode, next_idx); return fscrypt_mergeable_bio(bio, inode, next_idx);
} }
static inline void __submit_bio(struct f2fs_sb_info *sbi, void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,
struct bio *bio, enum page_type type) enum page_type type)
{ {
if (!is_read_io(bio_op(bio))) { WARN_ON_ONCE(!is_read_io(bio_op(bio)));
unsigned int start; trace_f2fs_submit_read_bio(sbi->sb, type, bio);
if (type != DATA && type != NODE) iostat_update_submit_ctx(bio, type);
goto submit_io; submit_bio(bio);
}
if (f2fs_lfs_mode(sbi) && current->plug) static void f2fs_align_write_bio(struct f2fs_sb_info *sbi, struct bio *bio)
blk_finish_plug(current->plug); {
unsigned int start =
(bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS) % F2FS_IO_SIZE(sbi);
if (!F2FS_IO_ALIGNED(sbi)) if (start == 0)
goto submit_io; return;
start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; /* fill dummy pages */
start %= F2FS_IO_SIZE(sbi); for (; start < F2FS_IO_SIZE(sbi); start++) {
struct page *page =
mempool_alloc(sbi->write_io_dummy,
GFP_NOIO | __GFP_NOFAIL);
f2fs_bug_on(sbi, !page);
if (start == 0) lock_page(page);
goto submit_io;
/* fill dummy pages */ zero_user_segment(page, 0, PAGE_SIZE);
for (; start < F2FS_IO_SIZE(sbi); start++) { set_page_private_dummy(page);
struct page *page =
mempool_alloc(sbi->write_io_dummy,
GFP_NOIO | __GFP_NOFAIL);
f2fs_bug_on(sbi, !page);
lock_page(page); if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE)
f2fs_bug_on(sbi, 1);
}
}
zero_user_segment(page, 0, PAGE_SIZE); static void f2fs_submit_write_bio(struct f2fs_sb_info *sbi, struct bio *bio,
set_page_private_dummy(page); enum page_type type)
{
WARN_ON_ONCE(is_read_io(bio_op(bio)));
if (type == DATA || type == NODE) {
if (f2fs_lfs_mode(sbi) && current->plug)
blk_finish_plug(current->plug);
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) if (F2FS_IO_ALIGNED(sbi)) {
f2fs_bug_on(sbi, 1); f2fs_align_write_bio(sbi, bio);
/*
* In the NODE case, we lose next block address chain.
* So, we need to do checkpoint in f2fs_sync_file.
*/
if (type == NODE)
set_sbi_flag(sbi, SBI_NEED_CP);
} }
/*
* In the NODE case, we lose next block address chain. So, we
* need to do checkpoint in f2fs_sync_file.
*/
if (type == NODE)
set_sbi_flag(sbi, SBI_NEED_CP);
} }
submit_io:
if (is_read_io(bio_op(bio)))
trace_f2fs_submit_read_bio(sbi->sb, type, bio);
else
trace_f2fs_submit_write_bio(sbi->sb, type, bio);
trace_f2fs_submit_write_bio(sbi->sb, type, bio);
iostat_update_submit_ctx(bio, type); iostat_update_submit_ctx(bio, type);
submit_bio(bio); submit_bio(bio);
} }
void f2fs_submit_bio(struct f2fs_sb_info *sbi,
struct bio *bio, enum page_type type)
{
__submit_bio(sbi, bio, type);
}
static void __submit_merged_bio(struct f2fs_bio_info *io) static void __submit_merged_bio(struct f2fs_bio_info *io)
{ {
struct f2fs_io_info *fio = &io->fio; struct f2fs_io_info *fio = &io->fio;
...@@ -573,12 +574,13 @@ static void __submit_merged_bio(struct f2fs_bio_info *io) ...@@ -573,12 +574,13 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
if (!io->bio) if (!io->bio)
return; return;
if (is_read_io(fio->op)) if (is_read_io(fio->op)) {
trace_f2fs_prepare_read_bio(io->sbi->sb, fio->type, io->bio); trace_f2fs_prepare_read_bio(io->sbi->sb, fio->type, io->bio);
else f2fs_submit_read_bio(io->sbi, io->bio, fio->type);
} else {
trace_f2fs_prepare_write_bio(io->sbi->sb, fio->type, io->bio); trace_f2fs_prepare_write_bio(io->sbi->sb, fio->type, io->bio);
f2fs_submit_write_bio(io->sbi, io->bio, fio->type);
__submit_bio(io->sbi, io->bio, fio->type); }
io->bio = NULL; io->bio = NULL;
} }
...@@ -746,7 +748,10 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) ...@@ -746,7 +748,10 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
inc_page_count(fio->sbi, is_read_io(fio->op) ? inc_page_count(fio->sbi, is_read_io(fio->op) ?
__read_io_type(page) : WB_DATA_TYPE(fio->page)); __read_io_type(page) : WB_DATA_TYPE(fio->page));
__submit_bio(fio->sbi, bio, fio->type); if (is_read_io(bio_op(bio)))
f2fs_submit_read_bio(fio->sbi, bio, fio->type);
else
f2fs_submit_write_bio(fio->sbi, bio, fio->type);
return 0; return 0;
} }
...@@ -848,7 +853,7 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio, ...@@ -848,7 +853,7 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
/* page can't be merged into bio; submit the bio */ /* page can't be merged into bio; submit the bio */
del_bio_entry(be); del_bio_entry(be);
__submit_bio(sbi, *bio, DATA); f2fs_submit_write_bio(sbi, *bio, DATA);
break; break;
} }
f2fs_up_write(&io->bio_list_lock); f2fs_up_write(&io->bio_list_lock);
...@@ -911,7 +916,7 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, ...@@ -911,7 +916,7 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
} }
if (found) if (found)
__submit_bio(sbi, target, DATA); f2fs_submit_write_bio(sbi, target, DATA);
if (bio && *bio) { if (bio && *bio) {
bio_put(*bio); bio_put(*bio);
*bio = NULL; *bio = NULL;
...@@ -1107,7 +1112,7 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page, ...@@ -1107,7 +1112,7 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page,
} }
inc_page_count(sbi, F2FS_RD_DATA); inc_page_count(sbi, F2FS_RD_DATA);
f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE); f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE);
__submit_bio(sbi, bio, DATA); f2fs_submit_read_bio(sbi, bio, DATA);
return 0; return 0;
} }
...@@ -2137,7 +2142,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, ...@@ -2137,7 +2142,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
*last_block_in_bio, block_nr) || *last_block_in_bio, block_nr) ||
!f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) { !f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) {
submit_and_realloc: submit_and_realloc:
__submit_bio(F2FS_I_SB(inode), bio, DATA); f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
bio = NULL; bio = NULL;
} }
if (bio == NULL) { if (bio == NULL) {
...@@ -2284,7 +2289,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, ...@@ -2284,7 +2289,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
*last_block_in_bio, blkaddr) || *last_block_in_bio, blkaddr) ||
!f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) { !f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) {
submit_and_realloc: submit_and_realloc:
__submit_bio(sbi, bio, DATA); f2fs_submit_read_bio(sbi, bio, DATA);
bio = NULL; bio = NULL;
} }
...@@ -2445,7 +2450,7 @@ static int f2fs_mpage_readpages(struct inode *inode, ...@@ -2445,7 +2450,7 @@ static int f2fs_mpage_readpages(struct inode *inode,
#endif #endif
} }
if (bio) if (bio)
__submit_bio(F2FS_I_SB(inode), bio, DATA); f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA);
return ret; return ret;
} }
......
...@@ -3780,8 +3780,8 @@ int __init f2fs_init_bioset(void); ...@@ -3780,8 +3780,8 @@ int __init f2fs_init_bioset(void);
void f2fs_destroy_bioset(void); void f2fs_destroy_bioset(void);
int f2fs_init_bio_entry_cache(void); int f2fs_init_bio_entry_cache(void);
void f2fs_destroy_bio_entry_cache(void); void f2fs_destroy_bio_entry_cache(void);
void f2fs_submit_bio(struct f2fs_sb_info *sbi, void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,
struct bio *bio, enum page_type type); enum page_type type);
int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi); int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi);
void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
......
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