f2fs-tools: fix resize.f2fs (#9800)
[openwrt/staging/mkresin.git] / package / utils / f2fs-tools / patches / 200-resize_f2fs-fix_wrong_ovp_calculation.patch
1 From f056fbeff08d30a6d9acdb9e06704461ceee3500 Mon Sep 17 00:00:00 2001
2 From: Jaegeuk Kim <jaegeuk@kernel.org>
3 Date: Thu, 1 Apr 2021 20:13:55 -0700
4 Subject: resize.f2fs: fix wrong ovp calculation
5
6 beroal reported a mount failure due to broken valid_user_blocks.
7 [ 6890.647749] F2FS-fs (loop0): Wrong valid_user_blocks: 16040048,
8 user_block_count: 10016768
9
10 From fsck,
11
12 segment_count_main [0x 9a95 : 39573]
13 -> 39573 * 2MB = 78GB as user space
14
15 overprov_segment_count [0x 4e29 : 20009]
16 -> 20009 * 2MB = 40GB as overprovisioned space which user can't see.
17
18 But,
19 [FSCK] valid_block_count matching with CP [Ok..] [0xf4c070]
20 -> 0xf4c070 = 16040048
21
22 valid_block_count [0x f4c070 : 16040048]
23 -> So, this is correct.
24
25 It turns out resize.f2fs gave very large and wrong overprovisioning space
26 result in shortage of user blocks. The root cause was f2fs_get_usable_segments()
27 didn't consider resize case which needs segment_count_main from new superblock.
28
29 Fixes: f8410857b7a8 ("f2fs-tools: zns zone-capacity support")
30 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
31 ---
32 lib/libf2fs_zoned.c | 3 +++
33 1 file changed, 3 insertions(+)
34
35 --- a/lib/libf2fs_zoned.c
36 +++ b/lib/libf2fs_zoned.c
37 @@ -495,6 +495,9 @@ uint32_t f2fs_get_usable_segments(struct
38 int i, j;
39 uint32_t usable_segs = 0, zone_segs;
40
41 + if (c.func == RESIZE)
42 + return get_sb(segment_count_main);
43 +
44 for (i = 0; i < c.ndevs; i++) {
45 if (c.devices[i].zoned_model != F2FS_ZONED_HM) {
46 usable_segs += c.devices[i].total_segments;