ext4: defend against inline-to-block conversion race in write completion
PATCH 1/1 ext4: defend against inline-to-block conversion race in write completion
Replace BUG_ON(!ext4_has_inline_data(inode)) with defensive error handling in ext4_write_inline_data_end(). A file can be converted from inline to block storage by concurrent paths while a write completion is in flight.
Lock-based synchronization is impractical here since multiple conversion paths use different locks. Defensive check with proper cleanup
handles all races uniformly and safely.
--- fs/ext4/inline.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/inline.c +8 -1
@@ -812,7 +812,14 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, goto out; }ext4_write_lock_xattr (inode, &no_expand); -BUG_ON (!ext4_has_inline_data (inode)); +/* File may have been converted to block storage by concurrent path */ +if (!ext4_has_inline_data (inode)) { +ext4_write_unlock_xattr (inode, &no_expand); +brelse (iloc.bh); +folio_unlock (folio); +folio_put (folio); +return -EIO ; + }/* * ei->i_inline_off may have changed since
Signature · 1 line
2.43.0
Theodore Tso
maintainerQuoted 3 lines · Deepanshu Kartikey
Replace BUG_ON(!ext4_has_inline_data(inode)) with defensive error handling in
ext4_write_inline_data_end(). A file can be converted from inline to block storage by concurrent paths while a write completion is in flight.
Thanks for this proposed change. It's covered, as part of Aditya Prakash Srivastava change, "ext4: use fsdata to track inline data write state and fix race"[1] which is being tested in my tree.
[1] https://patch.msgid.link/[email protected]
- Ted