diff mbox series

[RFC,ndctl,2/9] test: core: Fix module unload failures

Message ID 165030181048.3224737.7100905803654677976.stgit@lep8c.aus.stglabs.ibm.com (mailing list archive)
State New, archived
Headers show
Series test: Enable PAPR test family by default | expand

Commit Message

Shivaprasad G Bhat April 18, 2022, 5:10 p.m. UTC
The kmod_module_remove_module() called by the tests without
disabling the regions from the test provider. So, the module
remove fails during many of the tests.

The patch writes a wrapper which properly disables the test provider
specific regions before calling the kmod_module_remove_module().

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 test.h                        |    2 ++
 test/ack-shutdown-count-set.c |    4 ++--
 test/core.c                   |   28 ++++++++++++++++++++++++++++
 test/dsm-fail.c               |    4 ++--
 test/libndctl.c               |    3 +--
 test/pmem_namespaces.c        |   23 ++++++-----------------
 6 files changed, 41 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/test.h b/test.h
index b2267e66..6cff4189 100644
--- a/test.h
+++ b/test.h
@@ -23,6 +23,8 @@  struct kmod_module;
 int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 		struct ndctl_ctx *nd_ctx, int log_level,
 		struct ndctl_test *test);
+int ndctl_test_module_remove(struct kmod_ctx **ctx, struct kmod_module **mod,
+			struct ndctl_ctx *nd_ctx);
 
 struct ndctl_ctx;
 int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
diff --git a/test/ack-shutdown-count-set.c b/test/ack-shutdown-count-set.c
index f091a404..2d77aa07 100644
--- a/test/ack-shutdown-count-set.c
+++ b/test/ack-shutdown-count-set.c
@@ -109,9 +109,9 @@  static int test_ack_shutdown_count_set(int loglevel, struct ndctl_test *test,
 	}
 
 	result = do_test(ctx, test);
-	kmod_module_remove_module(mod, 0);
 
-	kmod_unref(kmod_ctx);
+	ndctl_test_module_remove(&kmod_ctx, &mod, ctx);
+
 	return result;
 }
 
diff --git a/test/core.c b/test/core.c
index 5d1aa237..7b23e258 100644
--- a/test/core.c
+++ b/test/core.c
@@ -107,6 +107,34 @@  int ndctl_test_get_skipped(struct ndctl_test *test)
 	return test->skip;
 }
 
+void ndctl_test_module_remove(struct kmod_ctx **ctx, struct kmod_module **mod,
+				struct ndctl_ctx *nd_ctx)
+{
+	struct ndctl_bus *bus;
+	int rc;
+
+	ndctl_bus_foreach(nd_ctx, bus) {
+		struct ndctl_region *region;
+
+		if ((strcmp(ndctl_bus_get_provider(bus),
+			   "nfit_test.0") != 0) &&
+			strcmp(ndctl_bus_get_provider(bus),
+				"nfit_test.1") != 0)
+			continue;
+
+		ndctl_region_foreach(bus, region)
+			ndctl_region_disable_invalidate(region);
+	}
+
+	rc = kmod_module_remove_module(*mod, 0);
+	if (rc < 0 && rc != -ENOENT) {
+		fprintf(stderr, "couldn't remove module %s\n",
+				    strerror(-rc));
+	}
+
+	kmod_unref(*ctx);
+}
+
 int ndctl_test_init(struct kmod_ctx **ctx, struct kmod_module **mod,
 		struct ndctl_ctx *nd_ctx, int log_level,
 		struct ndctl_test *test)
diff --git a/test/dsm-fail.c b/test/dsm-fail.c
index 5b443dcd..65ac2bd4 100644
--- a/test/dsm-fail.c
+++ b/test/dsm-fail.c
@@ -356,9 +356,9 @@  int test_dsm_fail(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
 	}
 
 	result = do_test(ctx, test);
-	kmod_module_remove_module(mod, 0);
 
-	kmod_unref(kmod_ctx);
+	ndctl_test_module_remove(&kmod_ctx, &mod, ctx);
+
 	return result;
 }
 
diff --git a/test/libndctl.c b/test/libndctl.c
index 51245cf4..df61f84c 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -2612,8 +2612,7 @@  int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx)
 
 	if (i >= ARRAY_SIZE(do_test))
 		result = EXIT_SUCCESS;
-	kmod_module_remove_module(mod, 0);
-	kmod_unref(kmod_ctx);
+	ndctl_test_module_remove(&kmod_ctx, &mod, ctx);
 	return result;
 }
 
diff --git a/test/pmem_namespaces.c b/test/pmem_namespaces.c
index 4bafff51..64207020 100644
--- a/test/pmem_namespaces.c
+++ b/test/pmem_namespaces.c
@@ -198,7 +198,7 @@  int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 			rc = 77;
 			ndctl_test_skip(test);
 			fprintf(stderr, "nfit_test unavailable skipping tests\n");
-			goto err_module;
+			goto exit;
 		}
 	}
 
@@ -214,7 +214,7 @@  int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 		if (rc < 0) {
 			fprintf(stderr, "failed to zero %s\n",
 					ndctl_dimm_get_devname(dimm));
-			goto err;
+			goto exit;
 		}
 	}
 
@@ -228,14 +228,14 @@  int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 	if (!pmem_region || ndctl_region_enable(pmem_region) < 0) {
 		fprintf(stderr, "%s: failed to find PMEM region\n", comm);
 		rc = -ENODEV;
-		goto err;
+		goto exit;
 	}
 
 	rc = -ENODEV;
 	ndns = create_pmem_namespace(pmem_region);
 	if (!ndns) {
 		fprintf(stderr, "%s: failed to create PMEM namespace\n", comm);
-		goto err;
+		goto exit;
 	}
 
 	sprintf(bdev, "/dev/%s", ndctl_namespace_get_block_device(ndns));
@@ -243,20 +243,9 @@  int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 
 	disable_pmem_namespace(ndns);
 
- err:
-	/* unload nfit_test */
-	bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
-	if (bus)
-		ndctl_region_foreach(bus, region)
-			ndctl_region_disable_invalidate(region);
-	bus = ndctl_bus_get_by_provider(ctx, "nfit_test.1");
-	if (bus)
-		ndctl_region_foreach(bus, region)
-			ndctl_region_disable_invalidate(region);
-	kmod_module_remove_module(mod, 0);
+ exit:
+	ndctl_test_module_remove(&kmod_ctx, &mod, ctx);
 
- err_module:
-	kmod_unref(kmod_ctx);
 	return rc;
 }