Commit 6415fedc authored by Yunlong Song's avatar Yunlong Song Committed by Jaegeuk Kim

f2fs: update cur_valid_map_mir together with cur_valid_map

When cur_valid_map passes the f2fs_test_and_set(,clear)_bit test,
cur_valid_map_mir update is skipped unlikely, so fix it. The fix
now changes the mirror check together with cur_valid_map all the
time.
Signed-off-by: default avatarYunlong Song <yunlong.song@huawei.com>
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: Fix unused variable and add unlikely for corner condition.]
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent a36c106d
...@@ -1503,6 +1503,10 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) ...@@ -1503,6 +1503,10 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
struct seg_entry *se; struct seg_entry *se;
unsigned int segno, offset; unsigned int segno, offset;
long int new_vblocks; long int new_vblocks;
bool exist;
#ifdef CONFIG_F2FS_CHECK_FS
bool mir_exist;
#endif
segno = GET_SEGNO(sbi, blkaddr); segno = GET_SEGNO(sbi, blkaddr);
...@@ -1519,17 +1523,23 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) ...@@ -1519,17 +1523,23 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
/* Update valid block bitmap */ /* Update valid block bitmap */
if (del > 0) { if (del > 0) {
if (f2fs_test_and_set_bit(offset, se->cur_valid_map)) { exist = f2fs_test_and_set_bit(offset, se->cur_valid_map);
#ifdef CONFIG_F2FS_CHECK_FS #ifdef CONFIG_F2FS_CHECK_FS
if (f2fs_test_and_set_bit(offset, mir_exist = f2fs_test_and_set_bit(offset,
se->cur_valid_map_mir)) se->cur_valid_map_mir);
f2fs_bug_on(sbi, 1); if (unlikely(exist != mir_exist)) {
else f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
WARN_ON(1); "when setting bitmap, blk:%u, old bit:%d",
#else blkaddr, exist);
f2fs_bug_on(sbi, 1); f2fs_bug_on(sbi, 1);
}
#endif #endif
if (unlikely(exist)) {
f2fs_msg(sbi->sb, KERN_ERR,
"Bitmap was wrongly set, blk:%u", blkaddr);
f2fs_bug_on(sbi, 1);
} }
if (f2fs_discard_en(sbi) && if (f2fs_discard_en(sbi) &&
!f2fs_test_and_set_bit(offset, se->discard_map)) !f2fs_test_and_set_bit(offset, se->discard_map))
sbi->discard_blks--; sbi->discard_blks--;
...@@ -1540,17 +1550,23 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) ...@@ -1540,17 +1550,23 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
se->ckpt_valid_blocks++; se->ckpt_valid_blocks++;
} }
} else { } else {
if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) { exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
#ifdef CONFIG_F2FS_CHECK_FS #ifdef CONFIG_F2FS_CHECK_FS
if (!f2fs_test_and_clear_bit(offset, mir_exist = f2fs_test_and_clear_bit(offset,
se->cur_valid_map_mir)) se->cur_valid_map_mir);
f2fs_bug_on(sbi, 1); if (unlikely(exist != mir_exist)) {
else f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
WARN_ON(1); "when clearing bitmap, blk:%u, old bit:%d",
#else blkaddr, exist);
f2fs_bug_on(sbi, 1); f2fs_bug_on(sbi, 1);
}
#endif #endif
if (unlikely(!exist)) {
f2fs_msg(sbi->sb, KERN_ERR,
"Bitmap was wrongly cleared, blk:%u", blkaddr);
f2fs_bug_on(sbi, 1);
} }
if (f2fs_discard_en(sbi) && if (f2fs_discard_en(sbi) &&
f2fs_test_and_clear_bit(offset, se->discard_map)) f2fs_test_and_clear_bit(offset, se->discard_map))
sbi->discard_blks++; sbi->discard_blks++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment