* [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
@ 2025-04-14 11:11 Chao Yu via Linux-f2fs-devel
2025-04-15 19:28 ` Juhyung Park
0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-04-14 11:11 UTC (permalink / raw)
To: jaegeuk; +Cc: 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 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.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/resize.c | 12 ++++++++----
man/resize.f2fs.8 | 2 +-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/fsck/resize.c b/fsck/resize.c
index 1ab7d75..58914ec 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -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;
}
diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
index bdda4fd..5b6daf5 100644
--- a/man/resize.f2fs.8
+++ b/man/resize.f2fs.8
@@ -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
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
2025-04-14 11:11 [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize Chao Yu via Linux-f2fs-devel
@ 2025-04-15 19:28 ` Juhyung Park
2025-04-16 3:33 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 5+ messages in thread
From: Juhyung Park @ 2025-04-15 19:28 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel
Hm.
Would this be what @uplinkr might have encountered?
On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel
<linux-f2fs-devel@lists.sourceforge.net> wrote:
>
> 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.
>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> fsck/resize.c | 12 ++++++++----
> man/resize.f2fs.8 | 2 +-
> 2 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 1ab7d75..58914ec 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -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;
> }
> diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
> index bdda4fd..5b6daf5 100644
> --- a/man/resize.f2fs.8
> +++ b/man/resize.f2fs.8
> @@ -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
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
2025-04-15 19:28 ` Juhyung Park
@ 2025-04-16 3:33 ` Chao Yu via Linux-f2fs-devel
2025-04-16 3:40 ` Juhyung Park
0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-04-16 3:33 UTC (permalink / raw)
To: Juhyung Park, uplinkr; +Cc: jaegeuk, linux-f2fs-devel
On 4/16/25 03:28, Juhyung Park wrote:
> 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,
>
> On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel
> <linux-f2fs-devel@lists.sourceforge.net> wrote:
>>
>> 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.
>>
>> Signed-off-by: Chao Yu <chao@kernel.org>
>> ---
>> fsck/resize.c | 12 ++++++++----
>> man/resize.f2fs.8 | 2 +-
>> 2 files changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index 1ab7d75..58914ec 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -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;
>> }
>> diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
>> index bdda4fd..5b6daf5 100644
>> --- a/man/resize.f2fs.8
>> +++ b/man/resize.f2fs.8
>> @@ -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
>>
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> Linux-f2fs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
2025-04-16 3:33 ` Chao Yu via Linux-f2fs-devel
@ 2025-04-16 3:40 ` Juhyung Park
2025-04-16 5:51 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 5+ messages in thread
From: Juhyung Park @ 2025-04-16 3:40 UTC (permalink / raw)
To: Chao Yu; +Cc: uplinkr, jaegeuk, 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. :/
On Tue, Apr 15, 2025 at 8:34 PM Chao Yu <chao@kernel.org> wrote:
>
> On 4/16/25 03:28, Juhyung Park wrote:
> > 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,
>
> >
> > On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel
> > <linux-f2fs-devel@lists.sourceforge.net> wrote:
> >>
> >> 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.
> >>
> >> Signed-off-by: Chao Yu <chao@kernel.org>
> >> ---
> >> fsck/resize.c | 12 ++++++++----
> >> man/resize.f2fs.8 | 2 +-
> >> 2 files changed, 9 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/fsck/resize.c b/fsck/resize.c
> >> index 1ab7d75..58914ec 100644
> >> --- a/fsck/resize.c
> >> +++ b/fsck/resize.c
> >> @@ -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;
> >> }
> >> diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
> >> index bdda4fd..5b6daf5 100644
> >> --- a/man/resize.f2fs.8
> >> +++ b/man/resize.f2fs.8
> >> @@ -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
> >>
> >>
> >>
> >> _______________________________________________
> >> Linux-f2fs-devel mailing list
> >> Linux-f2fs-devel@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize
2025-04-16 3:40 ` Juhyung Park
@ 2025-04-16 5:51 ` Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-04-16 5:51 UTC (permalink / raw)
To: Juhyung Park; +Cc: uplinkr, jaegeuk, linux-f2fs-devel
On 4/16/25 11:40, Juhyung Park wrote:
> Just checked gparted's source code:
> https://github.com/GNOME/gparted/blob/GPARTED_1_7_0/src/f2fs.cc#L135
>
> Seems unlikely. :/
Alright, seems still we need another testcase for reproducing. :(
Thanks,
>
> On Tue, Apr 15, 2025 at 8:34 PM Chao Yu <chao@kernel.org> wrote:
>>
>> On 4/16/25 03:28, Juhyung Park wrote:
>>> 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,
>>
>>>
>>> On Mon, Apr 14, 2025 at 4:13 AM Chao Yu via Linux-f2fs-devel
>>> <linux-f2fs-devel@lists.sourceforge.net> wrote:
>>>>
>>>> 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.
>>>>
>>>> Signed-off-by: Chao Yu <chao@kernel.org>
>>>> ---
>>>> fsck/resize.c | 12 ++++++++----
>>>> man/resize.f2fs.8 | 2 +-
>>>> 2 files changed, 9 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/fsck/resize.c b/fsck/resize.c
>>>> index 1ab7d75..58914ec 100644
>>>> --- a/fsck/resize.c
>>>> +++ b/fsck/resize.c
>>>> @@ -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;
>>>> }
>>>> diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8
>>>> index bdda4fd..5b6daf5 100644
>>>> --- a/man/resize.f2fs.8
>>>> +++ b/man/resize.f2fs.8
>>>> @@ -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
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Linux-f2fs-devel mailing list
>>>> Linux-f2fs-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-16 5:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 11:11 [f2fs-dev] [PATCH] resize.f2fs: fix to always change metadata for expand resize Chao Yu via Linux-f2fs-devel
2025-04-15 19:28 ` Juhyung Park
2025-04-16 3:33 ` Chao Yu via Linux-f2fs-devel
2025-04-16 3:40 ` Juhyung Park
2025-04-16 5:51 ` Chao Yu via Linux-f2fs-devel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.