Skip to content

Commit c3688d2

Browse files
zhangyi089tytso
authored andcommitted
ext4: unify SYNC mode checks in fallocate paths
In the ext4 fallocate call chain, SYNC mode handling is inconsistent: some places check the inode state, while others check the open file descriptor state. Unify these checks by evaluating both conditions to ensure consistent behavior across all fallocate operations. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20260327102939.1095257-11-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 7d81ec0 commit c3688d2

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

fs/ext4/extents.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,7 +4782,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
47824782
goto out_handle;
47834783

47844784
ext4_update_inode_fsync_trans(handle, inode, 1);
4785-
if (file->f_flags & O_SYNC)
4785+
if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
47864786
ext4_handle_sync(handle);
47874787

47884788
out_handle:
@@ -4820,7 +4820,8 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,
48204820
if (ret)
48214821
goto out;
48224822

4823-
if (file->f_flags & O_SYNC && EXT4_SB(inode->i_sb)->s_journal) {
4823+
if (((file->f_flags & O_SYNC) || IS_SYNC(inode)) &&
4824+
EXT4_SB(inode->i_sb)->s_journal) {
48244825
ret = ext4_fc_commit(EXT4_SB(inode->i_sb)->s_journal,
48254826
EXT4_I(inode)->i_sync_tid);
48264827
}
@@ -5593,7 +5594,7 @@ static int ext4_collapse_range(struct file *file, loff_t offset, loff_t len)
55935594
goto out_handle;
55945595

55955596
ext4_update_inode_fsync_trans(handle, inode, 1);
5596-
if (IS_SYNC(inode))
5597+
if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
55975598
ext4_handle_sync(handle);
55985599

55995600
out_handle:
@@ -5717,7 +5718,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
57175718
goto out_handle;
57185719

57195720
ext4_update_inode_fsync_trans(handle, inode, 1);
5720-
if (IS_SYNC(inode))
5721+
if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
57215722
ext4_handle_sync(handle);
57225723

57235724
out_handle:

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4531,7 +4531,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
45314531
goto out_handle;
45324532

45334533
ext4_update_inode_fsync_trans(handle, inode, 1);
4534-
if (IS_SYNC(inode))
4534+
if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
45354535
ext4_handle_sync(handle);
45364536
out_handle:
45374537
ext4_journal_stop(handle);

0 commit comments

Comments
 (0)