[PATCH v4 10/13] ext4: unify SYNC mode checks in fallocate paths

Zhang Yi posted 13 patches 6 days, 6 hours ago
[PATCH v4 10/13] ext4: unify SYNC mode checks in fallocate paths
Posted by Zhang Yi 6 days, 6 hours ago
From: Zhang Yi <yi.zhang@huawei.com>

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>
---
 fs/ext4/extents.c | 9 +++++----
 fs/ext4/inode.c   | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 16386f499138..f4009544f762 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4753,7 +4753,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:
@@ -4791,7 +4791,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);
 	}
@@ -5564,7 +5565,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:
@@ -5688,7 +5689,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 b934ad86a96d..3b150e643ef5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4501,7 +4501,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);
-- 
2.52.0
Re: [PATCH v4 10/13] ext4: unify SYNC mode checks in fallocate paths
Posted by Jan Kara 1 day ago
On Fri 27-03-26 18:29:36, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> 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>

Ah, OK, you unify it here :). Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/extents.c | 9 +++++----
>  fs/ext4/inode.c   | 2 +-
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 16386f499138..f4009544f762 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -4753,7 +4753,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:
> @@ -4791,7 +4791,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);
>  	}
> @@ -5564,7 +5565,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:
> @@ -5688,7 +5689,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 b934ad86a96d..3b150e643ef5 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4501,7 +4501,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);
> -- 
> 2.52.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR