From: "Darrick J. Wong" <djwong@xxxxxxxxxx> Add a new mkfs option that allows the user to specify an extent size hint with units. This removes the need to specify the option in filesystem block size, which eases the computation requirements in deployment scripts. # mkfs.xfs -d extsize=2m /dev/sda Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: John Garry <john.g.garry@xxxxxxxxxx> --- man/man8/mkfs.xfs.8.in | 15 +++++++++++++ mkfs/xfs_mkfs.c | 48 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in index 08bb92f6522d..9742482dcee9 100644 --- a/man/man8/mkfs.xfs.8.in +++ b/man/man8/mkfs.xfs.8.in @@ -482,6 +482,18 @@ will be assigned the project quota id provided in Directories will pass on the project id to newly created regular files and directories. .TP +.BI extsize= num +All inodes created by +.B mkfs.xfs +will have this +.I value +extent size hint applied. +Directories will pass on this hint to newly created regular files and +directories. +This option cannot be combined with the +.B extszinherit +option. +.TP .BI extszinherit= value All inodes created by .B mkfs.xfs @@ -491,6 +503,9 @@ extent size hint applied. The value must be provided in units of filesystem blocks. Directories will pass on this hint to newly created regular files and directories. +This option cannot be combined with the +.B extsize +option. .TP .BI daxinherit= value If diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index d3a15cf44e00..bffe0b7ea8b0 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -74,6 +74,7 @@ enum { D_NOALIGN, D_RTINHERIT, D_PROJINHERIT, + D_EXTSIZE, D_EXTSZINHERIT, D_COWEXTSIZE, D_DAXINHERIT, @@ -315,6 +316,7 @@ static struct opt_params dopts = { [D_NOALIGN] = "noalign", [D_RTINHERIT] = "rtinherit", [D_PROJINHERIT] = "projinherit", + [D_EXTSIZE] = "extsize", [D_EXTSZINHERIT] = "extszinherit", [D_COWEXTSIZE] = "cowextsize", [D_DAXINHERIT] = "daxinherit", @@ -422,8 +424,17 @@ static struct opt_params dopts = { .maxval = UINT_MAX, .defaultval = SUBOPT_NEEDS_VAL, }, + { .index = D_EXTSIZE, + .conflicts = { { &dopts, D_EXTSZINHERIT }, + { NULL, LAST_CONFLICT } }, + .convert = true, + .minval = 0, + .maxval = XFS_AG_MAX_BYTES, + .defaultval = SUBOPT_NEEDS_VAL, + }, { .index = D_EXTSZINHERIT, - .conflicts = { { NULL, LAST_CONFLICT } }, + .conflicts = { { &dopts, D_EXTSIZE }, + { NULL, LAST_CONFLICT } }, .minval = 0, .maxval = UINT_MAX, .defaultval = SUBOPT_NEEDS_VAL, @@ -881,6 +892,7 @@ struct cli_params { char *lsu; char *rtextsize; char *rtsize; + char *extsize; /* parameters where 0 is a valid CLI value */ int dsunit; @@ -993,7 +1005,7 @@ usage( void ) inobtcount=0|1,bigtime=0|1]\n\ /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\ (sunit=value,swidth=value|su=num,sw=num|noalign),\n\ - sectsize=num\n\ + sectsize=num,extsize=num\n\ /* force overwrite */ [-f]\n\ /* inode size */ [-i perblock=n|size=num,maxpct=n,attr=0|1|2,\n\ projid32bit=0|1,sparse=0|1,nrext64=0|1]\n\ @@ -1601,6 +1613,9 @@ data_opts_parser( cli->fsx.fsx_projid = getnum(value, opts, subopt); cli->fsx.fsx_xflags |= FS_XFLAG_PROJINHERIT; break; + case D_EXTSIZE: + cli->extsize = getstr(value, opts, subopt); + break; case D_EXTSZINHERIT: cli->fsx.fsx_extsize = getnum(value, opts, subopt); if (cli->fsx.fsx_extsize) @@ -2084,6 +2099,33 @@ _("Minimum block size for CRC enabled filesystems is %d bytes.\n"), } +/* + * Convert the -d extsize= option to a number, then set the extent size hint + * to that number. + */ +static void +set_extsize( + struct cli_params *cli, + char *extsize, + struct opt_params *opts, + int subopt) +{ + uint64_t extsz_bytes; + if (!extsize) + return; + + extsz_bytes = getnum(extsize, opts, subopt); + if (extsz_bytes % blocksize) + illegal_option(extsize, opts, subopt, + _("Value must be a multiple of block size.")); + + cli->fsx.fsx_extsize = extsz_bytes / blocksize; + if (cli->fsx.fsx_extsize) + cli->fsx.fsx_xflags |= FS_XFLAG_EXTSZINHERIT; + else + cli->fsx.fsx_xflags &= ~FS_XFLAG_EXTSZINHERIT; +} + /* * Grab log sector size and validate. * @@ -4251,6 +4293,8 @@ main( blocksize = cfg.blocksize; sectorsize = cfg.sectorsize; + set_extsize(&cli, cli.extsize, &dopts, D_EXTSIZE); + validate_log_sectorsize(&cfg, &cli, &dft); validate_sb_features(&cfg, &cli); -- 2.34.1