f2fs: add f2fs_init_write_merge_io function
authorYufen Yu <yuyufen@huawei.com>
Wed, 25 May 2022 09:43:36 +0000 (17:43 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 25 May 2022 17:48:56 +0000 (10:48 -0700)
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 <yuyufen@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
[Jaegeuk Kim: clean up]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 54a7a8ad994d114e784a4b4903f408f0761779ef..f5f2b7233982cdd96809463a26727c58c46c319c 100644 (file)
@@ -584,6 +584,34 @@ static bool __has_merged_page(struct bio *bio, struct inode *inode,
        return false;
 }
 
+int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi)
+{
+       int i;
+
+       for (i = 0; i < NR_PAGE_TYPE; i++) {
+               int n = (i == META) ? 1 : NR_TEMP_TYPE;
+               int j;
+
+               sbi->write_io[i] = f2fs_kmalloc(sbi,
+                               array_size(n, sizeof(struct f2fs_bio_info)),
+                               GFP_KERNEL);
+               if (!sbi->write_io[i])
+                       return -ENOMEM;
+
+               for (j = HOT; j < n; j++) {
+                       init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem);
+                       sbi->write_io[i][j].sbi = sbi;
+                       sbi->write_io[i][j].bio = NULL;
+                       spin_lock_init(&sbi->write_io[i][j].io_lock);
+                       INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
+                       INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
+                       init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock);
+               }
+       }
+
+       return 0;
+}
+
 static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
                                enum page_type type, enum temp_type temp)
 {
index f4d03a81ef3f8600225411d04f735686dff1e368..c73014901006c16d82de3d5d62af8f6bccf5a90f 100644 (file)
@@ -3713,6 +3713,7 @@ int f2fs_init_bio_entry_cache(void);
 void f2fs_destroy_bio_entry_cache(void);
 void f2fs_submit_bio(struct f2fs_sb_info *sbi,
                                struct bio *bio, enum page_type type);
+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_cond(struct f2fs_sb_info *sbi,
                                struct inode *inode, struct page *page,
index 63daae67a9d93f2db999899661866f847125cdf1..5b558f69c46189bcf55dcdf9dd6fcac725df8b81 100644 (file)
@@ -4091,30 +4091,9 @@ try_onemore:
        set_sbi_flag(sbi, SBI_POR_DOING);
        spin_lock_init(&sbi->stat_lock);
 
-       for (i = 0; i < NR_PAGE_TYPE; i++) {
-               int n = (i == META) ? 1 : NR_TEMP_TYPE;
-               int j;
-
-               sbi->write_io[i] =
-                       f2fs_kmalloc(sbi,
-                                    array_size(n,
-                                               sizeof(struct f2fs_bio_info)),
-                                    GFP_KERNEL);
-               if (!sbi->write_io[i]) {
-                       err = -ENOMEM;
-                       goto free_bio_info;
-               }
-
-               for (j = HOT; j < n; j++) {
-                       init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem);
-                       sbi->write_io[i][j].sbi = sbi;
-                       sbi->write_io[i][j].bio = NULL;
-                       spin_lock_init(&sbi->write_io[i][j].io_lock);
-                       INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
-                       INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
-                       init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock);
-               }
-       }
+       err = f2fs_init_write_merge_io(sbi);
+       if (err)
+               goto free_bio_info;
 
        init_f2fs_rwsem(&sbi->cp_rwsem);
        init_f2fs_rwsem(&sbi->quota_sem);