resize.f2fs: fix to always change metadata for expand resize
PATCH 1/1 resize.f2fs: fix to always change metadata for expand resize
w/ below testcase, resize will generate a corrupted image which contains inconsistent metadata:
touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img /mnt/f2fs
[ 31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762 [ 31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpoint
The root cause is safe mode (via -s option) is not compatible w/ expand resize, due to in safe mode, we will keep all parameters related to NAT, SIT, SSA area, e.g. sit_bitmap_size, however, we will update segment_count_main according new partition size, result in there is no enough sit_bitmap and SIT blocks to address the entire block address of new partition.
Adding a check condition to avoid expanding partition in safe mode, and change manual accordingly.
--- fsck/resize.c | 12 ++++++++---- man/resize.f2fs.8 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)
fsck/resize.c +8 -4
@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)/* may different sector size */ if ((c.target_sectors * c.sector_size >> -get_sb (log_blocksize)) <get_sb (block_count)) +get_sb (log_blocksize)) <get_sb (block_count)) {if (!c.safe_resize) {ASSERT_MSG ("Nothing to resize, now only supports resizing with safe resize flag\n" );return -1 ; }else {return f2fs_resize_shrink (sbi); } -else if (((c.target_sectors * c.sector_size >> + }else if (((c.target_sectors * c.sector_size >>get_sb (log_blocksize)) >get_sb (block_count)) || - c.ignore_error) + c.ignore_error) { +if (c.safe_resize) { +ASSERT_MSG ("Expanding resize doesn't support safe resize flag" ); +return -1 ; + }return f2fs_resize_grow (sbi); -else { + }else {MSG (0 ,"Nothing to resize.\n" );return 0 ; }
man/resize.f2fs.8 +1 -1
@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly. Specify support write hint. .TP .BI \-s -Enable safe resize. +Enable safe resize, it can only be used w/ shrink resize. .TP .BI \-V Print the version number and exit.
Signature · 8 lines
2.49.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hm.
Would this be what @uplinkr might have encountered?
Quoted 78 lines · On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel…
w/ below testcase, resize will generate a corrupted image which contains inconsistent metadata:
touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img/mnt/f2fs[ 31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762 [ 31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpointThe root cause is safe mode (via -s option) is not compatible w/ expand resize, due to in safe mode, we will keep all parameters related to NAT, SIT, SSA area, e.g.
sit_bitmap_size, however, we will updatesegment_count_mainaccording new partition size, result in there is no enoughsit_bitmapand SIT blocks to address the entire block address of new partition.Adding a check condition to avoid expanding partition in safe mode, and change manual accordingly.
Signed-off-by Chao Yu <[email protected]>--- fsck/resize.c | 12 ++++++++---- man/resize.f2fs.8 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)fsck/resize.c +8
-4@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)/* may different sector size */ if ((c.target_sectors * c.sector_size >> -get_sb (log_blocksize)) <get_sb (block_count)) +get_sb (log_blocksize)) <get_sb (block_count)) {if (!c.safe_resize) {ASSERT_MSG ("Nothing to resize, now only supports resizing with safe resize flag\n" );return -1 ; }else {return f2fs_resize_shrink (sbi); } -else if (((c.target_sectors * c.sector_size >> + }else if (((c.target_sectors * c.sector_size >>get_sb (log_blocksize)) >get_sb (block_count)) || - c.ignore_error) + c.ignore_error) { +if (c.safe_resize) { +ASSERT_MSG ("Expanding resize doesn't support safe resize flag" ); +return -1 ; + }return f2fs_resize_grow (sbi); -else { + }else {MSG (0 ,"Nothing to resize.\n" );return 0 ; }man/resize.f2fs.8 +1
-2@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly. Specify support write hint. .TP .BI \-s -Enable safe resize. +Enable safe resize, it can only be used w/ shrink resize. .TP .BI \-V Print the version number and exit. --2.49.0
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 3 lines · Juhyung Park
Hm.
Would this be what @uplinkr might have encountered?
Maybe, :)
@uplinkr, previously, if you used '-s' parameter while expand-resizing, that could be the reason it corrupted your partition.
Thanks,
Quoted 81 lines
Quoted 78 lines · On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel…
w/ below testcase, resize will generate a corrupted image which contains inconsistent metadata:
touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img/mnt/f2fs[ 31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762 [ 31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpointThe root cause is safe mode (via -s option) is not compatible w/ expand resize, due to in safe mode, we will keep all parameters related to NAT, SIT, SSA area, e.g.
sit_bitmap_size, however, we will updatesegment_count_mainaccording new partition size, result in there is no enoughsit_bitmapand SIT blocks to address the entire block address of new partition.Adding a check condition to avoid expanding partition in safe mode, and change manual accordingly.
Signed-off-by Chao Yu <[email protected]>--- fsck/resize.c | 12 ++++++++---- man/resize.f2fs.8 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)fsck/resize.c +8
-4@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)/* may different sector size */ if ((c.target_sectors * c.sector_size >> -get_sb (log_blocksize)) <get_sb (block_count)) +get_sb (log_blocksize)) <get_sb (block_count)) {if (!c.safe_resize) {ASSERT_MSG ("Nothing to resize, now only supports resizing with safe resize flag\n" );return -1 ; }else {return f2fs_resize_shrink (sbi); } -else if (((c.target_sectors * c.sector_size >> + }else if (((c.target_sectors * c.sector_size >>get_sb (log_blocksize)) >get_sb (block_count)) || - c.ignore_error) + c.ignore_error) { +if (c.safe_resize) { +ASSERT_MSG ("Expanding resize doesn't support safe resize flag" ); +return -1 ; + }return f2fs_resize_grow (sbi); -else { + }else {MSG (0 ,"Nothing to resize.\n" );return 0 ; }man/resize.f2fs.8 +1
-2@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly. Specify support write hint. .TP .BI \-s -Enable safe resize. +Enable safe resize, it can only be used w/ shrink resize. .TP .BI \-V Print the version number and exit. --2.49.0
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Just checked gparted's source code:
https://github.com/GNOME/gparted/blob/GPARTED_1_7_0/src/f2fs.cc#L135
Seems unlikely. :/
Quoted 94 lines · Chao Yu
Quoted 3 lines · Juhyung Park
Hm.
Would this be what @uplinkr might have encountered?
Maybe, :)
@uplinkr, previously, if you used '-s' parameter while expand-resizing, that could be the reason it corrupted your partition.
Thanks,
Quoted 81 lines
Quoted 78 lines · On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel…
w/ below testcase, resize will generate a corrupted image which contains inconsistent metadata:
touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img/mnt/f2fs[ 31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762 [ 31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpointThe root cause is safe mode (via -s option) is not compatible w/ expand resize, due to in safe mode, we will keep all parameters related to NAT, SIT, SSA area, e.g.
sit_bitmap_size, however, we will updatesegment_count_mainaccording new partition size, result in there is no enoughsit_bitmapand SIT blocks to address the entire block address of new partition.Adding a check condition to avoid expanding partition in safe mode, and change manual accordingly.
Signed-off-by Chao Yu <[email protected]>--- fsck/resize.c | 12 ++++++++---- man/resize.f2fs.8 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)fsck/resize.c +8
-4@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)/* may different sector size */ if ((c.target_sectors * c.sector_size >> -get_sb (log_blocksize)) <get_sb (block_count)) +get_sb (log_blocksize)) <get_sb (block_count)) {if (!c.safe_resize) {ASSERT_MSG ("Nothing to resize, now only supports resizing with safe resize flag\n" );return -1 ; }else {return f2fs_resize_shrink (sbi); } -else if (((c.target_sectors * c.sector_size >> + }else if (((c.target_sectors * c.sector_size >>get_sb (log_blocksize)) >get_sb (block_count)) || - c.ignore_error) + c.ignore_error) { +if (c.safe_resize) { +ASSERT_MSG ("Expanding resize doesn't support safe resize flag" ); +return -1 ; + }return f2fs_resize_grow (sbi); -else { + }else {MSG (0 ,"Nothing to resize.\n" );return 0 ; }man/resize.f2fs.8 +1
-2@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly. Specify support write hint. .TP .BI \-s -Enable safe resize. +Enable safe resize, it can only be used w/ shrink resize. .TP .BI \-V Print the version number and exit. --2.49.0
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 4 lines · Juhyung Park
Just checked gparted's source code:
https://github.com/GNOME/gparted/blob/GPARTED_1_7_0/src/f2fs.cc#L135Seems unlikely. :/
Alright, seems still we need another testcase for reproducing. :(
Thanks,
Quoted 96 lines · Chao Yu
Quoted 94 lines · Juhyung Park
Quoted 3 lines
Hm.
Would this be what @uplinkr might have encountered?
Maybe, :)
@uplinkr, previously, if you used '-s' parameter while expand-resizing, that could be the reason it corrupted your partition.
Thanks,
Quoted 81 lines
Quoted 78 lines · On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel…
w/ below testcase, resize will generate a corrupted image which contains inconsistent metadata:
touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s img -t $((1024*1024*1024))
mount img/mnt/f2fs[ 31.725200] F2FS-fs (loop0): Wrong bitmap size: sit: 192, sit_blk_cnt:4762 [ 31.728441] F2FS-fs (loop0): Failed to get valid F2FS checkpointThe root cause is safe mode (via -s option) is not compatible w/ expand resize, due to in safe mode, we will keep all parameters related to NAT, SIT, SSA area, e.g.
sit_bitmap_size, however, we will updatesegment_count_mainaccording new partition size, result in there is no enoughsit_bitmapand SIT blocks to address the entire block address of new partition.Adding a check condition to avoid expanding partition in safe mode, and change manual accordingly.
Signed-off-by Chao Yu <[email protected]>--- fsck/resize.c | 12 ++++++++---- man/resize.f2fs.8 | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)fsck/resize.c +8
-4@@ -756,18 +756,22 @@ int f2fs_resize(struct f2fs_sb_info *sbi)/* may different sector size */ if ((c.target_sectors * c.sector_size >> -get_sb (log_blocksize)) <get_sb (block_count)) +get_sb (log_blocksize)) <get_sb (block_count)) {if (!c.safe_resize) {ASSERT_MSG ("Nothing to resize, now only supports resizing with safe resize flag\n" );return -1 ; }else {return f2fs_resize_shrink (sbi); } -else if (((c.target_sectors * c.sector_size >> + }else if (((c.target_sectors * c.sector_size >>get_sb (log_blocksize)) >get_sb (block_count)) || - c.ignore_error) + c.ignore_error) { +if (c.safe_resize) { +ASSERT_MSG ("Expanding resize doesn't support safe resize flag" ); +return -1 ; + }return f2fs_resize_grow (sbi); -else { + }else {MSG (0 ,"Nothing to resize.\n" );return 0 ; }man/resize.f2fs.8 +1
-2@@ -69,7 +69,7 @@ Skip caution dialogue and resize partition directly. Specify support write hint. .TP .BI \-s -Enable safe resize. +Enable safe resize, it can only be used w/ shrink resize. .TP .BI \-V Print the version number and exit. --2.49.0
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel