]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ext4: unify SYNC mode checks in fallocate paths
authorZhang Yi <yi.zhang@huawei.com>
Fri, 27 Mar 2026 10:29:36 +0000 (18:29 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 10 Apr 2026 01:57:52 +0000 (21:57 -0400)
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>
fs/ext4/extents.c
fs/ext4/inode.c

index 00b9860d387570fc8bc5118f3538f2bbf88707e4..053aeb9f0e74e77ef5636dddf4492065c8dfab44 100644 (file)
@@ -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:
index cb1365bbb84366f6e36730f9ce6534fa0558480b..9c1b95c439d51a17f632fd493f3868af7aacea17 100644 (file)
@@ -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);