]> www.infradead.org Git - users/hch/blktests.git/commitdiff
common/null_blk: allow _configure_null_blk with built-in null_blk
authorChristoph Hellwig <hch@lst.de>
Wed, 1 Jun 2022 08:29:42 +0000 (10:29 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 7 Jun 2022 10:24:47 +0000 (12:24 +0200)
Test that do use _configure_null_blk already configure do not actually
require a built-in null_blk driver.  Relax the check in _have_null_blk
to just require a driver instead of a module, and instead set a skip
reason instead of failing in _init_null_blk when null_blk is built-in
or otherwise not available.

Also try to load the null_blk module in _configure_null_blk as
_init_null_blk is optional now and we thus can't rely on the module
to be loaded.

Signed-off-by: Christoph Hellwig <hch@lst.de>
common/null_blk

index 6611db03a00e3f59c875c50d1e3690f447237f31..30d54c2a234a19714796c50ad61bb5986102cab5 100644 (file)
@@ -4,8 +4,10 @@
 #
 # null_blk helper functions.
 
+. common/shellcheck
+
 _have_null_blk() {
-       _have_modules null_blk
+       _have_driver null_blk
 }
 
 _remove_null_blk_devices() {
@@ -22,6 +24,7 @@ _init_null_blk() {
        if (( RUN_FOR_ZONED )); then zoned="zoned=1"; fi
 
        if ! modprobe -r null_blk || ! modprobe null_blk "$@" "${zoned}" ; then
+               SKIP_REASON="requires modular null_blk"
                return 1
        fi
 
@@ -32,8 +35,12 @@ _init_null_blk() {
 # Configure one null_blk instance with name $1 and parameters $2..${$#}.
 _configure_null_blk() {
        local nullb=/sys/kernel/config/nullb/$1 param val
-
        shift
+
+       if [[ ! -d /sys/module/null_blk ]]; then
+               modprobe -q null_blk
+       fi
+
        mkdir "$nullb" || return $?
        while [[ $# -gt 0 ]]; do
                param="${1%%=*}"
@@ -46,5 +53,5 @@ _configure_null_blk() {
 _exit_null_blk() {
        _remove_null_blk_devices
        udevadm settle
-       modprobe -r null_blk
+       modprobe -r -q null_blk
 }