Skip to content

Commit 74b0ebc

Browse files
Sunmin JeongJaegeuk Kim
authored andcommitted
f2fs: truncate page cache before clearing flags when aborting atomic write
In f2fs_do_write_data_page, FI_ATOMIC_FILE flag selects the target inode between the original inode and COW inode. When aborting atomic write and writeback occur simultaneously, invalid data can be written to original inode if the FI_ATOMIC_FILE flag is cleared meanwhile. To prevent the problem, let's truncate all pages before clearing the flag Atomic write thread Writeback thread f2fs_abort_atomic_write clear_inode_flag(inode, FI_ATOMIC_FILE) __writeback_single_inode do_writepages f2fs_do_write_data_page - use dn of original inode truncate_inode_pages_final Fixes: 3db1de0 ("f2fs: change the current atomic write way") Cc: [email protected] #v5.19+ Reviewed-by: Sungjong Seo <[email protected]> Reviewed-by: Yeongjin Gil <[email protected]> Signed-off-by: Sunmin Jeong <[email protected]> Reviewed-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 4bf7832 commit 74b0ebc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/f2fs/segment.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)
192192
if (!f2fs_is_atomic_file(inode))
193193
return;
194194

195+
if (clean)
196+
truncate_inode_pages_final(inode->i_mapping);
197+
195198
release_atomic_write_cnt(inode);
196199
clear_inode_flag(inode, FI_ATOMIC_COMMITTED);
197200
clear_inode_flag(inode, FI_ATOMIC_REPLACE);
@@ -201,7 +204,6 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)
201204
F2FS_I(inode)->atomic_write_task = NULL;
202205

203206
if (clean) {
204-
truncate_inode_pages_final(inode->i_mapping);
205207
f2fs_i_size_write(inode, fi->original_i_size);
206208
fi->original_i_size = 0;
207209
}

0 commit comments

Comments
 (0)