mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
f2fs: force out-place update for all writes on compressed file
For compressed file, compressed write may fail and fall back to raw
write.
-Thread A - Thread B
- f2fs_write_multi_pages - f2fs_down_write(&sbi->cp_rwsem);
- f2fs_write_compressed_pages - ...
- f2fs_trylock_op - ...
- f2fs_down_read_trylock(&sbi->cp_rwsem); - ...
- f2fs_write_raw_pages - ...
Thread B acquires the lock first, which causes Thread A to fail lock
acquisition and fall back to raw-data write.
IPU_FORCE is enabled on small-capacity storage devices (< 16GB),
so f2fs_write_raw_pages() overwrites the original compressed data
in-place.
The in-memory node has been updated with raw-data addresses, while the
node metadata stored on eMMC still remains in compressed state.
If a power-cut occurs before the node is flushed to disk, on-disk
inconsistency arises: disk data is raw, yet metadata treats it as a
compressed cluster, leading to decompression failure.
To eliminate this risk completely, force out-place update for all
write operations on compressed file.
Cc: stable@kernel.org
Fixes: 4c8ff7095b ("f2fs: support data compression")
Signed-off-by: Jiucheng Xu <jiucheng.xu@amlogic.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
06768d77ed
commit
a64a3fec11
|
|
@ -2914,10 +2914,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 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user