[PATCH 02/25] ext4: remove page offset calculation in ext4_block_truncate_page()

libaokun@huaweicloud.com posted 25 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH 02/25] ext4: remove page offset calculation in ext4_block_truncate_page()
Posted by libaokun@huaweicloud.com 3 months, 2 weeks ago
From: Baokun Li <libaokun1@huawei.com>

For bs <= ps scenarios, calculating the offset within the block is
sufficient. For bs > ps, an initial page offset calculation can lead to
incorrect behavior. Thus this redundant calculation has been removed.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/inode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0742039c53a7..4c04af7e51c9 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4183,7 +4183,6 @@ static int ext4_block_zero_page_range(handle_t *handle,
 static int ext4_block_truncate_page(handle_t *handle,
 		struct address_space *mapping, loff_t from)
 {
-	unsigned offset = from & (PAGE_SIZE-1);
 	unsigned length;
 	unsigned blocksize;
 	struct inode *inode = mapping->host;
@@ -4192,8 +4191,8 @@ static int ext4_block_truncate_page(handle_t *handle,
 	if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
 		return 0;
 
-	blocksize = inode->i_sb->s_blocksize;
-	length = blocksize - (offset & (blocksize - 1));
+	blocksize = i_blocksize(inode);
+	length = blocksize - (from & (blocksize - 1));
 
 	return ext4_block_zero_page_range(handle, mapping, from, length);
 }
-- 
2.46.1
Re: [PATCH 02/25] ext4: remove page offset calculation in ext4_block_truncate_page()
Posted by Jan Kara 3 months, 1 week ago
On Sat 25-10-25 11:21:58, libaokun@huaweicloud.com wrote:
> From: Baokun Li <libaokun1@huawei.com>
> 
> For bs <= ps scenarios, calculating the offset within the block is
> sufficient. For bs > ps, an initial page offset calculation can lead to
> incorrect behavior. Thus this redundant calculation has been removed.
> 
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Feel free to add:

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

								Honza

> ---
>  fs/ext4/inode.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 0742039c53a7..4c04af7e51c9 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4183,7 +4183,6 @@ static int ext4_block_zero_page_range(handle_t *handle,
>  static int ext4_block_truncate_page(handle_t *handle,
>  		struct address_space *mapping, loff_t from)
>  {
> -	unsigned offset = from & (PAGE_SIZE-1);
>  	unsigned length;
>  	unsigned blocksize;
>  	struct inode *inode = mapping->host;
> @@ -4192,8 +4191,8 @@ static int ext4_block_truncate_page(handle_t *handle,
>  	if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
>  		return 0;
>  
> -	blocksize = inode->i_sb->s_blocksize;
> -	length = blocksize - (offset & (blocksize - 1));
> +	blocksize = i_blocksize(inode);
> +	length = blocksize - (from & (blocksize - 1));
>  
>  	return ext4_block_zero_page_range(handle, mapping, from, length);
>  }
> -- 
> 2.46.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR