[PATCH blktests 2/3] common/rc: introduce _load_module()
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Sun Feb 22 19:50:22 PST 2026
When a test case requires specific modules for testing, it loads and
uses the modules. To maintain a clean environment, it is desired that
the test case unloads after execution. The modules should be unloaded
only when the module was not loaded before the test case run. However,
writing logic to determine the module load status and unload accordingly
can be cumbersome.
To simplify and standardize such module unload control, introduce the
helper function _load_module(). It attempts to load the specified
module and records it to the global array MODULES_TO_UNLOAD only when
the module was not already loaded. Modules listed in MODULES_TO_UNLOAD
are unloaded by _unload_modules() after each test case run.
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
common/rc | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/common/rc b/common/rc
index abf66a4..0a8caca 100644
--- a/common/rc
+++ b/common/rc
@@ -69,6 +69,18 @@ _have_driver()
return 0
}
+# Load the specified module. Record the module to MODULES_TO_UNLOAD so that they
+# will be unloaded by _unload_modules() after each test case run.
+_load_module() {
+ local modname="${1/-/_}"
+
+ if ! modprobe --quiet --first-time "${modname}"; then
+ return 1
+ fi
+
+ MODULES_TO_UNLOAD+=("${modname}")
+}
+
# Check that the specified crypto algorithm is present, regardless of whether
# it's built-in or as module.
_have_crypto_algorithm()
--
2.53.0
More information about the Linux-nvme
mailing list