f2fs: force out-place update for all writes on compressed file
PATCH 1/1 f2fs: force out-place update for all writes on compressed file
For compressed file, compressed write may fail and fall back to raw write.
If in-place update(IPU) is allowed, raw data could be written into disk before cluster metadata is updated from compressed state to raw state. Sudden power-cut during this window will result in inconsistency:
raw data on disk but metadata still expects compressed content, which causes decompression failure when reading the file later.
To eliminate this risk completely, force out-place update for all write operations on compressed file, so IPU will never be used.
Signed-off-by Jiucheng Xu <[email protected]>
--- fs/f2fs/data.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/f2fs/data.c +6 -4
@@ -2973,10 +2973,12 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (f2fs_used_in_atomic_write (inode))return true; -/* rewrite low ratio compress data w/ OPU mode to avoid fragmentation */ -if (f2fs_compressed_file (inode) && -F2FS_OPTION (sbi).compress_mode ==COMPR_MODE_USER && -is_inode_flag_set (inode,FI_ENABLE_COMPRESS )) +/* +* rewrite low ratio compress data w/ OPU mode to avoid fragmentation. +* If IO comes from compressed write path and fallback to raw write, +* force out‑place to prevent metadata‑data inconsistency. +*/ +if (f2fs_compressed_file (inode))return true;/* swap file is migrating in aligned write mode */
---
base-commit: 0a1703eba23707e3b2edfa2a2329352e7abc0ffa
change-id: 20260818-origin-dev-0e8c63e2145a
Best regards,
Signature · 1 line
Jiucheng Xu <[email protected]>