[PATCH v2 4/8] ext4: propagate flags to convert_initialized_extent()

Ojaswin Mujoo posted 8 patches 3 weeks, 3 days ago
There is a newer version of this series
[PATCH v2 4/8] ext4: propagate flags to convert_initialized_extent()
Posted by Ojaswin Mujoo 3 weeks, 3 days ago
Currently, ext4_zero_range passes EXT4_EX_NOCACHE flag to avoid caching
extents however this is not respected by convert_initialized_extent().
Hence, modify it to accept flags from the caller and to pass the flags
on to other extent manipulation functions it calls. This makes
sure the NOCACHE flag is respected throughout the code path.

Also, we no longer explicitly pass CONVERT_UNWRITTEN as the caller takes
care of this. Account this behavior in Kunit tests as well.

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 fs/ext4/extents.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index a581e9278d48..3d45abfb13cd 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3844,6 +3844,7 @@ static struct ext4_ext_path *
 convert_initialized_extent(handle_t *handle, struct inode *inode,
 			   struct ext4_map_blocks *map,
 			   struct ext4_ext_path *path,
+			   int flags,
 			   unsigned int *allocated)
 {
 	struct ext4_extent *ex;
@@ -3869,11 +3870,11 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
 
 	if (ee_block != map->m_lblk || ee_len > map->m_len) {
 		path = ext4_split_convert_extents(handle, inode, map, path,
-				EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, NULL);
+						  flags, NULL);
 		if (IS_ERR(path))
 			return path;
 
-		path = ext4_find_extent(inode, map->m_lblk, path, 0);
+		path = ext4_find_extent(inode, map->m_lblk, path, flags);
 		if (IS_ERR(path))
 			return path;
 		depth = ext_depth(inode);
@@ -4263,7 +4264,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
 			if ((!ext4_ext_is_unwritten(ex)) &&
 			    (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) {
 				path = convert_initialized_extent(handle,
-					inode, map, path, &allocated);
+					inode, map, path, flags, &allocated);
 				if (IS_ERR(path))
 					err = PTR_ERR(path);
 				goto out;
-- 
2.52.0
Re: [PATCH v2 4/8] ext4: propagate flags to convert_initialized_extent()
Posted by Zhang Yi 3 weeks ago
On 1/14/2026 10:57 PM, Ojaswin Mujoo wrote:
> Currently, ext4_zero_range passes EXT4_EX_NOCACHE flag to avoid caching
> extents however this is not respected by convert_initialized_extent().
> Hence, modify it to accept flags from the caller and to pass the flags
> on to other extent manipulation functions it calls. This makes
> sure the NOCACHE flag is respected throughout the code path.
> 
> Also, we no longer explicitly pass CONVERT_UNWRITTEN as the caller takes
> care of this. Account this behavior in Kunit tests as well.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>


It looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>


> ---
>   fs/ext4/extents.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index a581e9278d48..3d45abfb13cd 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3844,6 +3844,7 @@ static struct ext4_ext_path *
>   convert_initialized_extent(handle_t *handle, struct inode *inode,
>   			   struct ext4_map_blocks *map,
>   			   struct ext4_ext_path *path,
> +			   int flags,
>   			   unsigned int *allocated)
>   {
>   	struct ext4_extent *ex;
> @@ -3869,11 +3870,11 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
>   
>   	if (ee_block != map->m_lblk || ee_len > map->m_len) {
>   		path = ext4_split_convert_extents(handle, inode, map, path,
> -				EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, NULL);
> +						  flags, NULL);
>   		if (IS_ERR(path))
>   			return path;
>   
> -		path = ext4_find_extent(inode, map->m_lblk, path, 0);
> +		path = ext4_find_extent(inode, map->m_lblk, path, flags);
>   		if (IS_ERR(path))
>   			return path;
>   		depth = ext_depth(inode);
> @@ -4263,7 +4264,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
>   			if ((!ext4_ext_is_unwritten(ex)) &&
>   			    (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) {
>   				path = convert_initialized_extent(handle,
> -					inode, map, path, &allocated);
> +					inode, map, path, flags, &allocated);
>   				if (IS_ERR(path))
>   					err = PTR_ERR(path);
>   				goto out;
Re: [PATCH v2 4/8] ext4: propagate flags to convert_initialized_extent()
Posted by Jan Kara 3 weeks, 2 days ago
On Wed 14-01-26 20:27:48, Ojaswin Mujoo wrote:
> Currently, ext4_zero_range passes EXT4_EX_NOCACHE flag to avoid caching
> extents however this is not respected by convert_initialized_extent().
> Hence, modify it to accept flags from the caller and to pass the flags
> on to other extent manipulation functions it calls. This makes
> sure the NOCACHE flag is respected throughout the code path.
> 
> Also, we no longer explicitly pass CONVERT_UNWRITTEN as the caller takes
> care of this. Account this behavior in Kunit tests as well.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

I don't see any changes in tests here as the changelog states. Otherwise it
looks good. Feel free to add:

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

									Honza

> ---
>  fs/ext4/extents.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index a581e9278d48..3d45abfb13cd 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3844,6 +3844,7 @@ static struct ext4_ext_path *
>  convert_initialized_extent(handle_t *handle, struct inode *inode,
>  			   struct ext4_map_blocks *map,
>  			   struct ext4_ext_path *path,
> +			   int flags,
>  			   unsigned int *allocated)
>  {
>  	struct ext4_extent *ex;
> @@ -3869,11 +3870,11 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
>  
>  	if (ee_block != map->m_lblk || ee_len > map->m_len) {
>  		path = ext4_split_convert_extents(handle, inode, map, path,
> -				EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, NULL);
> +						  flags, NULL);
>  		if (IS_ERR(path))
>  			return path;
>  
> -		path = ext4_find_extent(inode, map->m_lblk, path, 0);
> +		path = ext4_find_extent(inode, map->m_lblk, path, flags);
>  		if (IS_ERR(path))
>  			return path;
>  		depth = ext_depth(inode);
> @@ -4263,7 +4264,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
>  			if ((!ext4_ext_is_unwritten(ex)) &&
>  			    (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) {
>  				path = convert_initialized_extent(handle,
> -					inode, map, path, &allocated);
> +					inode, map, path, flags, &allocated);
>  				if (IS_ERR(path))
>  					err = PTR_ERR(path);
>  				goto out;
> -- 
> 2.52.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [PATCH v2 4/8] ext4: propagate flags to convert_initialized_extent()
Posted by Ojaswin Mujoo 3 weeks, 1 day ago
On Thu, Jan 15, 2026 at 11:59:56AM +0100, Jan Kara wrote:
> On Wed 14-01-26 20:27:48, Ojaswin Mujoo wrote:
> > Currently, ext4_zero_range passes EXT4_EX_NOCACHE flag to avoid caching
> > extents however this is not respected by convert_initialized_extent().
> > Hence, modify it to accept flags from the caller and to pass the flags
> > on to other extent manipulation functions it calls. This makes
> > sure the NOCACHE flag is respected throughout the code path.
> > 
> > Also, we no longer explicitly pass CONVERT_UNWRITTEN as the caller takes
> > care of this. Account this behavior in Kunit tests as well.
> > 
> > Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> 
> I don't see any changes in tests here as the changelog states. Otherwise it
> looks good. Feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 
> 									Honza

Oh right, I changed the design a bit but fogot to update the commit.
I'll do that, thanks!

Regards,
ojaswin