diff mbox series

[blktests,v2,3/6] common/rc: ensure modules are loadable in _have_modules()

Message ID 20220818012624.71544-4-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series fix module check issues | expand

Commit Message

Shin'ichiro Kawasaki Aug. 18, 2022, 1:26 a.m. UTC
The commit e9645877fbf0 ("common: add a helper if a driver is
available") introduced the helper function _have_driver() to check the
driver or module is available no matter whether it is a loadable module
or built-in module. It was assumed that _have_modules() whould check
that specified modules are loadable and not built-in.

However, the function _have_modules() returns true even if the specified
modules are built-in and not loadable. This causes failures of some test
cases on test system with built-in modules such as nbd/004. It also
means that _have_modules() and _have_driver() have same functionality.

To avoid the unexpected failures, fix _have_modules() to return false
when the specified modules are built-in. Check if loadable module file
exists by searching the module file path. If the module file does not
exist, return false. Also add comments to describe the difference
between _have_driver() and _have_modules().

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/rc | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Bart Van Assche Aug. 18, 2022, 8:06 p.m. UTC | #1
On 8/17/22 18:26, Shin'ichiro Kawasaki wrote:
> +	count=$(find "$libpath" -name "$ko_underscore" -or \
> +		     -name "$ko_hyphen" | wc -l)

Do all Linux find executables support -or? It's probably safer to use -o 
instead of -or.

Thanks,

Bart.
Shin'ichiro Kawasaki Aug. 19, 2022, 12:35 a.m. UTC | #2
On Aug 18, 2022 / 13:06, Bart Van Assche wrote:
> On 8/17/22 18:26, Shin'ichiro Kawasaki wrote:
> > +	count=$(find "$libpath" -name "$ko_underscore" -or \
> > +		     -name "$ko_hyphen" | wc -l)
> 
> Do all Linux find executables support -or? It's probably safer to use -o
> instead of -or.

Thanks. I agree that -o is safer. Will use -o.
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 8150fee..ee2289c 100644
--- a/common/rc
+++ b/common/rc
@@ -28,6 +28,22 @@  _have_root() {
 	return 0
 }
 
+_module_file_exists()
+{
+	local ko_underscore=${1//-/_}.ko
+	local ko_hyphen=${1//_/-}.ko
+	local libpath
+	local -i count
+
+	libpath="/lib/modules/$(uname -r)/kernel"
+	count=$(find "$libpath" -name "$ko_underscore" -or \
+		     -name "$ko_hyphen" | wc -l)
+	((count)) && return 0
+	return 1
+}
+
+# Check that the specified module or driver is available, regardless of whether
+# it is built-in or built separately as a module.
 _have_driver()
 {
 	local modname="${1//-/_}"
@@ -41,12 +57,14 @@  _have_driver()
 	return 0
 }
 
+# Check that the specified modules are available as loadable modules and not
+# built-in the kernel.
 _have_modules() {
 	local missing=()
 	local module
 
 	for module in "$@"; do
-		if ! modprobe -n -q "$module"; then
+		if ! _module_file_exists "${module}"; then
 			missing+=("$module")
 		fi
 	done