[PATCH blktests 02/13] common/null_blk: allow _configure_null_blk with built-in null_blk

Christoph Hellwig
2022-06-07T12:47:52Z

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 | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/common/null_blk b/common/null_blk
index 6611db0..30d54c2 100644
--- a/common/null_blk
+++ b/common/null_blk
@@ -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
}
--
2.30.2