mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic()
@ 2026-10-23 10:23 Ojaswin Mujoo
  2026-10-23 11:56 ` Jan Kara
  2026-10-24  1:52 ` Zhang Yi
  0 siblings, 2 replies; 3+ messages in thread
From: Ojaswin Mujoo @ 2026-10-23 10:23 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
	Ritesh Harjani (IBM),
	Zhang Yi
  Cc: linux-ext4, linux-kernel

We should ideally never encounter a hole during the endio conversion as
that indicates something is wrong with our extent handling. Still if we do
find a hole at atomic write endio, ext4_map_blocks() returns 0 which would
be returned back to callers by ext4_convert_unwritten_extents_atomic().
This can be wrongly interpreted as a success. Fix this by bailing out with
-EINVAL instead.

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

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 7193429a05e1..b54d8227786b 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5107,6 +5107,14 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,
 		map.m_lblk += ret;
 		map.m_len = (max_blocks -= ret);
 		ret = ext4_map_blocks(handle, inode, &map, flags);
+		if (ret == 0) {
+			ext4_msg(inode->i_sb, KERN_ERR,
+				 "inode #%llu: block %u: len %u: "
+				 "hole found while converting extents for atomic write",
+				 inode->i_ino, map.m_lblk, map.m_len);
+			ret = -EINVAL;
+			break;
+		}
 		if (ret != max_blocks)
 			ext4_msg(inode->i_sb, KERN_INFO,
 				     "inode #%llu: block %u: len %u: "

---
base-commit: 8c4f6e3376348fc3162eed86a05b933921c8f9ed
change-id: 20261023-ext4-atomic-endio-fix-b4-9e1ead9e1aca

Best regards,
-- 
Ojaswin Mujoo <ojaswin@linux.ibm.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic()
  2026-10-23 10:23 [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic() Ojaswin Mujoo
@ 2026-10-23 11:56 ` Jan Kara
  2026-10-24  1:52 ` Zhang Yi
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2026-10-23 11:56 UTC (permalink / raw)
  To: Ojaswin Mujoo
  Cc: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
	Ritesh Harjani (IBM),
	Zhang Yi, linux-ext4, linux-kernel

On Fri 23-10-26 15:53:45, Ojaswin Mujoo wrote:
> We should ideally never encounter a hole during the endio conversion as
> that indicates something is wrong with our extent handling. Still if we do
> find a hole at atomic write endio, ext4_map_blocks() returns 0 which would
> be returned back to callers by ext4_convert_unwritten_extents_atomic().
> This can be wrongly interpreted as a success. Fix this by bailing out with
> -EINVAL instead.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Makes sense! Feel free to add:

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

								Honza

> ---
>  fs/ext4/extents.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 7193429a05e1..b54d8227786b 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5107,6 +5107,14 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,
>  		map.m_lblk += ret;
>  		map.m_len = (max_blocks -= ret);
>  		ret = ext4_map_blocks(handle, inode, &map, flags);
> +		if (ret == 0) {
> +			ext4_msg(inode->i_sb, KERN_ERR,
> +				 "inode #%llu: block %u: len %u: "
> +				 "hole found while converting extents for atomic write",
> +				 inode->i_ino, map.m_lblk, map.m_len);
> +			ret = -EINVAL;
> +			break;
> +		}
>  		if (ret != max_blocks)
>  			ext4_msg(inode->i_sb, KERN_INFO,
>  				     "inode #%llu: block %u: len %u: "
> 
> ---
> base-commit: 8c4f6e3376348fc3162eed86a05b933921c8f9ed
> change-id: 20261023-ext4-atomic-endio-fix-b4-9e1ead9e1aca
> 
> Best regards,
> -- 
> Ojaswin Mujoo <ojaswin@linux.ibm.com>
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic()
  2026-10-23 10:23 [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic() Ojaswin Mujoo
  2026-10-23 11:56 ` Jan Kara
@ 2026-10-24  1:52 ` Zhang Yi
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang Yi @ 2026-10-24  1:52 UTC (permalink / raw)
  To: Ojaswin Mujoo
  Cc: linux-ext4, linux-kernel, Theodore Ts'o, Andreas Dilger,
	Baokun Li, Jan Kara, Ritesh Harjani (IBM),
	Zhang Yi

On 10/23/2026 6:23 PM, Ojaswin Mujoo wrote:
> We should ideally never encounter a hole during the endio conversion as
> that indicates something is wrong with our extent handling. Still if we do
> find a hole at atomic write endio, ext4_map_blocks() returns 0 which would
> be returned back to callers by ext4_convert_unwritten_extents_atomic().
> This can be wrongly interpreted as a success. Fix this by bailing out with
> -EINVAL instead.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Ha, this looks good to me, thanks!

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

> ---
>   fs/ext4/extents.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 7193429a05e1..b54d8227786b 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5107,6 +5107,14 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,
>   		map.m_lblk += ret;
>   		map.m_len = (max_blocks -= ret);
>   		ret = ext4_map_blocks(handle, inode, &map, flags);
> +		if (ret == 0) {
> +			ext4_msg(inode->i_sb, KERN_ERR,
> +				 "inode #%llu: block %u: len %u: "
> +				 "hole found while converting extents for atomic write",
> +				 inode->i_ino, map.m_lblk, map.m_len);
> +			ret = -EINVAL;
> +			break;
> +		}
>   		if (ret != max_blocks)
>   			ext4_msg(inode->i_sb, KERN_INFO,
>   				     "inode #%llu: block %u: len %u: "
> 
> ---
> base-commit: 8c4f6e3376348fc3162eed86a05b933921c8f9ed
> change-id: 20261023-ext4-atomic-endio-fix-b4-9e1ead9e1aca
> 
> Best regards,


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-24  1:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 10:23 [PATCH] ext4: return -EINVAL on hole in ext4_convert_unwritten_extents_atomic() Ojaswin Mujoo
2026-10-23 11:56 ` Jan Kara
2026-10-24  1:52 ` Zhang Yi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®