Skip to content

Commit f098aeb

Browse files
YeongjinGilJaegeuk Kim
authored andcommitted
f2fs: fix to avoid atomicity corruption of atomic file
In the case of the following call stack for an atomic file, FI_DIRTY_INODE is set, but FI_ATOMIC_DIRTIED is not subsequently set. f2fs_file_write_iter f2fs_map_blocks f2fs_reserve_new_blocks inc_valid_block_count __mark_inode_dirty(dquot) f2fs_dirty_inode If FI_ATOMIC_DIRTIED is not set, atomic file can encounter corruption due to a mismatch between old file size and new data. To resolve this issue, I changed to set FI_ATOMIC_DIRTIED when FI_DIRTY_INODE is set. This ensures that FI_DIRTY_INODE, which was previously cleared by the Writeback thread during the commit atomic, is set and i_size is updated. Cc: <[email protected]> Fixes: fccaa81 ("f2fs: prevent atomic file from being dirtied before commit") Reviewed-by: Sungjong Seo <[email protected]> Reviewed-by: Sunmin Jeong <[email protected]> Signed-off-by: Yeongjin Gil <[email protected]> Reviewed-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 71e9bd3 commit f098aeb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/f2fs/inode.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
3434
if (f2fs_inode_dirtied(inode, sync))
3535
return;
3636

37-
if (f2fs_is_atomic_file(inode)) {
38-
set_inode_flag(inode, FI_ATOMIC_DIRTIED);
37+
if (f2fs_is_atomic_file(inode))
3938
return;
40-
}
4139

4240
mark_inode_dirty_sync(inode);
4341
}

fs/f2fs/super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,10 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync)
15301530
inc_page_count(sbi, F2FS_DIRTY_IMETA);
15311531
}
15321532
spin_unlock(&sbi->inode_lock[DIRTY_META]);
1533+
1534+
if (!ret && f2fs_is_atomic_file(inode))
1535+
set_inode_flag(inode, FI_ATOMIC_DIRTIED);
1536+
15331537
return ret;
15341538
}
15351539

0 commit comments

Comments
 (0)