Blame SOURCES/0070-ndctl-test-Prepare-for-BLK-aperture-support-removal.patch

26ccd9
From e423b467e10e3405e6e09260b7669e7022b5f5f7 Mon Sep 17 00:00:00 2001
26ccd9
From: Dan Williams <dan.j.williams@intel.com>
26ccd9
Date: Wed, 5 Jan 2022 13:31:50 -0800
26ccd9
Subject: [PATCH 070/217] ndctl/test: Prepare for BLK-aperture support removal
26ccd9
26ccd9
The kernel is dropping its support for the BLK-aperture access method. The
26ccd9
primary side effect of this for nfit_test is that NVDIMM namespace labeling
26ccd9
will not be enabled by default. Update the unit tests to initialize the
26ccd9
label index area in this scenario.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/164141830999.3990253.5021445352398348657.stgit@dwillia2-desk3.amr.corp.intel.com
26ccd9
Tested-by: Alison Schofield <alison.schofield@intel.com>
26ccd9
Tested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
26ccd9
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 test/core.c     | 31 ++++++++++++++++++++++++++++---
26ccd9
 test/libndctl.c | 49 +++++++++++++++++++++++++++++++++++--------------
26ccd9
 2 files changed, 63 insertions(+), 17 deletions(-)
26ccd9
26ccd9
diff --git a/test/core.c b/test/core.c
26ccd9
index 2b03aa9..93e1dae 100644
26ccd9
--- a/test/core.c
26ccd9
+++ b/test/core.c
26ccd9
@@ -261,8 +261,8 @@ retry:
26ccd9
 		ndctl_bus_foreach(nd_ctx, bus) {
26ccd9
 			struct ndctl_region *region;
26ccd9
 
26ccd9
-			if (strncmp(ndctl_bus_get_provider(bus),
26ccd9
-						"nfit_test", 9) != 0)
26ccd9
+			if (strcmp(ndctl_bus_get_provider(bus),
26ccd9
+				   "nfit_test.0") != 0)
26ccd9
 				continue;
26ccd9
 			ndctl_region_foreach(bus, region)
26ccd9
 				ndctl_region_disable_invalidate(region);
26ccd9
@@ -280,5 +280,30 @@ retry:
26ccd9
 			NULL, NULL, NULL, NULL);
26ccd9
 	if (rc)
26ccd9
 		kmod_unref(*ctx);
26ccd9
-	return rc;
26ccd9
+
26ccd9
+	if (!nd_ctx)
26ccd9
+		return rc;
26ccd9
+
26ccd9
+	ndctl_bus_foreach (nd_ctx, bus) {
26ccd9
+		struct ndctl_region *region;
26ccd9
+		struct ndctl_dimm *dimm;
26ccd9
+
26ccd9
+		if (strcmp(ndctl_bus_get_provider(bus), "nfit_test.0") != 0)
26ccd9
+			continue;
26ccd9
+
26ccd9
+		ndctl_region_foreach (bus, region)
26ccd9
+			ndctl_region_disable_invalidate(region);
26ccd9
+
26ccd9
+		ndctl_dimm_foreach (bus, dimm) {
26ccd9
+			ndctl_dimm_read_label_index(dimm);
26ccd9
+			ndctl_dimm_init_labels(dimm, NDCTL_NS_VERSION_1_2);
26ccd9
+			ndctl_dimm_disable(dimm);
26ccd9
+			ndctl_dimm_enable(dimm);
26ccd9
+		}
26ccd9
+
26ccd9
+		ndctl_region_foreach (bus, region)
26ccd9
+			ndctl_region_enable(region);
26ccd9
+	}
26ccd9
+
26ccd9
+	return 0;
26ccd9
 }
26ccd9
diff --git a/test/libndctl.c b/test/libndctl.c
26ccd9
index d9b50f4..c0e4b4c 100644
26ccd9
--- a/test/libndctl.c
26ccd9
+++ b/test/libndctl.c
26ccd9
@@ -2587,17 +2587,41 @@ static int check_dimms(struct ndctl_bus *bus, struct dimm *dimms, int n,
26ccd9
 	return 0;
26ccd9
 }
26ccd9
 
26ccd9
-static void reset_bus(struct ndctl_bus *bus)
26ccd9
+enum dimm_reset {
26ccd9
+	DIMM_INIT,
26ccd9
+	DIMM_ZERO,
26ccd9
+};
26ccd9
+
26ccd9
+static int reset_dimms(struct ndctl_bus *bus, enum dimm_reset reset)
26ccd9
 {
26ccd9
-	struct ndctl_region *region;
26ccd9
 	struct ndctl_dimm *dimm;
26ccd9
+	int rc = 0;
26ccd9
+
26ccd9
+	ndctl_dimm_foreach(bus, dimm) {
26ccd9
+		if (reset == DIMM_ZERO)
26ccd9
+			ndctl_dimm_zero_labels(dimm);
26ccd9
+		else {
26ccd9
+			ndctl_dimm_read_label_index(dimm);
26ccd9
+			ndctl_dimm_init_labels(dimm, NDCTL_NS_VERSION_1_2);
26ccd9
+		}
26ccd9
+		ndctl_dimm_disable(dimm);
26ccd9
+		rc = ndctl_dimm_enable(dimm);
26ccd9
+		if (rc)
26ccd9
+			break;
26ccd9
+	}
26ccd9
+
26ccd9
+	return rc;
26ccd9
+}
26ccd9
+
26ccd9
+static void reset_bus(struct ndctl_bus *bus, enum dimm_reset reset)
26ccd9
+{
26ccd9
+	struct ndctl_region *region;
26ccd9
 
26ccd9
 	/* disable all regions so that set_config_data commands are permitted */
26ccd9
 	ndctl_region_foreach(bus, region)
26ccd9
 		ndctl_region_disable_invalidate(region);
26ccd9
 
26ccd9
-	ndctl_dimm_foreach(bus, dimm)
26ccd9
-		ndctl_dimm_zero_labels(dimm);
26ccd9
+	reset_dimms(bus, reset);
26ccd9
 
26ccd9
 	/* set regions back to their default state */
26ccd9
 	ndctl_region_foreach(bus, region)
26ccd9
@@ -2608,7 +2632,6 @@ static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
26ccd9
 {
26ccd9
 	struct ndctl_bus *bus = ndctl_bus_get_by_provider(ctx, NFIT_PROVIDER0);
26ccd9
 	struct ndctl_region *region;
26ccd9
-	struct ndctl_dimm *dimm;
26ccd9
 	int rc;
26ccd9
 
26ccd9
 	if (!bus)
26ccd9
@@ -2625,13 +2648,10 @@ static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
26ccd9
 	if (rc)
26ccd9
 		return rc;
26ccd9
 
26ccd9
-	ndctl_dimm_foreach(bus, dimm) {
26ccd9
-		rc = ndctl_dimm_zero_labels(dimm);
26ccd9
-		if (rc < 0) {
26ccd9
-			fprintf(stderr, "failed to zero %s\n",
26ccd9
-					ndctl_dimm_get_devname(dimm));
26ccd9
-			return rc;
26ccd9
-		}
26ccd9
+	rc = reset_dimms(bus, DIMM_INIT);
26ccd9
+	if (rc < 0) {
26ccd9
+		fprintf(stderr, "failed to reset dimms\n");
26ccd9
+		return rc;
26ccd9
 	}
26ccd9
 
26ccd9
 	/*
26ccd9
@@ -2649,14 +2669,14 @@ static int do_test0(struct ndctl_ctx *ctx, struct ndctl_test *test)
26ccd9
 		rc = check_regions(bus, regions0, ARRAY_SIZE(regions0), DAX);
26ccd9
 		if (rc)
26ccd9
 			return rc;
26ccd9
-		reset_bus(bus);
26ccd9
+		reset_bus(bus, DIMM_INIT);
26ccd9
 	}
26ccd9
 
26ccd9
 	if (ndctl_test_attempt(test, KERNEL_VERSION(4, 8, 0))) {
26ccd9
 		rc = check_regions(bus, regions0, ARRAY_SIZE(regions0), PFN);
26ccd9
 		if (rc)
26ccd9
 			return rc;
26ccd9
-		reset_bus(bus);
26ccd9
+		reset_bus(bus, DIMM_INIT);
26ccd9
 	}
26ccd9
 
26ccd9
 	return check_regions(bus, regions0, ARRAY_SIZE(regions0), BTT);
26ccd9
@@ -2671,6 +2691,7 @@ static int do_test1(struct ndctl_ctx *ctx, struct ndctl_test *test)
26ccd9
 		return -ENXIO;
26ccd9
 
26ccd9
 	ndctl_bus_wait_probe(bus);
26ccd9
+	reset_bus(bus, DIMM_ZERO);
26ccd9
 
26ccd9
 	/*
26ccd9
 	 * Starting with v4.10 the dimm on nfit_test.1 gets a unique
26ccd9
-- 
26ccd9
2.27.0
26ccd9