diff mbox series

[v3] mkfs: fix the issue of maxpct set to 0 not taking effect

Message ID 20250411071203.10598-1-liuhuan01@kylinos.cn (mailing list archive)
State New
Headers show
Series [v3] mkfs: fix the issue of maxpct set to 0 not taking effect | expand

Commit Message

liuh April 11, 2025, 7:12 a.m. UTC
From: liuh <liuhuan01@kylinos.cn>

If a filesystem has the sb_imax_pct field set to zero, there is no limit to the number of inode blocks in the filesystem.

However, when using mkfs.xfs and specifying maxpct = 0, the result is not as expected.
	[root@fs ~]# mkfs.xfs -f -i maxpct=0 xfs.img
	data     =               bsize=4096   blocks=262144, imaxpct=25
	         =               sunit=0      swidth=0 blks

The reason is that the condition will never succeed when specifying maxpct = 0. As a result, the default algorithm was applied.
	cfg->imaxpct = cli->imaxpct;
	if (cfg->imaxpct)
		return;

The result with patch:
	[root@fs ~]# mkfs.xfs -f -i maxpct=0 xfs.img
	data     =               bsize=4096   blocks=262144, imaxpct=0
	         =               sunit=0      swidth=0 blks

	[root@fs ~]# mkfs.xfs -f xfs.img
	data     =               bsize=4096   blocks=262144, imaxpct=25
	         =               sunit=0      swidth=0 blks

Cc: <linux-xfs@vger.kernel.org> # v4.15.0
Fixes: d7240c965389e1 ("mkfs: rework imaxpct calculation")
Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: liuh <liuhuan01@kylinos.cn>
---
 mkfs/xfs_mkfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Darrick J. Wong April 11, 2025, 3:39 p.m. UTC | #1
On Fri, Apr 11, 2025 at 03:12:03PM +0800, liuhuan01@kylinos.cn wrote:
> From: liuh <liuhuan01@kylinos.cn>
> 
> If a filesystem has the sb_imax_pct field set to zero, there is no limit to the number of inode blocks in the filesystem.
> 
> However, when using mkfs.xfs and specifying maxpct = 0, the result is not as expected.
> 	[root@fs ~]# mkfs.xfs -f -i maxpct=0 xfs.img
> 	data     =               bsize=4096   blocks=262144, imaxpct=25
> 	         =               sunit=0      swidth=0 blks
> 
> The reason is that the condition will never succeed when specifying maxpct = 0. As a result, the default algorithm was applied.
> 	cfg->imaxpct = cli->imaxpct;
> 	if (cfg->imaxpct)
> 		return;
> 
> The result with patch:
> 	[root@fs ~]# mkfs.xfs -f -i maxpct=0 xfs.img
> 	data     =               bsize=4096   blocks=262144, imaxpct=0
> 	         =               sunit=0      swidth=0 blks
> 
> 	[root@fs ~]# mkfs.xfs -f xfs.img
> 	data     =               bsize=4096   blocks=262144, imaxpct=25
> 	         =               sunit=0      swidth=0 blks
> 
> Cc: <linux-xfs@vger.kernel.org> # v4.15.0
> Fixes: d7240c965389e1 ("mkfs: rework imaxpct calculation")
> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: liuh <liuhuan01@kylinos.cn>

Looks good to me,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  mkfs/xfs_mkfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 3f4455d4..25bed4eb 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -1048,13 +1048,13 @@ struct cli_params {
>  	int	data_concurrency;
>  	int	log_concurrency;
>  	int	rtvol_concurrency;
> +	int	imaxpct;
>  
>  	/* parameters where 0 is not a valid value */
>  	int64_t	agcount;
>  	int64_t	rgcount;
>  	int	inodesize;
>  	int	inopblock;
> -	int	imaxpct;
>  	int	lsectorsize;
>  	uuid_t	uuid;
>  
> @@ -4048,9 +4048,10 @@ calculate_imaxpct(
>  	struct mkfs_params	*cfg,
>  	struct cli_params	*cli)
>  {
> -	cfg->imaxpct = cli->imaxpct;
> -	if (cfg->imaxpct)
> +	if (cli->imaxpct >= 0) {
> +		cfg->imaxpct = cli->imaxpct;
>  		return;
> +	}
>  
>  	/*
>  	 * This returns the % of the disk space that is used for
> @@ -5181,6 +5182,7 @@ main(
>  		.log_concurrency = -1, /* auto detect non-mechanical ddev */
>  		.rtvol_concurrency = -1, /* auto detect non-mechanical rtdev */
>  		.autofsck = FSPROP_AUTOFSCK_UNSET,
> +		.imaxpct = -1, /* set sb_imax_pct automatically */
>  	};
>  	struct mkfs_params	cfg = {};
>  
> -- 
> 2.43.0
>
diff mbox series

Patch

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 3f4455d4..25bed4eb 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1048,13 +1048,13 @@  struct cli_params {
 	int	data_concurrency;
 	int	log_concurrency;
 	int	rtvol_concurrency;
+	int	imaxpct;
 
 	/* parameters where 0 is not a valid value */
 	int64_t	agcount;
 	int64_t	rgcount;
 	int	inodesize;
 	int	inopblock;
-	int	imaxpct;
 	int	lsectorsize;
 	uuid_t	uuid;
 
@@ -4048,9 +4048,10 @@  calculate_imaxpct(
 	struct mkfs_params	*cfg,
 	struct cli_params	*cli)
 {
-	cfg->imaxpct = cli->imaxpct;
-	if (cfg->imaxpct)
+	if (cli->imaxpct >= 0) {
+		cfg->imaxpct = cli->imaxpct;
 		return;
+	}
 
 	/*
 	 * This returns the % of the disk space that is used for
@@ -5181,6 +5182,7 @@  main(
 		.log_concurrency = -1, /* auto detect non-mechanical ddev */
 		.rtvol_concurrency = -1, /* auto detect non-mechanical rtdev */
 		.autofsck = FSPROP_AUTOFSCK_UNSET,
+		.imaxpct = -1, /* set sb_imax_pct automatically */
 	};
 	struct mkfs_params	cfg = {};