linux/fs/f2fs
Xiuhong Wang 2f6d721e14 f2fs: compress: fix reserve_cblocks counting error when out of space
When a file only needs one direct_node, performing the following
operations will cause the file to be unrepairable:

unisoc # ./f2fs_io compress test.apk
unisoc #df -h | grep dm-48
/dev/block/dm-48 112G 112G 1.2M 100% /data

unisoc # ./f2fs_io release_cblocks test.apk
924
unisoc # df -h | grep dm-48
/dev/block/dm-48 112G 112G 4.8M 100% /data

unisoc # dd if=/dev/random of=file4 bs=1M count=3
3145728 bytes (3.0 M) copied, 0.025 s, 120 M/s
unisoc # df -h | grep dm-48
/dev/block/dm-48 112G 112G 1.8M 100% /data

unisoc # ./f2fs_io reserve_cblocks test.apk
F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device

adb reboot
unisoc # df -h  | grep dm-48
/dev/block/dm-48             112G 112G   11M 100% /data
unisoc # ./f2fs_io reserve_cblocks test.apk
0

This is because the file has only one direct_node. After returning
to -ENOSPC, reserved_blocks += ret will not be executed. As a result,
the reserved_blocks at this time is still 0, which is not the real
number of reserved blocks. Therefore, fsck cannot be set to repair
the file.

After this patch, the fsck flag will be set to fix this problem.

unisoc # df -h | grep dm-48
/dev/block/dm-48             112G 112G  1.8M 100% /data
unisoc # ./f2fs_io reserve_cblocks test.apk
F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device

adb reboot then fsck will be executed
unisoc # df -h  | grep dm-48
/dev/block/dm-48             112G 112G   11M 100% /data
unisoc # ./f2fs_io reserve_cblocks test.apk
924

Fixes: c75488fb4d ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com>
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-03-12 18:25:17 -07:00
..
acl.c fs: port i_{g,u}id_into_vfs{g,u}id() to mnt_idmap 2023-01-19 09:24:29 +01:00
acl.h fs: port ->set_acl() to pass mnt_idmap 2023-01-19 09:24:27 +01:00
checkpoint.c f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-02-27 09:41:12 -08:00
compress.c f2fs: ro: compress: fix to avoid caching unaligned extent 2024-03-04 09:51:52 -08:00
data.c f2fs: relocate f2fs_precache_extents() in f2fs_swap_activate() 2024-03-04 09:51:52 -08:00
debug.c f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
dir.c f2fs: fix to create selinux label during whiteout initialization 2024-02-27 09:41:14 -08:00
extent_cache.c f2fs: split initial and dynamic conditions for extent_cache 2023-09-12 13:49:33 -07:00
f2fs.h f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
file.c f2fs: compress: fix reserve_cblocks counting error when out of space 2024-03-12 18:25:17 -07:00
gc.c f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
gc.h f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-05-17 11:19:23 -07:00
inline.c f2fs: convert to new timestamp accessors 2023-10-18 13:26:22 +02:00
inode.c f2fs update for 6.8-rc1 2024-01-11 20:39:15 -08:00
iostat.c f2fs: add async reset zone command support 2023-06-12 13:04:09 -07:00
iostat.h f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx() 2023-02-07 10:39:28 -08:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: fix to create selinux label during whiteout initialization 2024-02-27 09:41:14 -08:00
node.c f2fs: ro: compress: fix to avoid caching unaligned extent 2024-03-04 09:51:52 -08:00
node.h f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-02-27 09:41:12 -08:00
recovery.c f2fs: fix to check return value __allocate_new_segment 2024-03-04 09:52:51 -08:00
segment.c f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
segment.h f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
shrinker.c f2fs: add block_age-based extent cache 2022-12-12 14:53:56 -08:00
super.c f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup 2024-03-04 10:18:26 -08:00
sysfs.c f2fs: add a proc entry show disk layout 2024-03-06 09:43:26 -08:00
verity.c f2fs: Use folio in f2fs_read_merkle_tree_page 2024-02-27 09:41:15 -08:00
xattr.c f2fs: fix to check return value of f2fs_recover_xattr_data 2023-12-15 15:09:17 -08:00
xattr.h f2fs: move f2fs_xattr_handlers and f2fs_xattr_handler_map to .rodata 2023-10-09 16:24:18 +02:00