Skip to content

Commit c3e238b

Browse files
Yongpeng YangJaegeuk Kim
authored andcommitted
f2fs: fix fsck inconsistency caused by FGGC of node block
During FGGC node block migration, fsck may incorrectly treat the migrated node block as fsync-written data. The reproduction scenario: root@vm:/mnt/f2fs# seq 1 2048 | xargs -n 1 ./test_sync // write inline inode and sync root@vm:/mnt/f2fs# rm -f 1 root@vm:/mnt/f2fs# sync root@vm:/mnt/f2fs# f2fs_io gc_range // move data block in sync mode and not write CP SPO, "fsck --dry-run" find inode has already checkpointed but still with DENT_BIT_SHIFT set The root cause is that GC does not clear the dentry mark and fsync mark during node block migration, leading fsck to misinterpret them as user-issued fsync writes. In BGGC mode, node block migration is handled by f2fs_sync_node_pages(), which guarantees the dentry and fsync marks are cleared before writing. This patch move the set/clear of the fsync|dentry marks into __write_node_folio to make the logic clearer, and ensures the fsync|dentry mark is cleared in FGGC. Cc: stable@kernel.org Fixes: da011cc ("f2fs: move node pages only in victim section during GC") Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 019f9dd commit c3e238b

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

fs/f2fs/node.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,10 @@ static struct folio *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)
17271727
return last_folio;
17281728
}
17291729

1730-
static bool __write_node_folio(struct folio *folio, bool atomic, bool *submitted,
1731-
struct writeback_control *wbc, bool do_balance,
1732-
enum iostat_type io_type, unsigned int *seq_id)
1730+
static bool __write_node_folio(struct folio *folio, bool atomic, bool do_fsync,
1731+
bool *submitted, struct writeback_control *wbc,
1732+
bool do_balance, enum iostat_type io_type,
1733+
unsigned int *seq_id)
17331734
{
17341735
struct f2fs_sb_info *sbi = F2FS_F_SB(folio);
17351736
nid_t nid;
@@ -1802,6 +1803,8 @@ static bool __write_node_folio(struct folio *folio, bool atomic, bool *submitted
18021803
if (atomic && !test_opt(sbi, NOBARRIER))
18031804
fio.op_flags |= REQ_PREFLUSH | REQ_FUA;
18041805

1806+
set_dentry_mark(folio, false);
1807+
set_fsync_mark(folio, do_fsync);
18051808
if (IS_INODE(folio) && (atomic || is_fsync_dnode(folio)))
18061809
set_dentry_mark(folio,
18071810
f2fs_need_dentry_mark(sbi, ino_of_node(folio)));
@@ -1868,7 +1871,7 @@ static int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
18681871
goto out_folio;
18691872
}
18701873

1871-
if (!__write_node_folio(node_folio, false, NULL,
1874+
if (!__write_node_folio(node_folio, false, false, NULL,
18721875
&wbc, false, FS_GC_NODE_IO, NULL))
18731876
err = -EAGAIN;
18741877
goto release_folio;
@@ -1915,6 +1918,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
19151918
for (i = 0; i < nr_folios; i++) {
19161919
struct folio *folio = fbatch.folios[i];
19171920
bool submitted = false;
1921+
bool do_fsync = false;
19181922

19191923
if (unlikely(f2fs_cp_error(sbi))) {
19201924
f2fs_folio_put(last_folio, false);
@@ -1945,11 +1949,8 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
19451949

19461950
f2fs_folio_wait_writeback(folio, NODE, true, true);
19471951

1948-
set_fsync_mark(folio, 0);
1949-
set_dentry_mark(folio, 0);
1950-
19511952
if (!atomic || folio == last_folio) {
1952-
set_fsync_mark(folio, 1);
1953+
do_fsync = true;
19531954
percpu_counter_inc(&sbi->rf_node_block_count);
19541955
if (IS_INODE(folio)) {
19551956
if (is_inode_flag_set(inode,
@@ -1966,8 +1967,9 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
19661967

19671968
if (!__write_node_folio(folio, atomic &&
19681969
folio == last_folio,
1969-
&submitted, wbc, true,
1970-
FS_NODE_IO, seq_id)) {
1970+
do_fsync, &submitted,
1971+
wbc, true, FS_NODE_IO,
1972+
seq_id)) {
19711973
f2fs_folio_put(last_folio, false);
19721974
folio_batch_release(&fbatch);
19731975
ret = -EIO;
@@ -2167,10 +2169,7 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
21672169
if (!folio_clear_dirty_for_io(folio))
21682170
goto continue_unlock;
21692171

2170-
set_fsync_mark(folio, 0);
2171-
set_dentry_mark(folio, 0);
2172-
2173-
if (!__write_node_folio(folio, false, &submitted,
2172+
if (!__write_node_folio(folio, false, false, &submitted,
21742173
wbc, do_balance, io_type, NULL)) {
21752174
folio_batch_release(&fbatch);
21762175
ret = -EIO;

0 commit comments

Comments
 (0)