[PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()

Zhang Yi posted 7 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()
Posted by Zhang Yi 1 month, 2 weeks ago
From: Zhang Yi <yi.zhang@huawei.com>

In the write path mapping check of ext4_iomap_begin(), the return value
'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
it can be returned directly without checking IOMAP_ATOMIC.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/inode.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index b84a2a10dfb8..67fe7d0f47e3 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3816,17 +3816,19 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 		if (offset + length <= i_size_read(inode)) {
 			ret = ext4_map_blocks(NULL, inode, &map, 0);
 			/*
-			 * For atomic writes the entire requested length should
-			 * be mapped. For DAX we convert extents to initialized
-			 * ones before copying the data, otherwise we do it
-			 * after I/O so there's no need to call into
-			 * ext4_iomap_alloc().
+			 * For DAX we convert extents to initialized ones before
+			 * copying the data, otherwise we do it after I/O so
+			 * there's no need to call into ext4_iomap_alloc().
 			 */
 			if ((map.m_flags & EXT4_MAP_MAPPED) ||
 			    (!(flags & IOMAP_DAX) &&
 			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
-				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
-				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
+				/*
+				 * For atomic writes the entire requested
+				 * length should be mapped.
+				 */
+				if (ret == orig_mlen ||
+				    (!(flags & IOMAP_ATOMIC) && ret > 0))
 					goto out;
 			}
 			map.m_len = orig_mlen;
-- 
2.52.0
Re: [PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()
Posted by Markus Elfring 1 month ago
> In the write path mapping check of ext4_iomap_begin(), the return value
> 'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
> it can be returned directly without checking IOMAP_ATOMIC.

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n94


How do you think about to use the word “simplify” in the summary phrase?

Regards,
Markus
Re: [PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()
Posted by Zhang Yi 1 month ago
On 1/4/2026 9:00 PM, Markus Elfring wrote:
>> In the write path mapping check of ext4_iomap_begin(), the return value
>> 'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
>> it can be returned directly without checking IOMAP_ATOMIC.
> 
> See also once more:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n94
> 
> 
> How do you think about to use the word “simplify” in the summary phrase?
> 
> Regards,
> Markus

Yeah, it makes sense to me, I will revise it in v3.

Thanks,
Yi.

Re: [PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()
Posted by Ojaswin Mujoo 1 month, 1 week ago
On Tue, Dec 23, 2025 at 09:18:01AM +0800, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> In the write path mapping check of ext4_iomap_begin(), the return value
> 'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
> it can be returned directly without checking IOMAP_ATOMIC.
> 
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> Reviewed-by: Jan Kara <jack@suse.cz>

Looks good, feel free to add:
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Regards,
ojaswin

> ---
>  fs/ext4/inode.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index b84a2a10dfb8..67fe7d0f47e3 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3816,17 +3816,19 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
>  		if (offset + length <= i_size_read(inode)) {
>  			ret = ext4_map_blocks(NULL, inode, &map, 0);
>  			/*
> -			 * For atomic writes the entire requested length should
> -			 * be mapped. For DAX we convert extents to initialized
> -			 * ones before copying the data, otherwise we do it
> -			 * after I/O so there's no need to call into
> -			 * ext4_iomap_alloc().
> +			 * For DAX we convert extents to initialized ones before
> +			 * copying the data, otherwise we do it after I/O so
> +			 * there's no need to call into ext4_iomap_alloc().
>  			 */
>  			if ((map.m_flags & EXT4_MAP_MAPPED) ||
>  			    (!(flags & IOMAP_DAX) &&
>  			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
> -				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
> -				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
> +				/*
> +				 * For atomic writes the entire requested
> +				 * length should be mapped.
> +				 */
> +				if (ret == orig_mlen ||
> +				    (!(flags & IOMAP_ATOMIC) && ret > 0))
>  					goto out;
>  			}
>  			map.m_len = orig_mlen;
> -- 
> 2.52.0
>
Re: [PATCH -next v2 6/7] ext4: simply the mapping query logic in ext4_iomap_begin()
Posted by Baokun Li 1 month, 1 week ago
On 2025-12-23 09:18, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> In the write path mapping check of ext4_iomap_begin(), the return value
> 'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
> it can be returned directly without checking IOMAP_ATOMIC.
>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> Reviewed-by: Jan Kara <jack@suse.cz>

Looks good. Feel free to add:

Reviewed-by: Baokun Li <libaokun1@huawei.com>

> ---
>  fs/ext4/inode.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index b84a2a10dfb8..67fe7d0f47e3 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3816,17 +3816,19 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
>  		if (offset + length <= i_size_read(inode)) {
>  			ret = ext4_map_blocks(NULL, inode, &map, 0);
>  			/*
> -			 * For atomic writes the entire requested length should
> -			 * be mapped. For DAX we convert extents to initialized
> -			 * ones before copying the data, otherwise we do it
> -			 * after I/O so there's no need to call into
> -			 * ext4_iomap_alloc().
> +			 * For DAX we convert extents to initialized ones before
> +			 * copying the data, otherwise we do it after I/O so
> +			 * there's no need to call into ext4_iomap_alloc().
>  			 */
>  			if ((map.m_flags & EXT4_MAP_MAPPED) ||
>  			    (!(flags & IOMAP_DAX) &&
>  			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
> -				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
> -				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
> +				/*
> +				 * For atomic writes the entire requested
> +				 * length should be mapped.
> +				 */
> +				if (ret == orig_mlen ||
> +				    (!(flags & IOMAP_ATOMIC) && ret > 0))
>  					goto out;
>  			}
>  			map.m_len = orig_mlen;