diff mbox series

[f2fs-dev,1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks

Message ID 20240305084023.3686070-1-xiuhong.wang@unisoc.com (mailing list archive)
State Superseded
Headers show
Series [f2fs-dev,1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks | expand

Commit Message

Xiuhong Wang March 5, 2024, 8:40 a.m. UTC
The following f2fs_io test will get a "0" result instead of -EINVAL,
unisoc # ./f2fs_io compress file
unisoc # ./f2fs_io reserve_cblocks file
 0
it's not reasonable, so the judgement of
atomic_read(&F2FS_I(inode)->i_compr_blocks) should be placed after
the judgement of is_inode_flag_set(inode, FI_COMPRESS_RELEASED).

Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com>
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
 fs/f2fs/file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Chao Yu March 6, 2024, 1:51 a.m. UTC | #1
On 2024/3/5 16:40, Xiuhong Wang wrote:
> The following f2fs_io test will get a "0" result instead of -EINVAL,
> unisoc # ./f2fs_io compress file
> unisoc # ./f2fs_io reserve_cblocks file
>   0
> it's not reasonable, so the judgement of
> atomic_read(&F2FS_I(inode)->i_compr_blocks) should be placed after
> the judgement of is_inode_flag_set(inode, FI_COMPRESS_RELEASED).
> 
> Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
> Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com>
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
>   fs/f2fs/file.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 4ca6c693b33a..572d7bd4d161 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3720,18 +3720,18 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
>   	if (ret)
>   		return ret;
>   
> -	if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
> -		goto out;
> -
>   	f2fs_balance_fs(sbi, true);
>   
>   	inode_lock(inode);
>   
>   	if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
>   		ret = -EINVAL;
> -		goto unlock_inode;

Nitpick, maybe keep unlock_inode label is better.

> +		goto out;
>   	}
>   
> +	if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
> +		goto out;

goto unlock_inode

Thanks,

> +
>   	f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
>   	filemap_invalidate_lock(inode->i_mapping);
>   
> @@ -3776,9 +3776,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
>   		inode_set_ctime_current(inode);
>   		f2fs_mark_inode_dirty_sync(inode, true);
>   	}
> -unlock_inode:
> -	inode_unlock(inode);
>   out:
> +	inode_unlock(inode);
>   	mnt_drop_write_file(filp);
>   
>   	if (ret >= 0) {
diff mbox series

Patch

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4ca6c693b33a..572d7bd4d161 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3720,18 +3720,18 @@  static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 	if (ret)
 		return ret;
 
-	if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
-		goto out;
-
 	f2fs_balance_fs(sbi, true);
 
 	inode_lock(inode);
 
 	if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
 		ret = -EINVAL;
-		goto unlock_inode;
+		goto out;
 	}
 
+	if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
+		goto out;
+
 	f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 	filemap_invalidate_lock(inode->i_mapping);
 
@@ -3776,9 +3776,8 @@  static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 		inode_set_ctime_current(inode);
 		f2fs_mark_inode_dirty_sync(inode, true);
 	}
-unlock_inode:
-	inode_unlock(inode);
 out:
+	inode_unlock(inode);
 	mnt_drop_write_file(filp);
 
 	if (ret >= 0) {