]> www.infradead.org Git - users/hch/blktests.git/commitdiff
common/rc: ensure modules are loadable in _have_modules()
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 23 Aug 2022 00:11:50 +0000 (09:11 +0900)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 29 Aug 2022 23:52:54 +0000 (08:52 +0900)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
common/rc

index 5b34c60c4c49d6eae14f345ce66c00a4fabae825..8681a46500d89f689a8bad9f37377d66da0613e2 100644 (file)
--- 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" -o \
+                    -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