anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone
Jeff Moyer 2c91dc
From fe831b526b88f6ca7a27fdb149b8a7d2ecddbc55 Mon Sep 17 00:00:00 2001
Jeff Moyer 2c91dc
From: Santosh Sivaraj <santosh@fossix.org>
Jeff Moyer 2c91dc
Date: Thu, 13 May 2021 11:42:18 +0530
Jeff Moyer 2c91dc
Subject: [PATCH 021/217] Use page size as alignment value
Bryan Gurney bc084d
Jeff Moyer 2c91dc
The alignment sizes passed to ndctl in the tests are all hardcoded to 4k,
Jeff Moyer 2c91dc
the default page size on x86. Change those to the default page size on that
Jeff Moyer 2c91dc
architecture (sysconf/getconf). No functional changes otherwise.
Bryan Gurney bc084d
Jeff Moyer 2c91dc
Link: https://lore.kernel.org/r/20210513061218.760322-4-santosh@fossix.org
Jeff Moyer 2c91dc
Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
Jeff Moyer 2c91dc
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
---
Jeff Moyer 2c91dc
 test/dpa-alloc.c    | 15 ++++++++-------
Jeff Moyer 2c91dc
 test/multi-dax.sh   |  6 ++++--
Jeff Moyer 2c91dc
 test/sector-mode.sh |  4 +++-
Jeff Moyer 2c91dc
 3 files changed, 15 insertions(+), 10 deletions(-)
Bryan Gurney bc084d
Jeff Moyer 2c91dc
diff --git a/test/dpa-alloc.c b/test/dpa-alloc.c
Jeff Moyer 2c91dc
index 0b3bb7a..59185cf 100644
Jeff Moyer 2c91dc
--- a/test/dpa-alloc.c
Jeff Moyer 2c91dc
+++ b/test/dpa-alloc.c
Jeff Moyer 2c91dc
@@ -38,12 +38,13 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
Bryan Gurney bc084d
 	struct ndctl_region *region, *blk_region = NULL;
Bryan Gurney bc084d
 	struct ndctl_namespace *ndns;
Bryan Gurney bc084d
 	struct ndctl_dimm *dimm;
Bryan Gurney bc084d
-	unsigned long size;
Bryan Gurney bc084d
+	unsigned long size, page_size;
Bryan Gurney bc084d
 	struct ndctl_bus *bus;
Bryan Gurney bc084d
 	char uuid_str[40];
Bryan Gurney bc084d
 	int round;
Bryan Gurney bc084d
 	int rc;
Bryan Gurney bc084d
 
Bryan Gurney bc084d
+	page_size = sysconf(_SC_PAGESIZE);
Bryan Gurney bc084d
 	/* disable nfit_test.1, not used in this test */
Bryan Gurney bc084d
 	bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER1);
Bryan Gurney bc084d
 	if (!bus)
Jeff Moyer 2c91dc
@@ -124,11 +125,11 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
Bryan Gurney bc084d
 			return rc;
Bryan Gurney bc084d
 		}
Bryan Gurney bc084d
 		ndctl_namespace_disable_invalidate(ndns);
Bryan Gurney bc084d
-		rc = ndctl_namespace_set_size(ndns, SZ_4K);
Bryan Gurney bc084d
+		rc = ndctl_namespace_set_size(ndns, page_size);
Bryan Gurney bc084d
 		if (rc) {
Bryan Gurney bc084d
-			fprintf(stderr, "failed to init %s to size: %d\n",
Bryan Gurney bc084d
+			fprintf(stderr, "failed to init %s to size: %lu\n",
Bryan Gurney bc084d
 					ndctl_namespace_get_devname(ndns),
Bryan Gurney bc084d
-					SZ_4K);
Bryan Gurney bc084d
+					page_size);
Bryan Gurney bc084d
 			return rc;
Bryan Gurney bc084d
 		}
Bryan Gurney bc084d
 		namespaces[i].ndns = ndns;
Jeff Moyer 2c91dc
@@ -150,7 +151,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
Bryan Gurney bc084d
 		ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
Bryan Gurney bc084d
 		if (i % ARRAY_SIZE(namespaces) == 0)
Bryan Gurney bc084d
 			round++;
Bryan Gurney bc084d
-		size = SZ_4K * round;
Bryan Gurney bc084d
+		size = page_size * round;
Bryan Gurney bc084d
 		rc = ndctl_namespace_set_size(ndns, size);
Bryan Gurney bc084d
 		if (rc) {
Bryan Gurney bc084d
 			fprintf(stderr, "%s: set_size: %lx failed: %d\n",
Jeff Moyer 2c91dc
@@ -166,7 +167,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
Bryan Gurney bc084d
 	i--;
Bryan Gurney bc084d
 	round++;
Bryan Gurney bc084d
 	ndns = namespaces[i % ARRAY_SIZE(namespaces)].ndns;
Bryan Gurney bc084d
-	size = SZ_4K * round;
Bryan Gurney bc084d
+	size = page_size * round;
Bryan Gurney bc084d
 	rc = ndctl_namespace_set_size(ndns, size);
Bryan Gurney bc084d
 	if (rc) {
Bryan Gurney bc084d
 		fprintf(stderr, "%s failed to update while labels full\n",
Jeff Moyer 2c91dc
@@ -175,7 +176,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
Bryan Gurney bc084d
 	}
Bryan Gurney bc084d
 
Bryan Gurney bc084d
 	round--;
Bryan Gurney bc084d
-	size = SZ_4K * round;
Bryan Gurney bc084d
+	size = page_size * round;
Bryan Gurney bc084d
 	rc = ndctl_namespace_set_size(ndns, size);
Bryan Gurney bc084d
 	if (rc) {
Bryan Gurney bc084d
 		fprintf(stderr, "%s failed to reduce size while labels full\n",
Jeff Moyer 2c91dc
diff --git a/test/multi-dax.sh b/test/multi-dax.sh
Jeff Moyer 2c91dc
index 8496619..b343a38 100755
Jeff Moyer 2c91dc
--- a/test/multi-dax.sh
Jeff Moyer 2c91dc
+++ b/test/multi-dax.sh
Jeff Moyer 2c91dc
@@ -13,6 +13,8 @@ check_prereq "jq"
Bryan Gurney bc084d
 
Bryan Gurney bc084d
 trap 'err $LINENO' ERR
Bryan Gurney bc084d
 
Bryan Gurney bc084d
+ALIGN_SIZE=`getconf PAGESIZE`
Bryan Gurney bc084d
+
Bryan Gurney bc084d
 # setup (reset nfit_test dimms)
Bryan Gurney bc084d
 modprobe nfit_test
Bryan Gurney bc084d
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
Jeff Moyer 2c91dc
@@ -23,9 +25,9 @@ rc=1
Bryan Gurney bc084d
 query=". | sort_by(.available_size) | reverse | .[0].dev"
Bryan Gurney bc084d
 region=$($NDCTL list -b $NFIT_TEST_BUS0 -t pmem -Ri | jq -r "$query")
Bryan Gurney bc084d
 
Bryan Gurney bc084d
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
Bryan Gurney bc084d
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
Bryan Gurney bc084d
 chardev1=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
Bryan Gurney bc084d
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a 4096 -s 16M)
Bryan Gurney bc084d
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -r $region -t pmem -m devdax -a $ALIGN_SIZE -s 16M)
Bryan Gurney bc084d
 chardev2=$(echo $json | jq ". | select(.mode == \"devdax\") | .daxregion.devices[0].chardev")
Bryan Gurney bc084d
 
Bryan Gurney bc084d
 _cleanup
Jeff Moyer 2c91dc
diff --git a/test/sector-mode.sh b/test/sector-mode.sh
Jeff Moyer 2c91dc
index 54fa806..7a2faea 100755
Jeff Moyer 2c91dc
--- a/test/sector-mode.sh
Jeff Moyer 2c91dc
+++ b/test/sector-mode.sh
Jeff Moyer 2c91dc
@@ -11,6 +11,8 @@ check_prereq "jq"
Bryan Gurney bc084d
 set -e
Bryan Gurney bc084d
 trap 'err $LINENO' ERR
Bryan Gurney bc084d
 
Bryan Gurney bc084d
+ALIGN_SIZE=`getconf PAGESIZE`
Bryan Gurney bc084d
+
Bryan Gurney bc084d
 # setup (reset nfit_test dimms)
Bryan Gurney bc084d
 modprobe nfit_test
Bryan Gurney bc084d
 $NDCTL disable-region -b $NFIT_TEST_BUS0 all
Jeff Moyer 2c91dc
@@ -27,7 +29,7 @@ NAMESPACE=$($NDCTL list -b $NFIT_TEST_BUS1 -N | jq -r "$query")
Bryan Gurney bc084d
 REGION=$($NDCTL list -R --namespace=$NAMESPACE | jq -r "(.[]) | .dev")
Bryan Gurney bc084d
 echo 0 > /sys/bus/nd/devices/$REGION/read_only
Bryan Gurney bc084d
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
Bryan Gurney bc084d
-$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a 4K
Bryan Gurney bc084d
+$NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a $ALIGN_SIZE
Bryan Gurney bc084d
 $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K
Bryan Gurney bc084d
 
Bryan Gurney bc084d
 _cleanup
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc