Re: [PATCH 01/10] ext4: add did_zero output parameter to ext4_block_zero_page_range()
From: Jan Kara
Date: Mon Mar 23 2026 - 12:48:19 EST
On Tue 10-03-26 09:40:52, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@xxxxxxxxxx>
>
> Add a bool *did_zero output parameter to ext4_block_zero_page_range()
> and __ext4_block_zero_page_range(). The parameter reports whether a
> partial block was zeroed out, which is needed for the upcoming iomap
> buffered I/O conversion.
>
> Signed-off-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@xxxxxxx>
Honza
> ---
> fs/ext4/inode.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 396dc3a5d16b..1e037a314dab 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4003,7 +4003,8 @@ void ext4_set_aops(struct inode *inode)
> * racing writeback can come later and flush the stale pagecache to disk.
> */
> static int __ext4_block_zero_page_range(handle_t *handle,
> - struct address_space *mapping, loff_t from, loff_t length)
> + struct address_space *mapping, loff_t from, loff_t length,
> + bool *did_zero)
> {
> unsigned int offset, blocksize, pos;
> ext4_lblk_t iblock;
> @@ -4091,6 +4092,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
> err = ext4_jbd2_inode_add_write(handle, inode, from,
> length);
> }
> + if (!err && did_zero)
> + *did_zero = true;
>
> unlock:
> folio_unlock(folio);
> @@ -4106,7 +4109,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
> * that corresponds to 'from'
> */
> static int ext4_block_zero_page_range(handle_t *handle,
> - struct address_space *mapping, loff_t from, loff_t length)
> + struct address_space *mapping, loff_t from, loff_t length,
> + bool *did_zero)
> {
> struct inode *inode = mapping->host;
> unsigned blocksize = inode->i_sb->s_blocksize;
> @@ -4120,10 +4124,11 @@ static int ext4_block_zero_page_range(handle_t *handle,
> length = max;
>
> if (IS_DAX(inode)) {
> - return dax_zero_range(inode, from, length, NULL,
> + return dax_zero_range(inode, from, length, did_zero,
> &ext4_iomap_ops);
> }
> - return __ext4_block_zero_page_range(handle, mapping, from, length);
> + return __ext4_block_zero_page_range(handle, mapping, from, length,
> + did_zero);
> }
>
> /*
> @@ -4146,7 +4151,7 @@ static int ext4_block_truncate_page(handle_t *handle,
> blocksize = i_blocksize(inode);
> length = blocksize - (from & (blocksize - 1));
>
> - return ext4_block_zero_page_range(handle, mapping, from, length);
> + return ext4_block_zero_page_range(handle, mapping, from, length, NULL);
> }
>
> int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
> @@ -4169,13 +4174,13 @@ int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
> if (start == end &&
> (partial_start || (partial_end != sb->s_blocksize - 1))) {
> err = ext4_block_zero_page_range(handle, mapping,
> - lstart, length);
> + lstart, length, NULL);
> return err;
> }
> /* Handle partial zero out on the start of the range */
> if (partial_start) {
> - err = ext4_block_zero_page_range(handle, mapping,
> - lstart, sb->s_blocksize);
> + err = ext4_block_zero_page_range(handle, mapping, lstart,
> + sb->s_blocksize, NULL);
> if (err)
> return err;
> }
> @@ -4183,7 +4188,7 @@ int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
> if (partial_end != sb->s_blocksize - 1)
> err = ext4_block_zero_page_range(handle, mapping,
> byte_end - partial_end,
> - partial_end + 1);
> + partial_end + 1, NULL);
> return err;
> }
>
> --
> 2.52.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR