]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
common/null_blk: introduce _have_null_blk_feature
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 11 Jan 2024 09:00:37 +0000 (18:00 +0900)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 23 Jan 2024 10:39:47 +0000 (19:39 +0900)
Introduce a helper function _have_null_blk_feature which checks
/sys/kernel/config/features. It allows test cases to adapt to null_blk
feature support status.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
common/null_blk

index 91b78d4c6a8ee44711cd78d4ba5ede58608060d6..164125df562da83fa9b2c941a00b71c81b92153e 100644 (file)
@@ -10,6 +10,21 @@ _have_null_blk() {
        _have_driver null_blk
 }
 
+_have_null_blk_feature() {
+       # Ensure that null_blk driver is built-in or loaded
+       if ! [[ -d /sys/module/null_blk ]]; then
+               if ! modprobe -q null_blk; then
+                       return 1
+               fi
+               if [[ ! "${MODULES_TO_UNLOAD[*]}" =~ null_blk ]]; then
+                       MODULES_TO_UNLOAD+=(null_blk)
+               fi
+       fi
+
+       # Check that null_blk has the specified feature
+       grep -qe "$1" /sys/kernel/config/nullb/features
+}
+
 _remove_null_blk_devices() {
        if [[ -d /sys/kernel/config/nullb ]]; then
                find /sys/kernel/config/nullb -mindepth 1 -maxdepth 1 \