summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhang Yi <yi.zhang@huawei.com>2026-03-27 13:29:36 +0300
committerTheodore Ts'o <tytso@mit.edu>2026-04-10 04:57:52 +0300
commitc3688d212fc6306bbb7136fbc1d0be0f175a5270 (patch)
tree5d2867bf7cc05aa2b617297fb32829a93a8e6c72
parent7d81ec0246ff74b10d92a4617fea84eaf06162c0 (diff)
downloadlinux-c3688d212fc6306bbb7136fbc1d0be0f175a5270.tar.xz
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>
-rw-r--r--fs/ext4/extents.c9
-rw-r--r--fs/ext4/inode.c2
2 files changed, 6 insertions, 5 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 00b9860d3875..053aeb9f0e74 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4782,7 +4782,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
goto out_handle;
ext4_update_inode_fsync_trans(handle, inode, 1);
- if (file->f_flags & O_SYNC)
+ if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
ext4_handle_sync(handle);
out_handle:
@@ -4820,7 +4820,8 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,
if (ret)
goto out;
- if (file->f_flags & O_SYNC && EXT4_SB(inode->i_sb)->s_journal) {
+ if (((file->f_flags & O_SYNC) || IS_SYNC(inode)) &&
+ EXT4_SB(inode->i_sb)->s_journal) {
ret = ext4_fc_commit(EXT4_SB(inode->i_sb)->s_journal,
EXT4_I(inode)->i_sync_tid);
}
@@ -5593,7 +5594,7 @@ static int ext4_collapse_range(struct file *file, loff_t offset, loff_t len)
goto out_handle;
ext4_update_inode_fsync_trans(handle, inode, 1);
- if (IS_SYNC(inode))
+ if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
ext4_handle_sync(handle);
out_handle:
@@ -5717,7 +5718,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
goto out_handle;
ext4_update_inode_fsync_trans(handle, inode, 1);
- if (IS_SYNC(inode))
+ if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
ext4_handle_sync(handle);
out_handle:
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cb1365bbb843..9c1b95c439d5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4531,7 +4531,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
goto out_handle;
ext4_update_inode_fsync_trans(handle, inode, 1);
- if (IS_SYNC(inode))
+ if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
ext4_handle_sync(handle);
out_handle:
ext4_journal_stop(handle);