resize.f2fs: skip cursegs when finding next free block
authorSheng Yong <shengyong1@huawei.com>
Mon, 4 Jun 2018 08:14:36 +0000 (16:14 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 28 Aug 2018 06:49:26 +0000 (23:49 -0700)
resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
However, if a curseg is selected, and f2fs_defragment is broken by any
error, curseg->next_blkoff is left not updated.

To avoid this, we skip cursegs when finding next free block.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/f2fs.h
fsck/fsck.c
fsck/mount.c

index d0e08aa..d216444 100644 (file)
@@ -380,16 +380,13 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
        return 1;
 }
 
-static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno, int type)
+static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno)
 {
        int i;
 
        for (i = 0; i < NO_CHECK_TYPE; i++) {
                struct curseg_info *curseg = CURSEG_I(sbi, i);
 
-               if (type == i)
-                       continue;
-
                if (segno == curseg->segno)
                        return 1;
        }
index 05a6301..b1741d9 100644 (file)
@@ -1741,7 +1741,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
                se = get_seg_entry(sbi, i);
                if (se->valid_blocks != 0)
                        sit_valid_segs++;
-               else if (IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE)) {
+               else if (IS_CUR_SEGNO(sbi, i)) {
                        /* curseg has not been written back to device */
                        MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
                        sit_valid_segs++;
index 0e67a6b..301ff90 100644 (file)
@@ -35,8 +35,7 @@ u32 get_free_segments(struct f2fs_sb_info *sbi)
        for (i = 0; i < TOTAL_SEGS(sbi); i++) {
                struct seg_entry *se = get_seg_entry(sbi, i);
 
-               if (se->valid_blocks == 0x0 &&
-                               !IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
+               if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i))
                        free_segs++;
        }
        return free_segs;
@@ -1970,8 +1969,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
                                                        se->valid_blocks);
                rewrite_current_sit_page(sbi, segno, sit_blk);
 
-               if (se->valid_blocks == 0x0 &&
-                               !IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
+               if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, segno))
                        free_segs++;
        }
 
@@ -1999,7 +1997,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
                se = get_seg_entry(sbi, segno);
 
                if (se->valid_blocks == sbi->blocks_per_seg ||
-                               IS_CUR_SEGNO(sbi, segno, type)) {
+                               IS_CUR_SEGNO(sbi, segno)) {
                        *to = left ? START_BLOCK(sbi, segno) - 1:
                                                START_BLOCK(sbi, segno + 1);
                        continue;