All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shivaprasad G Bhat <sbhat@linux.ibm.com>
To: nvdimm@lists.linux.dev, dan.j.williams@intel.com,
	vishal.l.verma@intel.com
Cc: aneesh.kumar@linux.ibm.com, sbhat@linux.ibm.com, vaibhav@linux.ibm.com
Subject: [RFC ndctl PATCH 2/9] test: core: Fix module unload failures
Date: Mon, 18 Apr 2022 12:10:16 -0500	[thread overview]
Message-ID: <165030181048.3224737.7100905803654677976.stgit@lep8c.aus.stglabs.ibm.com> (raw)
In-Reply-To: <165030175745.3224737.6985015146263991065.stgit@lep8c.aus.stglabs.ibm.com>

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 --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;
 }
 



  parent reply	other threads:[~2022-04-18 17:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 17:09 [RFC ndctl PATCH 0/9] test: Enable PAPR test family by default Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 1/9] test/common: Ensure to unload test modules Shivaprasad G Bhat
2022-04-18 17:10 ` Shivaprasad G Bhat [this message]
2022-04-18 17:10 ` [RFC ndctl PATCH 3/9] test: Unload the nfit module during cleanup Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 4/9] test: Introduce skip file to skip irrelevant tests Shivaprasad G Bhat
2022-04-18 17:10 ` [RFC ndctl PATCH 5/9] test: Assign provider name based on the test family Shivaprasad G Bhat
2022-04-18 17:11 ` [RFC ndctl PATCH 6/9] test: Enable PAPR test family tests after INTEL family tests Shivaprasad G Bhat
2022-04-18 17:15 ` [ndctl v3 PATCH 7/9] test/libndctl: Enable libndctl tests on ndtest Shivaprasad G Bhat
2022-04-18 17:17 ` [ndctl v3 PATCH 8/9] test/inject-smart: Enable inject-smart " Shivaprasad G Bhat
2022-04-18 17:19 ` [ndctl v3 PATCH 9/9] test/monitor.sh: Partially skip monitor test " Shivaprasad G Bhat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165030181048.3224737.7100905803654677976.stgit@lep8c.aus.stglabs.ibm.com \
    --to=sbhat@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=vaibhav@linux.ibm.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.