[v4,4/5] ocfs2: convert to use i_blockmask()

Message ID 20230310054829.4241-4-frank.li@vivo.com
State New
Headers
Series [v4,1/5] fs: add i_blockmask() |

Commit Message

李扬韬 March 10, 2023, 5:48 a.m. UTC
  Use i_blockmask() to simplify code. BTW convert ocfs2_is_io_unaligned
to return bool type and the fact that the value will be the same
(i.e. that ->i_blkbits is never changed by ocfs2).

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/ocfs2/file.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
  

Comments

Joseph Qi March 10, 2023, 11:13 a.m. UTC | #1
On 3/10/23 1:48 PM, Yangtao Li wrote:
> Use i_blockmask() to simplify code. BTW convert ocfs2_is_io_unaligned
> to return bool type and the fact that the value will be the same
> (i.e. that ->i_blkbits is never changed by ocfs2).
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  fs/ocfs2/file.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index efb09de4343d..7fd06a4d27d4 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -2159,14 +2159,9 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
>  	return ret;
>  }
>  
> -static int ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
> +static bool ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
>  {
> -	int blockmask = inode->i_sb->s_blocksize - 1;
> -	loff_t final_size = pos + count;
> -
> -	if ((pos & blockmask) || (final_size & blockmask))
> -		return 1;
> -	return 0;
> +	return ((pos | count) & i_blockmask(inode)) != 0;

Or !!((pos | count) & i_blockmask(inode))?

My concern is just like erofs, we'd better get vfs helper into mainline
first. Or can we fold the whole series into one patch? Since it's simple
enough I think.

Thanks,
Joseph

>  }
>  
>  static int ocfs2_inode_lock_for_extent_tree(struct inode *inode,
  

Patch

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index efb09de4343d..7fd06a4d27d4 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2159,14 +2159,9 @@  int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
 	return ret;
 }
 
-static int ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
+static bool ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
 {
-	int blockmask = inode->i_sb->s_blocksize - 1;
-	loff_t final_size = pos + count;
-
-	if ((pos & blockmask) || (final_size & blockmask))
-		return 1;
-	return 0;
+	return ((pos | count) & i_blockmask(inode)) != 0;
 }
 
 static int ocfs2_inode_lock_for_extent_tree(struct inode *inode,