lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241216130551.811305-3-txpeng@tencent.com>
Date: Mon, 16 Dec 2024 21:05:49 +0800
From: Tianxiang Peng <luminosity1999@...il.com>
To: chandan.babu@...cle.com,
	djwong@...nel.org,
	p.raghav@...sung.com,
	mcgrof@...nel.org,
	brauner@...nel.org,
	dchinner@...hat.com
Cc: Tianxiang Peng <txpeng@...cent.com>,
	linux-xfs@...r.kernel.org,
	linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	allexjlzheng@...cent.com,
	flyingpeng@...cent.com
Subject: [PATCH 2/2] mkfs: make cluster size tunnable when sparse alloc enabled

Add clustersize parameter for -i(inode size) switch. When sparse
inode allocation is enabled, use clustersize from cmdline if it's
provided and fallback to XFS_INODE_BIG_CLUSTER_SIZE if not.

Signed-off-by: Tianxiang Peng <txpeng@...cent.com>
Reviewed-by: Jinliang Zheng <allexjlzheng@...cent.com>
Reviewed-by: Hao Peng <flyingpeng@...cent.com>
---
 mkfs/xfs_mkfs.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index bbd0dbb6..b8a597d4 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -92,6 +92,7 @@ enum {
 	I_SPINODES,
 	I_NREXT64,
 	I_EXCHANGE,
+	I_CLUSTERSIZE,
 	I_MAX_OPTS,
 };
 
@@ -474,6 +475,7 @@ static struct opt_params iopts = {
 		[I_SPINODES] = "sparse",
 		[I_NREXT64] = "nrext64",
 		[I_EXCHANGE] = "exchange",
+		[I_CLUSTERSIZE] = "clustersize",
 		[I_MAX_OPTS] = NULL,
 	},
 	.subopt_params = {
@@ -535,6 +537,13 @@ static struct opt_params iopts = {
 		  .maxval = 1,
 		  .defaultval = 1,
 		},
+		{ .index = I_CLUSTERSIZE,
+		  .conflicts = { { NULL, LAST_CONFLICT } },
+		  .is_power_2 = true,
+		  .minval = XFS_DINODE_MIN_SIZE,
+		  .maxval = XFS_DINODE_MIN_SIZE << XFS_INODES_PER_CHUNK_LOG,
+		  .defaultval = XFS_INODE_BIG_CLUSTER_SIZE,
+		},
 	},
 };
 
@@ -956,6 +965,7 @@ struct cli_params {
 	int	inopblock;
 	int	imaxpct;
 	int	lsectorsize;
+	int	clustersize;
 	uuid_t	uuid;
 
 	/* feature flags that are set */
@@ -993,6 +1003,7 @@ struct mkfs_params {
 	int		inodesize;
 	int		inodelog;
 	int		inopblock;
+	int		clustersize;
 
 	uint64_t	dblocks;
 	uint64_t	logblocks;
@@ -1055,7 +1066,7 @@ usage( void )
 /* 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\
-			    exchange=0|1]\n\
+			    exchange=0|1,clustersize=num]\n\
 /* no discard */	[-K]\n\
 /* log subvol */	[-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
 			    sunit=value|su=num,sectsize=num,lazy-count=0|1,\n\
@@ -1756,6 +1767,9 @@ inode_opts_parser(
 	case I_EXCHANGE:
 		cli->sb_feat.exchrange = getnum(value, opts, subopt);
 		break;
+	case I_CLUSTERSIZE:
+		cli->clustersize = getnum(value, opts, subopt);
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -2594,6 +2608,17 @@ validate_inodesize(
 	}
 }
 
+static void
+validate_clustersize(
+	struct mkfs_params	*cfg,
+	struct cli_params	*cli)
+{
+	if (cli->sb_feat.spinodes && cli->clustersize)
+		cfg->clustersize = cli->clustersize;
+	else
+		cfg->clustersize = XFS_INODE_BIG_CLUSTER_SIZE;
+}
+
 static xfs_rfsblock_t
 calc_dev_size(
 	char			*size,
@@ -3517,12 +3542,10 @@ sb_set_features(
 		sbp->sb_versionnum |= XFS_SB_VERSION_4;
 
 	if (fp->inode_align) {
-		int     cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
-
 		sbp->sb_versionnum |= XFS_SB_VERSION_ALIGNBIT;
 		if (cfg->sb_feat.crcs_enabled)
-			cluster_size *= cfg->inodesize / XFS_DINODE_MIN_SIZE;
-		sbp->sb_inoalignmt = cluster_size >> cfg->blocklog;
+			cfg->clustersize *= cfg->inodesize / XFS_DINODE_MIN_SIZE;
+		sbp->sb_inoalignmt = cfg->clustersize >> cfg->blocklog;
 	} else
 		sbp->sb_inoalignmt = 0;
 
@@ -4634,6 +4657,7 @@ main(
 	 */
 	validate_dirblocksize(&cfg, &cli);
 	validate_inodesize(&cfg, &cli);
+	validate_clustersize(&cfg, &cli);
 
 	/*
 	 * if the device size was specified convert it to a block count
-- 
2.43.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ