f2fs: split f2fs_allocate_new_segments()
authorChao Yu <yuchao0@huawei.com>
Mon, 22 Jun 2020 09:38:48 +0000 (17:38 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 8 Jul 2020 04:51:48 +0000 (21:51 -0700)
to two independent functions:
- f2fs_allocate_new_segment() for specified type segment allocation
- f2fs_allocate_new_segments() for all data type segments allocation

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/recovery.c
fs/f2fs/segment.c

index 874b793ab00e0a420450da5f4982952ccfe34502..4f1f1a3e33347ebefc164bdd6e901087162c8461 100644 (file)
@@ -3335,7 +3335,8 @@ void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
 int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
 void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
                                        unsigned int start, unsigned int end);
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type);
+void f2fs_allocate_new_segment(struct f2fs_sb_info *sbi, int type);
+void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
 bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
                                        struct cp_control *cpc);
index 6ef2656c617134ac28572a114c8754937c89c736..1af37f3b3309f8d81836a97297ec17a67a0fb47d 100644 (file)
@@ -1658,7 +1658,7 @@ next_alloc:
                map.m_seg_type = CURSEG_COLD_DATA_PINNED;
 
                f2fs_lock_op(sbi);
-               f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
+               f2fs_allocate_new_segment(sbi, CURSEG_COLD_DATA);
                f2fs_unlock_op(sbi);
 
                err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
index ae5310f02e7ff1b7fa20e8b1819449aff560e870..af974ba273b323de3588780172286682195ff915 100644 (file)
@@ -742,7 +742,7 @@ next:
                f2fs_put_page(page, 1);
        }
        if (!err)
-               f2fs_allocate_new_segments(sbi, NO_CHECK_TYPE);
+               f2fs_allocate_new_segments(sbi);
        return err;
 }
 
index 5aa4158a1440cc8f5d0b529f8b0a6a5b7845097f..c35614d255e143c73720998c6e359ed7e991a31a 100644 (file)
@@ -2733,28 +2733,35 @@ unlock:
        up_read(&SM_I(sbi)->curseg_lock);
 }
 
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type)
+static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type)
 {
-       struct curseg_info *curseg;
+       struct curseg_info *curseg = CURSEG_I(sbi, type);
        unsigned int old_segno;
-       int i;
 
-       down_write(&SIT_I(sbi)->sentry_lock);
+       if (!curseg->next_blkoff &&
+               !get_valid_blocks(sbi, curseg->segno, false) &&
+               !get_ckpt_valid_blocks(sbi, curseg->segno))
+               return;
 
-       for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
-               if (type != NO_CHECK_TYPE && i != type)
-                       continue;
+       old_segno = curseg->segno;
+       SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+       locate_dirty_segment(sbi, old_segno);
+}
 
-               curseg = CURSEG_I(sbi, i);
-               if (type == NO_CHECK_TYPE || curseg->next_blkoff ||
-                               get_valid_blocks(sbi, curseg->segno, false) ||
-                               get_ckpt_valid_blocks(sbi, curseg->segno)) {
-                       old_segno = curseg->segno;
-                       SIT_I(sbi)->s_ops->allocate_segment(sbi, i, true);
-                       locate_dirty_segment(sbi, old_segno);
-               }
-       }
+void f2fs_allocate_new_segment(struct f2fs_sb_info *sbi, int type)
+{
+       down_write(&SIT_I(sbi)->sentry_lock);
+       __allocate_new_segment(sbi, type);
+       up_write(&SIT_I(sbi)->sentry_lock);
+}
 
+void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
+{
+       int i;
+
+       down_write(&SIT_I(sbi)->sentry_lock);
+       for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
+               __allocate_new_segment(sbi, i);
        up_write(&SIT_I(sbi)->sentry_lock);
 }