[RFC PATCH 3/9] ext4: use safe convert path for inline data write overflow

From: Yun Zhou

Date: Mon Jul 27 2026 - 07:05:46 EST


Replace ext4_convert_inline_data_to_extent() with
ext4_convert_inline_data() in the write paths that handle inline data
overflow.

ext4_convert_inline_data_to_extent() destroys inline data before
allocating the target block. If block allocation fails (e.g. -ENOSPC),
the inline data is already gone and cannot be recovered -- a potential
data loss on crash.

ext4_convert_inline_data() keeps
a copy of the inline data in a buffer and restores it on failure, making
the conversion safe against allocation failures.

Signed-off-by: Yun Zhou <yun.zhou@xxxxxxxxxxxxx>
---
fs/ext4/inline.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index ceee69a66482..8f1efe4297a0 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -724,7 +724,7 @@ int ext4_generic_write_inline_data(struct address_space *mapping,
if (!da) {
brelse(iloc.bh);
/* Retry inside */
- return ext4_convert_inline_data_to_extent(mapping, inode);
+ return ext4_convert_inline_data(inode);
}

ret = ext4_da_convert_inline_data_to_extent(mapping, inode);
@@ -785,7 +785,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
struct folio **foliop)
{
if (pos + len > ext4_get_max_inline_size(inode))
- return ext4_convert_inline_data_to_extent(mapping, inode);
+ return ext4_convert_inline_data(inode);
return ext4_generic_write_inline_data(mapping, inode, pos, len,
foliop, false);
}
--
2.43.0