* [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision @ 2022-06-14 11:49 qixiaoyu1 2022-06-14 11:49 ` [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow qixiaoyu1 2022-06-19 0:01 ` [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision Chao Yu 0 siblings, 2 replies; 10+ messages in thread From: qixiaoyu1 @ 2022-06-14 11:49 UTC (permalink / raw) To: jaegeuk; +Cc: liuchao12, linux-kernel, linux-f2fs-devel From: liuchao12 <liuchao12@xiaomi.com> Make.f2fs supports manually specifying overprovision, and we expect resize.f2fs to support it as well. This change add a new '-o' option to manually specify overprovision. Signed-off-by: liuchao12 <liuchao12@xiaomi.com> --- fsck/main.c | 8 ++++++-- fsck/resize.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fsck/main.c b/fsck/main.c index aef797e..3b4da0f 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -121,7 +121,8 @@ void resize_usage() MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n"); - MSG(0, " -s safe resize (Does not resize metadata)"); + MSG(0, " -o overprovision percentage [default:auto]\n"); + MSG(0, " -s safe resize (Does not resize metadata)\n"); MSG(0, " -t target sectors [default: device size]\n"); MSG(0, " -V print the version number and exit\n"); exit(1); @@ -527,7 +528,7 @@ void f2fs_parse_options(int argc, char *argv[]) #endif } else if (!strcmp("resize.f2fs", prog)) { #ifdef WITH_RESIZE - const char *option_string = "d:fst:iV"; + const char *option_string = "d:fst:io:V"; c.func = RESIZE; while ((option = getopt(argc, argv, option_string)) != EOF) { @@ -561,6 +562,9 @@ void f2fs_parse_options(int argc, char *argv[]) case 'i': c.large_nat_bitmap = 1; break; + case 'o': + c.new_overprovision = atof(optarg); + break; case 'V': show_version(prog); exit(0); diff --git a/fsck/resize.c b/fsck/resize.c index f1b7701..d19c6fa 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -146,12 +146,15 @@ safe_resize: get_sb(segs_per_sec)); /* Let's determine the best reserved and overprovisioned space */ - c.new_overprovision = get_best_overprovision(sb); + if (c.new_overprovision == 0) + c.new_overprovision = get_best_overprovision(sb); + c.new_reserved_segments = (2 * (100 / c.new_overprovision + 1) + 6) * get_sb(segs_per_sec); - if ((get_sb(segment_count_main) - 2) < c.new_reserved_segments || + if (c.new_overprovision == 0 || + (get_sb(segment_count_main) - 2) < c.new_reserved_segments || get_sb(segment_count_main) * blks_per_seg > get_sb(block_count)) { MSG(0, "\tError: Device size is not sufficient for F2FS volume, " @@ -476,6 +479,11 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, set_cp(overprov_segment_count, get_cp(overprov_segment_count) + get_cp(rsvd_segment_count)); + DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision); + DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n", + get_cp(overprov_segment_count), + c.new_reserved_segments); + free_segment_count = get_free_segments(sbi); new_segment_count = get_newsb(segment_count_main) - get_sb(segment_count_main); -- 2.36.1 _______________________________________________ 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] 10+ messages in thread
* [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow 2022-06-14 11:49 [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision qixiaoyu1 @ 2022-06-14 11:49 ` qixiaoyu1 2022-06-19 0:10 ` Chao Yu 2022-06-19 0:01 ` [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision Chao Yu 1 sibling, 1 reply; 10+ messages in thread From: qixiaoyu1 @ 2022-06-14 11:49 UTC (permalink / raw) To: jaegeuk; +Cc: qixiaoyu1, linux-kernel, linux-f2fs-devel Otherwise, after grow, kernel may report below error message when we mount the image if -o parameter is specified during resize: F2FS-fs (loop0): invalid crc_offset: 0 F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 F2FS-fs (loop0): Failed to get valid F2FS checkpoint mount(2) system call failed: Structure needs cleaning. Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> --- fsck/resize.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/fsck/resize.c b/fsck/resize.c index d19c6fa..e135b66 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -599,6 +599,26 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, DBG(0, "Info: Done to rebuild checkpoint blocks\n"); } +static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block *new_sb) +{ + struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); + block_t user_block_count; + unsigned int overprov_segment_count; + + overprov_segment_count = (get_newsb(segment_count_main) - + c.new_reserved_segments) * + c.new_overprovision / 100; + overprov_segment_count += c.new_reserved_segments; + + user_block_count = (get_newsb(segment_count_main) - + overprov_segment_count) * c.blks_per_seg; + + if (get_cp(valid_block_count) > user_block_count) + return -1; + + return 0; +} + static int f2fs_resize_grow(struct f2fs_sb_info *sbi) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); @@ -616,6 +636,9 @@ static int f2fs_resize_grow(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; + if (f2fs_resize_check(sbi, new_sb) < 0) + return -1; + /* check nat availability */ if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) { err = shrink_nats(sbi, new_sb); @@ -659,11 +682,8 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct f2fs_super_block new_sb_raw; struct f2fs_super_block *new_sb = &new_sb_raw; - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); block_t old_end_blkaddr, old_main_blkaddr; block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr; - block_t user_block_count; - unsigned int overprov_segment_count; unsigned int offset; int err = -1; @@ -674,15 +694,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; - overprov_segment_count = (get_newsb(segment_count_main) - - c.new_reserved_segments) * - c.new_overprovision / 100; - overprov_segment_count += c.new_reserved_segments; - - user_block_count = (get_newsb(segment_count_main) - - overprov_segment_count) * c.blks_per_seg; - - if (get_cp(valid_block_count) > user_block_count) + if (f2fs_resize_check(sbi, new_sb) < 0) return -1; /* check nat availability */ -- 2.36.1 _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow 2022-06-14 11:49 ` [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow qixiaoyu1 @ 2022-06-19 0:10 ` Chao Yu 0 siblings, 0 replies; 10+ messages in thread From: Chao Yu @ 2022-06-19 0:10 UTC (permalink / raw) To: qixiaoyu1, jaegeuk; +Cc: qixiaoyu1, linux-kernel, linux-f2fs-devel On 2022/6/14 19:49, qixiaoyu1 wrote: > Otherwise, after grow, kernel may report below error message > when we mount the image if -o parameter is specified during resize: > > F2FS-fs (loop0): invalid crc_offset: 0 > F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 > F2FS-fs (loop0): Failed to get valid F2FS checkpoint > mount(2) system call failed: Structure needs cleaning. > > Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> It looks this patch should be merged into previous one, otherwise -o option support is broken for resize.f2fs. Thanks, > --- > fsck/resize.c | 36 ++++++++++++++++++++++++------------ > 1 file changed, 24 insertions(+), 12 deletions(-) > > diff --git a/fsck/resize.c b/fsck/resize.c > index d19c6fa..e135b66 100644 > --- a/fsck/resize.c > +++ b/fsck/resize.c > @@ -599,6 +599,26 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, > DBG(0, "Info: Done to rebuild checkpoint blocks\n"); > } > > +static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block *new_sb) > +{ > + struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > + block_t user_block_count; > + unsigned int overprov_segment_count; > + > + overprov_segment_count = (get_newsb(segment_count_main) - > + c.new_reserved_segments) * > + c.new_overprovision / 100; > + overprov_segment_count += c.new_reserved_segments; > + > + user_block_count = (get_newsb(segment_count_main) - > + overprov_segment_count) * c.blks_per_seg; > + > + if (get_cp(valid_block_count) > user_block_count) > + return -1; > + > + return 0; > +} > + > static int f2fs_resize_grow(struct f2fs_sb_info *sbi) > { > struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); > @@ -616,6 +636,9 @@ static int f2fs_resize_grow(struct f2fs_sb_info *sbi) > if (get_new_sb(new_sb)) > return -1; > > + if (f2fs_resize_check(sbi, new_sb) < 0) > + return -1; > + > /* check nat availability */ > if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) { > err = shrink_nats(sbi, new_sb); > @@ -659,11 +682,8 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) > struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); > struct f2fs_super_block new_sb_raw; > struct f2fs_super_block *new_sb = &new_sb_raw; > - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > block_t old_end_blkaddr, old_main_blkaddr; > block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr; > - block_t user_block_count; > - unsigned int overprov_segment_count; > unsigned int offset; > int err = -1; > > @@ -674,15 +694,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) > if (get_new_sb(new_sb)) > return -1; > > - overprov_segment_count = (get_newsb(segment_count_main) - > - c.new_reserved_segments) * > - c.new_overprovision / 100; > - overprov_segment_count += c.new_reserved_segments; > - > - user_block_count = (get_newsb(segment_count_main) - > - overprov_segment_count) * c.blks_per_seg; > - > - if (get_cp(valid_block_count) > user_block_count) > + if (f2fs_resize_check(sbi, new_sb) < 0) > return -1; > > /* check nat availability */ _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision 2022-06-14 11:49 [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision qixiaoyu1 2022-06-14 11:49 ` [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow qixiaoyu1 @ 2022-06-19 0:01 ` Chao Yu 2022-06-20 8:48 ` [f2fs-dev] [PATCH v2] " qixiaoyu1 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 1/2] " qixiaoyu1 1 sibling, 2 replies; 10+ messages in thread From: Chao Yu @ 2022-06-19 0:01 UTC (permalink / raw) To: qixiaoyu1, jaegeuk; +Cc: liuchao12, linux-kernel, linux-f2fs-devel On 2022/6/14 19:49, qixiaoyu1 wrote: > From: liuchao12 <liuchao12@xiaomi.com> > > Make.f2fs supports manually specifying overprovision, and we expect > resize.f2fs to support it as well. > > This change add a new '-o' option to manually specify overprovision. > > Signed-off-by: liuchao12 <liuchao12@xiaomi.com> > --- > fsck/main.c | 8 ++++++-- > fsck/resize.c | 12 ++++++++++-- > 2 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/fsck/main.c b/fsck/main.c > index aef797e..3b4da0f 100644 > --- a/fsck/main.c > +++ b/fsck/main.c > @@ -121,7 +121,8 @@ void resize_usage() > MSG(0, "[options]:\n"); > MSG(0, " -d debug level [default:0]\n"); > MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n"); > - MSG(0, " -s safe resize (Does not resize metadata)"); > + MSG(0, " -o overprovision percentage [default:auto]\n"); Should update manual as well? > + MSG(0, " -s safe resize (Does not resize metadata)\n"); > MSG(0, " -t target sectors [default: device size]\n"); > MSG(0, " -V print the version number and exit\n"); > exit(1); > @@ -527,7 +528,7 @@ void f2fs_parse_options(int argc, char *argv[]) > #endif > } else if (!strcmp("resize.f2fs", prog)) { > #ifdef WITH_RESIZE > - const char *option_string = "d:fst:iV"; > + const char *option_string = "d:fst:io:V"; > > c.func = RESIZE; > while ((option = getopt(argc, argv, option_string)) != EOF) { > @@ -561,6 +562,9 @@ void f2fs_parse_options(int argc, char *argv[]) > case 'i': > c.large_nat_bitmap = 1; > break; > + case 'o': > + c.new_overprovision = atof(optarg); > + break; > case 'V': > show_version(prog); > exit(0); > diff --git a/fsck/resize.c b/fsck/resize.c > index f1b7701..d19c6fa 100644 > --- a/fsck/resize.c > +++ b/fsck/resize.c > @@ -146,12 +146,15 @@ safe_resize: > get_sb(segs_per_sec)); > > /* Let's determine the best reserved and overprovisioned space */ > - c.new_overprovision = get_best_overprovision(sb); > + if (c.new_overprovision == 0) > + c.new_overprovision = get_best_overprovision(sb); > + > c.new_reserved_segments = > (2 * (100 / c.new_overprovision + 1) + 6) * > get_sb(segs_per_sec); > > - if ((get_sb(segment_count_main) - 2) < c.new_reserved_segments || > + if (c.new_overprovision == 0 || Should never be zero here? Otherwise above "100 / c.new_overprovision" calculation will cause arithmetic exception. Thanks, > + (get_sb(segment_count_main) - 2) < c.new_reserved_segments || > get_sb(segment_count_main) * blks_per_seg > > get_sb(block_count)) { > MSG(0, "\tError: Device size is not sufficient for F2FS volume, " > @@ -476,6 +479,11 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, > set_cp(overprov_segment_count, get_cp(overprov_segment_count) + > get_cp(rsvd_segment_count)); > > + DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision); > + DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n", > + get_cp(overprov_segment_count), > + c.new_reserved_segments); > + > free_segment_count = get_free_segments(sbi); > new_segment_count = get_newsb(segment_count_main) - > get_sb(segment_count_main); _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH v2] resize.f2fs: add option to manually specify new overprovision 2022-06-19 0:01 ` [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision Chao Yu @ 2022-06-20 8:48 ` qixiaoyu1 2022-06-22 13:19 ` Chao Yu 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 1/2] " qixiaoyu1 1 sibling, 1 reply; 10+ messages in thread From: qixiaoyu1 @ 2022-06-20 8:48 UTC (permalink / raw) To: Chao Yu; +Cc: qixiaoyu1, linux-kernel, linux-f2fs-devel, Jaegeuk Kim, liuchao12 From: liuchao12 <liuchao12@xiaomi.com> Make.f2fs supports manually specifying overprovision, and we expect resize.f2fs to support it as well. This change add a new '-o' option to manually specify overprovision, and fix to check free space before grow. Otherwise, after grow, kernel may report below error message when we mount the image if -o parameter is specified during resize: F2FS-fs (loop0): invalid crc_offset: 0 F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 F2FS-fs (loop0): Failed to get valid F2FS checkpoint mount(2) system call failed: Structure needs cleaning. Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> --- Change log form v1: - merged fix to check free space before grow - delete unessassary check of "c.new_overprovision == 0" - update man page fsck/main.c | 8 ++++++-- fsck/resize.c | 45 ++++++++++++++++++++++++++++++++------------- man/resize.f2fs.8 | 9 +++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/fsck/main.c b/fsck/main.c index aef797e..3b4da0f 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -121,7 +121,8 @@ void resize_usage() MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n"); - MSG(0, " -s safe resize (Does not resize metadata)"); + MSG(0, " -o overprovision percentage [default:auto]\n"); + MSG(0, " -s safe resize (Does not resize metadata)\n"); MSG(0, " -t target sectors [default: device size]\n"); MSG(0, " -V print the version number and exit\n"); exit(1); @@ -527,7 +528,7 @@ void f2fs_parse_options(int argc, char *argv[]) #endif } else if (!strcmp("resize.f2fs", prog)) { #ifdef WITH_RESIZE - const char *option_string = "d:fst:iV"; + const char *option_string = "d:fst:io:V"; c.func = RESIZE; while ((option = getopt(argc, argv, option_string)) != EOF) { @@ -561,6 +562,9 @@ void f2fs_parse_options(int argc, char *argv[]) case 'i': c.large_nat_bitmap = 1; break; + case 'o': + c.new_overprovision = atof(optarg); + break; case 'V': show_version(prog); exit(0); diff --git a/fsck/resize.c b/fsck/resize.c index f1b7701..3d8ea46 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -146,7 +146,9 @@ safe_resize: get_sb(segs_per_sec)); /* Let's determine the best reserved and overprovisioned space */ - c.new_overprovision = get_best_overprovision(sb); + if (c.new_overprovision == 0) + c.new_overprovision = get_best_overprovision(sb); + c.new_reserved_segments = (2 * (100 / c.new_overprovision + 1) + 6) * get_sb(segs_per_sec); @@ -476,6 +478,11 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, set_cp(overprov_segment_count, get_cp(overprov_segment_count) + get_cp(rsvd_segment_count)); + DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision); + DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n", + get_cp(overprov_segment_count), + c.new_reserved_segments); + free_segment_count = get_free_segments(sbi); new_segment_count = get_newsb(segment_count_main) - get_sb(segment_count_main); @@ -591,6 +598,26 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, DBG(0, "Info: Done to rebuild checkpoint blocks\n"); } +static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block *new_sb) +{ + struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); + block_t user_block_count; + unsigned int overprov_segment_count; + + overprov_segment_count = (get_newsb(segment_count_main) - + c.new_reserved_segments) * + c.new_overprovision / 100; + overprov_segment_count += c.new_reserved_segments; + + user_block_count = (get_newsb(segment_count_main) - + overprov_segment_count) * c.blks_per_seg; + + if (get_cp(valid_block_count) > user_block_count) + return -1; + + return 0; +} + static int f2fs_resize_grow(struct f2fs_sb_info *sbi) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); @@ -608,6 +635,9 @@ static int f2fs_resize_grow(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; + if (f2fs_resize_check(sbi, new_sb) < 0) + return -1; + /* check nat availability */ if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) { err = shrink_nats(sbi, new_sb); @@ -651,11 +681,8 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct f2fs_super_block new_sb_raw; struct f2fs_super_block *new_sb = &new_sb_raw; - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); block_t old_end_blkaddr, old_main_blkaddr; block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr; - block_t user_block_count; - unsigned int overprov_segment_count; unsigned int offset; int err = -1; @@ -666,15 +693,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; - overprov_segment_count = (get_newsb(segment_count_main) - - c.new_reserved_segments) * - c.new_overprovision / 100; - overprov_segment_count += c.new_reserved_segments; - - user_block_count = (get_newsb(segment_count_main) - - overprov_segment_count) * c.blks_per_seg; - - if (get_cp(valid_block_count) > user_block_count) + if (f2fs_resize_check(sbi, new_sb) < 0) return -1; /* check nat availability */ diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8 index 463eca5..a4b6cd7 100644 --- a/man/resize.f2fs.8 +++ b/man/resize.f2fs.8 @@ -13,6 +13,10 @@ resize.f2fs \- resize filesystem size .B \-d .I debugging-level ] +[ +.B \-o +.I overprovision-ratio-percentage +] .I device .SH DESCRIPTION .B resize.f2fs @@ -35,6 +39,11 @@ Specify the size in sectors. Specify the level of debugging options. The default number is 0, which shows basic debugging messages. .TP +.BI \-o " overprovision-ratio-percentage" +Specify the percentage of the volume that will be used as overprovision area. +This area is hidden to users, and utilized by F2FS cleaner. If not specified, the +best number will be assigned automatically according to the partition size. +.TP .SH AUTHOR This version of .B resize.f2fs -- 2.36.1 _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH v2] resize.f2fs: add option to manually specify new overprovision 2022-06-20 8:48 ` [f2fs-dev] [PATCH v2] " qixiaoyu1 @ 2022-06-22 13:19 ` Chao Yu 0 siblings, 0 replies; 10+ messages in thread From: Chao Yu @ 2022-06-22 13:19 UTC (permalink / raw) To: qixiaoyu1 Cc: qixiaoyu1, Jaegeuk Kim, liuchao12, linux-kernel, linux-f2fs-devel On 2022/6/20 16:48, qixiaoyu1 wrote: > From: liuchao12 <liuchao12@xiaomi.com> > > Make.f2fs supports manually specifying overprovision, and we expect > resize.f2fs to support it as well. > > This change add a new '-o' option to manually specify overprovision, > and fix to check free space before grow. Otherwise, after grow, > kernel may report below error message when we mount the image if -o > parameter is specified during resize: > > F2FS-fs (loop0): invalid crc_offset: 0 > F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 > F2FS-fs (loop0): Failed to get valid F2FS checkpoint > mount(2) system call failed: Structure needs cleaning. > > Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, _______________________________________________ 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] 10+ messages in thread
* [f2fs-dev] [PATCH v3 1/2] resize.f2fs: add option to manually specify new overprovision 2022-06-19 0:01 ` [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision Chao Yu 2022-06-20 8:48 ` [f2fs-dev] [PATCH v2] " qixiaoyu1 @ 2022-06-20 11:56 ` qixiaoyu1 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V qixiaoyu1 1 sibling, 1 reply; 10+ messages in thread From: qixiaoyu1 @ 2022-06-20 11:56 UTC (permalink / raw) To: Chao Yu; +Cc: qixiaoyu1, linux-kernel, linux-f2fs-devel, Jaegeuk Kim, liuchao12 From: liuchao12 <liuchao12@xiaomi.com> Make.f2fs supports manually specifying overprovision, and we expect resize.f2fs to support it as well. This change add a new '-o' option to manually specify overprovision, and fix to check free space before grow. Otherwise, after grow, kernel may report below error message when we mount the image if -o parameter is specified during resize: F2FS-fs (loop0): invalid crc_offset: 0 F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 F2FS-fs (loop0): Failed to get valid F2FS checkpoint mount(2) system call failed: Structure needs cleaning. Signed-off-by: liuchao12 <liuchao12@xiaomi.com> Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> --- Change log from v2: - Sorry for miss liuchao12 mistakenly when merge the two patches... Change log from v1: - merged fix to check free space before grow - delete unessassary check of "c.new_overprovision == 0" - update man page fsck/main.c | 8 ++++++-- fsck/resize.c | 45 ++++++++++++++++++++++++++++++++------------- man/resize.f2fs.8 | 9 +++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/fsck/main.c b/fsck/main.c index aef797e..3b4da0f 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -121,7 +121,8 @@ void resize_usage() MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n"); - MSG(0, " -s safe resize (Does not resize metadata)"); + MSG(0, " -o overprovision percentage [default:auto]\n"); + MSG(0, " -s safe resize (Does not resize metadata)\n"); MSG(0, " -t target sectors [default: device size]\n"); MSG(0, " -V print the version number and exit\n"); exit(1); @@ -527,7 +528,7 @@ void f2fs_parse_options(int argc, char *argv[]) #endif } else if (!strcmp("resize.f2fs", prog)) { #ifdef WITH_RESIZE - const char *option_string = "d:fst:iV"; + const char *option_string = "d:fst:io:V"; c.func = RESIZE; while ((option = getopt(argc, argv, option_string)) != EOF) { @@ -561,6 +562,9 @@ void f2fs_parse_options(int argc, char *argv[]) case 'i': c.large_nat_bitmap = 1; break; + case 'o': + c.new_overprovision = atof(optarg); + break; case 'V': show_version(prog); exit(0); diff --git a/fsck/resize.c b/fsck/resize.c index f1b7701..3d8ea46 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -146,7 +146,9 @@ safe_resize: get_sb(segs_per_sec)); /* Let's determine the best reserved and overprovisioned space */ - c.new_overprovision = get_best_overprovision(sb); + if (c.new_overprovision == 0) + c.new_overprovision = get_best_overprovision(sb); + c.new_reserved_segments = (2 * (100 / c.new_overprovision + 1) + 6) * get_sb(segs_per_sec); @@ -476,6 +478,11 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, set_cp(overprov_segment_count, get_cp(overprov_segment_count) + get_cp(rsvd_segment_count)); + DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision); + DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n", + get_cp(overprov_segment_count), + c.new_reserved_segments); + free_segment_count = get_free_segments(sbi); new_segment_count = get_newsb(segment_count_main) - get_sb(segment_count_main); @@ -591,6 +598,26 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, DBG(0, "Info: Done to rebuild checkpoint blocks\n"); } +static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block *new_sb) +{ + struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); + block_t user_block_count; + unsigned int overprov_segment_count; + + overprov_segment_count = (get_newsb(segment_count_main) - + c.new_reserved_segments) * + c.new_overprovision / 100; + overprov_segment_count += c.new_reserved_segments; + + user_block_count = (get_newsb(segment_count_main) - + overprov_segment_count) * c.blks_per_seg; + + if (get_cp(valid_block_count) > user_block_count) + return -1; + + return 0; +} + static int f2fs_resize_grow(struct f2fs_sb_info *sbi) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); @@ -608,6 +635,9 @@ static int f2fs_resize_grow(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; + if (f2fs_resize_check(sbi, new_sb) < 0) + return -1; + /* check nat availability */ if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) { err = shrink_nats(sbi, new_sb); @@ -651,11 +681,8 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct f2fs_super_block new_sb_raw; struct f2fs_super_block *new_sb = &new_sb_raw; - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); block_t old_end_blkaddr, old_main_blkaddr; block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr; - block_t user_block_count; - unsigned int overprov_segment_count; unsigned int offset; int err = -1; @@ -666,15 +693,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) if (get_new_sb(new_sb)) return -1; - overprov_segment_count = (get_newsb(segment_count_main) - - c.new_reserved_segments) * - c.new_overprovision / 100; - overprov_segment_count += c.new_reserved_segments; - - user_block_count = (get_newsb(segment_count_main) - - overprov_segment_count) * c.blks_per_seg; - - if (get_cp(valid_block_count) > user_block_count) + if (f2fs_resize_check(sbi, new_sb) < 0) return -1; /* check nat availability */ diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8 index 463eca5..a4b6cd7 100644 --- a/man/resize.f2fs.8 +++ b/man/resize.f2fs.8 @@ -13,6 +13,10 @@ resize.f2fs \- resize filesystem size .B \-d .I debugging-level ] +[ +.B \-o +.I overprovision-ratio-percentage +] .I device .SH DESCRIPTION .B resize.f2fs @@ -35,6 +39,11 @@ Specify the size in sectors. Specify the level of debugging options. The default number is 0, which shows basic debugging messages. .TP +.BI \-o " overprovision-ratio-percentage" +Specify the percentage of the volume that will be used as overprovision area. +This area is hidden to users, and utilized by F2FS cleaner. If not specified, the +best number will be assigned automatically according to the partition size. +.TP .SH AUTHOR This version of .B resize.f2fs -- 2.36.1 _______________________________________________ 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] 10+ messages in thread
* [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 1/2] " qixiaoyu1 @ 2022-06-20 11:56 ` qixiaoyu1 2022-06-22 13:21 ` Chao Yu 0 siblings, 1 reply; 10+ messages in thread From: qixiaoyu1 @ 2022-06-20 11:56 UTC (permalink / raw) To: Chao Yu; +Cc: qixiaoyu1, linux-kernel, linux-f2fs-devel, Jaegeuk Kim, liuchao12 Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> --- man/resize.f2fs.8 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/man/resize.f2fs.8 b/man/resize.f2fs.8 index a4b6cd7..3288760 100644 --- a/man/resize.f2fs.8 +++ b/man/resize.f2fs.8 @@ -17,6 +17,15 @@ resize.f2fs \- resize filesystem size .B \-o .I overprovision-ratio-percentage ] +[ +.B \-i +] +[ +.B \-s +] +[ +.B \-V +] .I device .SH DESCRIPTION .B resize.f2fs @@ -44,6 +53,15 @@ Specify the percentage of the volume that will be used as overprovision area. This area is hidden to users, and utilized by F2FS cleaner. If not specified, the best number will be assigned automatically according to the partition size. .TP +.BI \-i +Enable extended node bitmap. +.TP +.BI \-s +Enable safe resize. +.TP +.BI \-V +Print the version number and exit. +.TP .SH AUTHOR This version of .B resize.f2fs -- 2.36.1 _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V qixiaoyu1 @ 2022-06-22 13:21 ` Chao Yu 2022-06-22 18:31 ` Jaegeuk Kim 0 siblings, 1 reply; 10+ messages in thread From: Chao Yu @ 2022-06-22 13:21 UTC (permalink / raw) To: qixiaoyu1 Cc: qixiaoyu1, Jaegeuk Kim, liuchao12, linux-kernel, linux-f2fs-devel On 2022/6/20 19:56, qixiaoyu1 wrote: > Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, _______________________________________________ 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] 10+ messages in thread
* Re: [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V 2022-06-22 13:21 ` Chao Yu @ 2022-06-22 18:31 ` Jaegeuk Kim 0 siblings, 0 replies; 10+ messages in thread From: Jaegeuk Kim @ 2022-06-22 18:31 UTC (permalink / raw) To: Chao Yu; +Cc: qixiaoyu1, liuchao12, linux-kernel, linux-f2fs-devel Thanks, I combined two patches into one. On 06/22, Chao Yu wrote: > On 2022/6/20 19:56, qixiaoyu1 wrote: > > Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com> > > Reviewed-by: Chao Yu <chao@kernel.org> > > Thanks, _______________________________________________ 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] 10+ messages in thread
end of thread, other threads:[~2022-06-22 18:31 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-06-14 11:49 [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision qixiaoyu1 2022-06-14 11:49 ` [f2fs-dev] [PATCH 2/2] f2fs-tools: fix to check free space before grow qixiaoyu1 2022-06-19 0:10 ` Chao Yu 2022-06-19 0:01 ` [f2fs-dev] [PATCH 1/2] resize.f2fs: add option to manually specify new overprovision Chao Yu 2022-06-20 8:48 ` [f2fs-dev] [PATCH v2] " qixiaoyu1 2022-06-22 13:19 ` Chao Yu 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 1/2] " qixiaoyu1 2022-06-20 11:56 ` [f2fs-dev] [PATCH v3 2/2] resize.f2fs: update man page for options -i, -s and -V qixiaoyu1 2022-06-22 13:21 ` Chao Yu 2022-06-22 18:31 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).