aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2019-05-16 20:40:42 +0800
committerJaegeuk Kim <jaegeuk@kernel.org>2019-05-20 17:42:42 -0700
commit9e0a58749de8b62932388cfb645ee6248cd1b413 (patch)
tree9e6b895659ce3a6ea1c21e4eafda45c9bfd1be96
parenta423b5f91e3c9de1c0f176fbd00fb058a4651bc2 (diff)
downloadf2fs-tools-9e0a58749de8b62932388cfb645ee6248cd1b413.tar.gz
fsck.f2fs: introduce check_curseg_offsets()
Let check_curseg_offset() just check one curseg, and introduce check_curseg_offsets() to check all cursegs, no logic changes. In addition, update message printed a bit. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fsck/fsck.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/fsck/fsck.c b/fsck/fsck.c
index fe48071..247b75e 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -2121,33 +2121,45 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
write_nat_bits(sbi, sb, cp, sbi->cur_cp);
}
-int check_curseg_offset(struct f2fs_sb_info *sbi)
+int check_curseg_offset(struct f2fs_sb_info *sbi, int type)
{
- int i;
+ struct curseg_info *curseg = CURSEG_I(sbi, type);
+ struct seg_entry *se;
+ int j, nblocks;
- for (i = 0; i < NO_CHECK_TYPE; i++) {
- struct curseg_info *curseg = CURSEG_I(sbi, i);
- struct seg_entry *se;
- int j, nblocks;
+ if ((curseg->next_blkoff >> 3) >= SIT_VBLOCK_MAP_SIZE) {
+ ASSERT_MSG("Next block offset:%u is invalid, type:%d",
+ curseg->next_blkoff, type);
+ return -EINVAL;
+ }
+ se = get_seg_entry(sbi, curseg->segno);
+ if (f2fs_test_bit(curseg->next_blkoff,
+ (const char *)se->cur_valid_map)) {
+ ASSERT_MSG("Next block offset is not free, type:%d", type);
+ return -EINVAL;
+ }
+ if (curseg->alloc_type == SSR)
+ return 0;
- if ((curseg->next_blkoff >> 3) >= SIT_VBLOCK_MAP_SIZE)
- return -EINVAL;
- se = get_seg_entry(sbi, curseg->segno);
- if (f2fs_test_bit(curseg->next_blkoff,
- (const char *)se->cur_valid_map)) {
- ASSERT_MSG("Next block offset is not free, type:%d", i);
+ nblocks = sbi->blocks_per_seg;
+ for (j = curseg->next_blkoff + 1; j < nblocks; j++) {
+ if (f2fs_test_bit(j, (const char *)se->cur_valid_map)) {
+ ASSERT_MSG("For LFS curseg, space after .next_blkoff "
+ "should be unused, type:%d", type);
return -EINVAL;
}
- if (curseg->alloc_type == SSR)
- continue;
+ }
+ return 0;
+}
- nblocks = sbi->blocks_per_seg;
- for (j = curseg->next_blkoff + 1; j < nblocks; j++) {
- if (f2fs_test_bit(j, (const char *)se->cur_valid_map)) {
- ASSERT_MSG("LFS must have free section:%d", i);
- return -EINVAL;
- }
- }
+int check_curseg_offsets(struct f2fs_sb_info *sbi)
+{
+ int i, ret;
+
+ for (i = 0; i < NO_CHECK_TYPE; i++) {
+ ret = check_curseg_offset(sbi, i);
+ if (ret)
+ return ret;
}
return 0;
}
@@ -2695,7 +2707,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
}
printf("[FSCK] next block offset is free ");
- if (check_curseg_offset(sbi) == 0) {
+ if (check_curseg_offsets(sbi) == 0) {
printf(" [Ok..]\n");
} else {
printf(" [Fail]\n");
@@ -2740,7 +2752,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
fix_hard_links(sbi);
fix_nat_entries(sbi);
rewrite_sit_area_bitmap(sbi);
- if (check_curseg_offset(sbi)) {
+ if (check_curseg_offsets(sbi)) {
move_curseg_info(sbi, SM_I(sbi)->main_blkaddr, 0);
write_curseg_info(sbi);
flush_curseg_sit_entries(sbi);