* [PATCH] ext4: retry inline data conversion on -EAGAIN
@ 2026-11-30 9:40 Petr Vaněk
2026-11-30 9:49 ` Petr Vaněk
2026-11-30 9:53 ` sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Petr Vaněk @ 2026-11-30 9:40 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi
Cc: Petr Vaněk, Sashiko, stable, linux-ext4
Commit e2c4c49dee64 ("ext4: restart handle if credits are insufficient
during allocating blocks") made ext4_block_write_begin() return -EAGAIN
when it cannot extend the handle, and taught its callers in inode.c to
retry. ext4_convert_inline_data_to_extent() was missed and passes the
error to write(2). It always needs the extension, because its handle is
sized before the inode has an extent tree, so with nodelalloc a write
that converts inline data fails with EAGAIN when a commit starts.
Retry on -EAGAIN like the other callers.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/linux-ext4/sashiko-outbox-236164@kernel.org/
Fixes: e2c4c49dee64 ("ext4: restart handle if credits are insufficient during allocating blocks")
Cc: stable@vger.kernel.org
---
Found while checking a review comment on "ext4: convert regular file
inline data through the page cache", which has the same gap.
Reproduced in QEMU (x86_64, 4 CPUs) on a 1k-block filesystem with a
1 MiB journal, mounted with nodelalloc: 8 threads create a file, write
42 bytes and then 300 bytes at offset 100, while another thread loops on
sync(). In each of three 20-second runs, write() failed with EAGAIN
about 300 times on e2c4c49dee64 and never on its parent. With this
patch it never failed, and every file read back intact. The ext4 KUnit
suite passes.
After a failed attempt the error path has already dropped the inline
data, so the retry continues from the data in folio 0, as the existing
ENOSPC retry does.
This patch was developed with the help of an AI coding assistant
(Claude Opus via OpenCode). It analysed the bug, wrote the fix, the
changelog and the reproducer; I reviewed the change and the test
results.
fs/ext4/inline.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index acdc65ce4796..274cc96daec7 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -682,7 +682,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
ext4_orphan_del(NULL, inode);
}
- if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
+ if (ret == -EAGAIN ||
+ (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)))
goto retry;
if (folio)
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: retry inline data conversion on -EAGAIN
2026-11-30 9:40 [PATCH] ext4: retry inline data conversion on -EAGAIN Petr Vaněk
@ 2026-11-30 9:49 ` Petr Vaněk
2026-11-30 9:53 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Petr Vaněk @ 2026-11-30 9:49 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi
Cc: Sashiko, stable, linux-ext4
On Mon, Nov 30, 2026 at 10:40:48AM +0100, Petr Vaněk wrote:
> Commit e2c4c49dee64 ("ext4: restart handle if credits are insufficient
> during allocating blocks") made ext4_block_write_begin() return -EAGAIN
> when it cannot extend the handle, and taught its callers in inode.c to
> retry. ext4_convert_inline_data_to_extent() was missed and passes the
> error to write(2). It always needs the extension, because its handle is
> sized before the inode has an extent tree, so with nodelalloc a write
> that converts inline data fails with EAGAIN when a commit starts.
>
> Retry on -EAGAIN like the other callers.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/linux-ext4/sashiko-outbox-236164@kernel.org/
> Fixes: e2c4c49dee64 ("ext4: restart handle if credits are insufficient during allocating blocks")
> Cc: stable@vger.kernel.org
I forgot to append my
Signed-off-by: Petr Vaněk <petr.vanek@e2b.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: retry inline data conversion on -EAGAIN
2026-11-30 9:40 [PATCH] ext4: retry inline data conversion on -EAGAIN Petr Vaněk
2026-11-30 9:49 ` Petr Vaněk
@ 2026-11-30 9:53 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-30 9:53 UTC (permalink / raw)
To: Petr Vaněk; +Cc: linux-ext4, tytso
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] ext4: data loss on -EAGAIN retry in
ext4_convert_inline_data_to_extent()
- [High] ext4: missing Signed-off-by trailer in commit message
--
commit 5b9d895c8cda9a4767a10cb3e7eca662442af68d
Author: Petr Vaněk <petr.vanek@e2b.dev>
> ext4: retry inline data conversion on -EAGAIN
>
> Commit e2c4c49dee64 ("ext4: restart handle if credits are insufficient
> during allocating blocks") made ext4_block_write_begin() return -EAGAIN
> when it cannot extend the handle, and taught its callers in inode.c to
> retry. ext4_convert_inline_data_to_extent() was missed and passes the
> error to write(2). It always needs the extension, because its handle is
> sized before the inode has an extent tree, so with nodelalloc a write
> that converts inline data fails with EAGAIN when a commit starts.
>
> Retry on -EAGAIN like the other callers.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/linux-ext4/sashiko-outbox-236164@kernel.org/
> Fixes: e2c4c49dee64 ("ext4: restart handle if credits are insufficient during allocating blocks")
> Cc: stable@vger.kernel.org
[Severity: High]
The commit message is missing a Signed-off-by: trailer from the author.
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index acdc65ce47960..274cc96daec7b 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
> @@ -682,7 +682,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
> ext4_orphan_del(NULL, inode);
> }
>
> - if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
> + if (ret == -EAGAIN ||
> + (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)))
> goto retry;
>
> if (folio)
[Severity: Critical]
Does jumping back to retry on -EAGAIN silently drop the original inline
data and leave logical block 0 unallocated?
Before ext4_block_write_begin() runs and returns -EAGAIN, the first pass
has already read the inline data into folio 0 (leaving it uptodate, clean,
and unmapped) and called ext4_destroy_inline_data_nolock(), which deletes
the on-disk inline data, clears EXT4_INODE_INLINE_DATA, and zeroes
i_inline_off and i_inline_size. The error path then unlocks and releases
folio 0 and stops the journal handle, committing the removal of the inline
data.
On the retry pass, ext4_convert_inline_data_to_extent() re-checks whether
the inode still has inline data:
fs/ext4/inline.c:ext4_convert_inline_data_to_extent() {
...
/* If some one has already done this for us, just exit. */
if (!ext4_has_inline_data(inode)) {
ret = 0;
goto out;
}
from = 0;
to = ext4_get_inline_size(inode);
...
}
Because the first attempt already cleared the inline state,
ext4_has_inline_data(inode) is now false (and ext4_get_inline_size(inode)
is 0), so the retry immediately exits with ret = 0 without calling
ext4_block_write_begin() or block_commit_write(). If the write that
triggered conversion starts at or past logical block 1 (or if clean,
unlocked folio 0 is reclaimed before ext4_write_begin() re-locks it),
logical block 0 is never allocated or dirtied and the original inline data
is permanently lost, reading back as a hole of zeros once folio 0 is
evicted.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130094048.1869586-1-petr.vanek@e2b.dev?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 9:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 9:40 [PATCH] ext4: retry inline data conversion on -EAGAIN Petr Vaněk
2026-11-30 9:49 ` Petr Vaněk
2026-11-30 9:53 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox