Skip to content

Commit 908ea65

Browse files
Yufen YuJaegeuk Kim
authored andcommitted
f2fs: add f2fs_init_write_merge_io function
Almost all other initialization of variables in f2fs_fill_super are extraced to a single function. Also do it for write_io[], which can make code more clean. This patch just refactors the code, theres no functional change. Signed-off-by: Yufen Yu <[email protected]> Reviewed-by: Chao Yu <[email protected]> [Jaegeuk Kim: clean up] Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 78901cf commit 908ea65

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

fs/f2fs/data.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,34 @@ static bool __has_merged_page(struct bio *bio, struct inode *inode,
584584
return false;
585585
}
586586

587+
int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi)
588+
{
589+
int i;
590+
591+
for (i = 0; i < NR_PAGE_TYPE; i++) {
592+
int n = (i == META) ? 1 : NR_TEMP_TYPE;
593+
int j;
594+
595+
sbi->write_io[i] = f2fs_kmalloc(sbi,
596+
array_size(n, sizeof(struct f2fs_bio_info)),
597+
GFP_KERNEL);
598+
if (!sbi->write_io[i])
599+
return -ENOMEM;
600+
601+
for (j = HOT; j < n; j++) {
602+
init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem);
603+
sbi->write_io[i][j].sbi = sbi;
604+
sbi->write_io[i][j].bio = NULL;
605+
spin_lock_init(&sbi->write_io[i][j].io_lock);
606+
INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
607+
INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
608+
init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock);
609+
}
610+
}
611+
612+
return 0;
613+
}
614+
587615
static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
588616
enum page_type type, enum temp_type temp)
589617
{

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,6 +3713,7 @@ int f2fs_init_bio_entry_cache(void);
37133713
void f2fs_destroy_bio_entry_cache(void);
37143714
void f2fs_submit_bio(struct f2fs_sb_info *sbi,
37153715
struct bio *bio, enum page_type type);
3716+
int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi);
37163717
void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
37173718
void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
37183719
struct inode *inode, struct page *page,

fs/f2fs/super.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,30 +4091,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
40914091
set_sbi_flag(sbi, SBI_POR_DOING);
40924092
spin_lock_init(&sbi->stat_lock);
40934093

4094-
for (i = 0; i < NR_PAGE_TYPE; i++) {
4095-
int n = (i == META) ? 1 : NR_TEMP_TYPE;
4096-
int j;
4097-
4098-
sbi->write_io[i] =
4099-
f2fs_kmalloc(sbi,
4100-
array_size(n,
4101-
sizeof(struct f2fs_bio_info)),
4102-
GFP_KERNEL);
4103-
if (!sbi->write_io[i]) {
4104-
err = -ENOMEM;
4105-
goto free_bio_info;
4106-
}
4107-
4108-
for (j = HOT; j < n; j++) {
4109-
init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem);
4110-
sbi->write_io[i][j].sbi = sbi;
4111-
sbi->write_io[i][j].bio = NULL;
4112-
spin_lock_init(&sbi->write_io[i][j].io_lock);
4113-
INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
4114-
INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
4115-
init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock);
4116-
}
4117-
}
4094+
err = f2fs_init_write_merge_io(sbi);
4095+
if (err)
4096+
goto free_bio_info;
41184097

41194098
init_f2fs_rwsem(&sbi->cp_rwsem);
41204099
init_f2fs_rwsem(&sbi->quota_sem);

0 commit comments

Comments
 (0)