mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 01:59:54 +00:00
resize.f2fs: add option to manually specify new overprovision
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> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Change-Id: I2ad0ecc5546a1712b7aa36230e91c3e0b1beb7e0
This commit is contained in:
parent
6efa2e5836
commit
9401f8f0eb
@ -122,7 +122,8 @@ void resize_usage()
|
|||||||
MSG(0, "[options]:\n");
|
MSG(0, "[options]:\n");
|
||||||
MSG(0, " -d debug level [default:0]\n");
|
MSG(0, " -d debug level [default:0]\n");
|
||||||
MSG(0, " -i extended node bitmap, node ratio is 20%% by default\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, " -t target sectors [default: device size]\n");
|
||||||
MSG(0, " -O feature1[,feature2,...] e.g. \"fsprojquota,fscasefold\"\n");
|
MSG(0, " -O feature1[,feature2,...] e.g. \"fsprojquota,fscasefold\"\n");
|
||||||
MSG(0, " -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
|
MSG(0, " -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
|
||||||
@ -539,7 +540,7 @@ void f2fs_parse_options(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
} else if (!strcmp("resize.f2fs", prog)) {
|
} else if (!strcmp("resize.f2fs", prog)) {
|
||||||
#ifdef WITH_RESIZE
|
#ifdef WITH_RESIZE
|
||||||
const char *option_string = "d:fst:O:C:iV";
|
const char *option_string = "d:fst:O:C:io:V";
|
||||||
int val;
|
int val;
|
||||||
char *token;
|
char *token;
|
||||||
|
|
||||||
@ -592,6 +593,8 @@ void f2fs_parse_options(int argc, char *argv[])
|
|||||||
MSG(0, "\tError: Unknown flag %s\n",token);
|
MSG(0, "\tError: Unknown flag %s\n",token);
|
||||||
}
|
}
|
||||||
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
|
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
|
||||||
|
case 'o':
|
||||||
|
c.new_overprovision = atof(optarg);
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
show_version(prog);
|
show_version(prog);
|
||||||
|
@ -146,7 +146,9 @@ safe_resize:
|
|||||||
get_sb(segs_per_sec));
|
get_sb(segs_per_sec));
|
||||||
|
|
||||||
/* Let's determine the best reserved and overprovisioned space */
|
/* 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 =
|
c.new_reserved_segments =
|
||||||
(2 * (100 / c.new_overprovision + 1) + 6) *
|
(2 * (100 / c.new_overprovision + 1) + 6) *
|
||||||
get_sb(segs_per_sec);
|
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) +
|
set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
|
||||||
get_cp(rsvd_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);
|
free_segment_count = get_free_segments(sbi);
|
||||||
new_segment_count = get_newsb(segment_count_main) -
|
new_segment_count = get_newsb(segment_count_main) -
|
||||||
get_sb(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");
|
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)
|
static int f2fs_resize_grow(struct f2fs_sb_info *sbi)
|
||||||
{
|
{
|
||||||
struct f2fs_super_block *sb = F2FS_RAW_SUPER(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))
|
if (get_new_sb(new_sb))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (f2fs_resize_check(sbi, new_sb) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* check nat availability */
|
/* check nat availability */
|
||||||
if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) {
|
if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) {
|
||||||
err = shrink_nats(sbi, new_sb);
|
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 *sb = F2FS_RAW_SUPER(sbi);
|
||||||
struct f2fs_super_block new_sb_raw;
|
struct f2fs_super_block new_sb_raw;
|
||||||
struct f2fs_super_block *new_sb = &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 old_end_blkaddr, old_main_blkaddr;
|
||||||
block_t new_end_blkaddr, new_main_blkaddr, tmp_end_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;
|
unsigned int offset;
|
||||||
int err = -1;
|
int err = -1;
|
||||||
|
|
||||||
@ -666,15 +693,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi)
|
|||||||
if (get_new_sb(new_sb))
|
if (get_new_sb(new_sb))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
overprov_segment_count = (get_newsb(segment_count_main) -
|
if (f2fs_resize_check(sbi, new_sb) < 0)
|
||||||
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 -1;
|
||||||
|
|
||||||
/* check nat availability */
|
/* check nat availability */
|
||||||
|
@ -13,6 +13,19 @@ resize.f2fs \- resize filesystem size
|
|||||||
.B \-d
|
.B \-d
|
||||||
.I debugging-level
|
.I debugging-level
|
||||||
]
|
]
|
||||||
|
[
|
||||||
|
.B \-o
|
||||||
|
.I overprovision-ratio-percentage
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.B \-i
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.B \-s
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.B \-V
|
||||||
|
]
|
||||||
.I device
|
.I device
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B resize.f2fs
|
.B resize.f2fs
|
||||||
@ -35,6 +48,20 @@ Specify the size in sectors.
|
|||||||
Specify the level of debugging options.
|
Specify the level of debugging options.
|
||||||
The default number is 0, which shows basic debugging messages.
|
The default number is 0, which shows basic debugging messages.
|
||||||
.TP
|
.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
|
||||||
|
.BI \-i
|
||||||
|
Enable extended node bitmap.
|
||||||
|
.TP
|
||||||
|
.BI \-s
|
||||||
|
Enable safe resize.
|
||||||
|
.TP
|
||||||
|
.BI \-V
|
||||||
|
Print the version number and exit.
|
||||||
|
.TP
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
This version of
|
This version of
|
||||||
.B resize.f2fs
|
.B resize.f2fs
|
||||||
|
Loading…
Reference in New Issue
Block a user