support built-in scsi_debug
Subsystems (2)
v2 cover support built-in scsi_debug
From: Shin'ichiro Kawasaki <[email protected]>
In the past, there was an issue related to scsi_debug module unload [1]. At that time, it was suggested to modify blktests not to rely on module load and unload. Based on that discussion, blktests was modified not to load or unload null_blk driver [2][3]. As of today, a number of test cases with null_blk can be run with built-in null_blk.
This series introduces similar support for built-in scsi_debug. This patch adds a new helper function _configure_scsi_debug which can set up scsi_debug device without module load and unload. Also it enables 5 test cases to run with built- in scsi_debug.
The first patch in this series fixes a minor issue found during this work. Next two patches modify common/scsi_debug functions as preparation. The 4th patch introduces the new function _configure_scsi_debug. Following 5 patches modify the 5 test cases so that they can run with built-in scsi debug.
Of note is that still srp test group and 9 test cases in other test groups are left to require loadable scsi_debug. The srp test group and 8 of the 9 test cases can not be run with built-in scsi_debug because the parameters they set are read-only on sysfs. The other one test case scsi/007 has other failure symptom now, so I leave it untouched at this moment.
[1] https://lore.kernel.org/linux-block/[email protected]/
[2] https://lore.kernel.org/linux-block/[email protected]/
[3] https://lore.kernel.org/linux-block/[email protected]/
Changes from v1:
* 4th patch: improved to restore scsi_debug parameters modified during test
* Squashed last 5 patches into 2 patches as suggested
* Added Reviewed-by tags
* Noted srp test group in the last paragraph of the cover letter
Shin'ichiro Kawasaki (6):
common/rc: skip module file check if modules path does not exist common/scsi_debug, tests/*: re-define _have_scsi_debug common/scsi_debug: factor out _setup_scsi_debug_vars common/scsi_debug: introduce _configure_scsi_debug scsi/{004,005}: allow to run with built-in scsi_debug block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod
common/rc | 1 + common/scsi_debug | 138 ++++++++++++++++++++++++++++++++++++++++++---- tests/block/001 | 4 +- tests/block/002 | 5 +- tests/block/009 | 3 +- tests/block/025 | 2 +- tests/block/027 | 6 +- tests/block/028 | 2 +- tests/block/032 | 3 +- tests/loop/004 | 5 +- tests/scsi/004 | 2 +- tests/scsi/005 | 5 +- tests/scsi/007 | 2 +- tests/zbd/008 | 5 +- tests/zbd/009 | 2 +- tests/zbd/010 | 2 +- 16 files changed, 156 insertions(+), 31 deletions(-)
Signature · 1 line
2.40.0
PATCH v2 1/6 common/rc: skip module file check if modules path does not exist
From: Shin'ichiro Kawasaki <[email protected]>
When all of the kernel modules are built-in, /lib/modules/*/kernel path may not exist. In this case, check for the path results in failure. Skip the check when the path does not exist.
--- common/rc | 1 + 1 file changed, 1 insertion(+)
common/rc +1 -0
@@ -36,6 +36,7 @@ _module_file_exists() local -i count libpath="/lib/modules/$(uname -r)/kernel" + [[ ! -d $libpath ]] && return 1 count=$(find "$libpath" -name "$ko_underscore*" -o \ -name "$ko_hyphen*" | wc -l) ((count)) && return 0
Signature · 1 line
2.40.0
Re: [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist
Looks good,
PATCH v2 2/6 common/scsi_debug, tests/*: re-define _have_scsi_debug
In reply to Shin'ichiro KawasakiFrom: Shin'ichiro Kawasaki <[email protected]>
As a preparation to adapt test cases to built-in scsi_debug module, re- define the _have_scsi_debug function. It checks that the scsi_debug module is built as a loadable module. Modify it to check that the scsi_debug module is available as built-in module or loadable module.
Also replace all _have_scsi_debug calls in test cases with "_have_module scsi_debug" so that the change of _have_scsi_debug do not affect the test cases. Following commits will modify them to call _have_scsi_debug, only for test cases ready to run with built-in scsi_debug.
--- common/scsi_debug | 2 +- tests/block/001 | 2 +- tests/block/002 | 3 ++- tests/block/009 | 3 ++- tests/block/025 | 2 +- tests/block/027 | 4 +++- tests/block/028 | 2 +- tests/block/032 | 3 ++- tests/loop/004 | 5 ++++- tests/scsi/004 | 2 +- tests/scsi/005 | 3 ++- tests/scsi/007 | 2 +- tests/zbd/008 | 5 +++-- tests/zbd/009 | 2 +- tests/zbd/010 | 2 +- 15 files changed, 26 insertions(+), 16 deletions(-)
common/scsi_debug +1 -1
@@ -5,7 +5,7 @@ # scsi_debug helper functions. _have_scsi_debug() { - _have_module scsi_debug + _have_driver scsi_debug } _init_scsi_debug() {
tests/block/001 +1 -1
@@ -13,7 +13,7 @@ DESCRIPTION="stress device hotplugging" TIMED=1 requires() { - _have_scsi_debug + _have_module scsi_debug _have_driver sd_mod _have_driver sr_mod }
tests/block/002 +2 -1
@@ -12,7 +12,8 @@ DESCRIPTION="remove a device while running blktrace" QUICK=1 requires() { - _have_blktrace && _have_scsi_debug + _have_blktrace + _have_module scsi_debug } test() {
tests/block/009 +2 -1
@@ -12,7 +12,8 @@ DESCRIPTION="check page-cache coherency after BLKDISCARD" requires() { - _have_scsi_debug && _have_program xfs_io + _have_module scsi_debug + _have_program xfs_io } test() {
tests/block/025 +1 -1
@@ -12,7 +12,7 @@ DESCRIPTION="do a huge discard with 4k sector size" requires() { - _have_scsi_debug + _have_module scsi_debug } test() {
tests/block/027 +3 -1
@@ -19,7 +19,9 @@ QUICK=1 CAN_BE_ZONED=1 requires() { - _have_cgroup2_controller io && _have_scsi_debug && _have_fio + _have_cgroup2_controller io + _have_module scsi_debug + _have_fio } scsi_debug_stress_remove() {
tests/block/028 +1 -1
@@ -12,7 +12,7 @@ DESCRIPTION="do I/O on scsi_debug with DIF/DIX enabled" DMESG_FILTER="sed -r 's/(guard tag error at sector|ref tag error at location)/blktests failure: \\1/'" requires() { - _have_scsi_debug + _have_module scsi_debug } test_pi() {
tests/block/032 +2 -1
@@ -13,7 +13,8 @@ DESCRIPTION="remove one mounted device" QUICK=1 requires() { - _have_xfs && _have_scsi_debug + _have_xfs + _have_module scsi_debug } test() {
tests/loop/004 +4 -1
@@ -11,7 +11,10 @@ DESCRIPTION="combine loop direct I/O mode and a custom block size" QUICK=1 requires() { - _have_program xfs_io && _have_scsi_debug && _have_src_program loblksize && _have_loop_set_block_size + _have_program xfs_io + _have_module scsi_debug + _have_src_program loblksize + _have_loop_set_block_size } test() {
tests/scsi/004 +1 -1
@@ -18,7 +18,7 @@ DESCRIPTION="ensure repeated TASK SET FULL results in EIO on timing out command" CAN_BE_ZONED=1 requires() { - _have_scsi_debug + _have_module scsi_debug } test() {
tests/scsi/005 +2 -1
@@ -11,7 +11,8 @@ DESCRIPTION="test SCSI device blacklisting" QUICK=1 requires() { - _have_scsi_debug && _have_module_param scsi_debug inq_vendor + _have_module scsi_debug + _have_module_param scsi_debug inq_vendor } test() {
tests/scsi/007 +1 -1
@@ -12,7 +12,7 @@ DESCRIPTION="Trigger the SCSI error handler" QUICK=1 requires() { - _have_scsi_debug + _have_module scsi_debug } config_hz() {
tests/zbd/008 +3 -2
@@ -13,8 +13,9 @@ DESCRIPTION="check no stale page cache after BLKZONERESET and data read race" TIMED=1 requires() { - _have_scsi_debug && _have_module_param scsi_debug zbc && - _have_program xfs_io + _have_module scsi_debug + _have_module_param scsi_debug zbc + _have_program xfs_io } test() {
tests/zbd/009 +1 -1
@@ -36,7 +36,7 @@ requires() { _have_driver btrfs _have_module_param scsi_debug zone_cap_mb _have_program mkfs.btrfs - _have_scsi_debug + _have_module scsi_debug have_good_mkfs_btrfs }
tests/zbd/010 +1 -1
@@ -15,7 +15,7 @@ requires() { _have_module null_blk _have_module_param scsi_debug zone_cap_mb _have_program mkfs.f2fs - _have_scsi_debug + _have_module scsi_debug } test() {
Signature · 1 line
2.40.0
Re: [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug
Looks good,
PATCH v2 3/6 common/scsi_debug: factor out _setup_scsi_debug_vars
In reply to Shin'ichiro KawasakiFrom: Shin'ichiro Kawasaki <[email protected]>
As a preparation to introduce a new helper function to configure scsi_debug device with built-in scsi_debug module, factor out a part of _init_scsi_debug to a new function _setup_scsi_debug_vars.
--- common/scsi_debug | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
common/scsi_debug +20 -16
@@ -8,22 +8,7 @@ _have_scsi_debug() { _have_driver scsi_debug } -_init_scsi_debug() { - local -a args=("$@") - - if (( RUN_FOR_ZONED )); then - if ! _have_module_param scsi_debug zbc; then - return - fi - args+=(zbc=host-managed zone_nr_conv=0) - fi - - if ! modprobe -r scsi_debug || ! modprobe scsi_debug "${args[@]}"; then - return 1 - fi - - udevadm settle - +_setup_scsi_debug_vars() { local host_sysfs host target_sysfs target SCSI_DEBUG_HOSTS=() SCSI_DEBUG_TARGETS=()
@@ -55,6 +40,25 @@ _init_scsi_debug() { return 0 } +_init_scsi_debug() { + local -a args=("$@") + + if (( RUN_FOR_ZONED )); then + if ! _have_module_param scsi_debug zbc; then + return + fi + args+=(zbc=host-managed zone_nr_conv=0) + fi + + if ! modprobe -r scsi_debug || ! modprobe scsi_debug "${args[@]}"; then + return 1 + fi + + udevadm settle + + _setup_scsi_debug_vars +} + _exit_scsi_debug() { unset SCSI_DEBUG_HOSTS unset SCSI_DEBUG_TARGETS
Signature · 1 line
2.40.0
Re: [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars
Looks good,
PATCH v2 4/6 common/scsi_debug: introduce _configure_scsi_debug
In reply to Shin'ichiro KawasakiFrom: Shin'ichiro Kawasaki <[email protected]>
To set up scsi_debug devices with built-in scsi_debug module, introduce a new helper function _configure_scsi_debug. It works in similar manner as _init_scsi_debug which sets up scsi_debug devices with loadable scsi_debug module.
_configure_scsi_debug takes parameters of scsi_debug devices in format of 'key=value' as its arguments. It calls another new helper function _scsi_debug_key_path to find sysfs files corresponding to the keys in /sys/bus/pseudo/drivers/scsi_debug or /sys/module/scsi_debug/parameters. When the file is found, write the value to the file.
Before setting the parameters through sysfs files, save current values of scsi_debug parameters in ORIG_SCSI_DEBUG_PARAMS. Use the saved values to restore parameters in _exit_scsi_debug. Do this value restore not only for the parameters modified in _configure_scsi_debug but also for the parameters modified by test cases.
Among the parameters, 'add_host' has special meaning to add new hosts. Then handle it separately so that it is set at last in _configure_scsi_debug, and restored at first in _exit_scsi_debug.
Also record the hosts which exist before _configure_scsi_debug in the array ORIG_SCSI_DEBUG_HOSTS. Those hosts should not be used for testing, then do not add them to SCSI_DEBUG_HOSTS.
--- common/scsi_debug | 112 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-)
common/scsi_debug +111 -1
@@ -8,16 +8,51 @@ _have_scsi_debug() { _have_driver scsi_debug } +SD_PSEUDO_PATH=/sys/bus/pseudo/drivers/scsi_debug +SD_PARAM_PATH=/sys/module/scsi_debug/parameters + +_scsi_debug_key_path() { + local key=${1} + + path="${SD_PSEUDO_PATH}/$key" + if [[ ! -e $path ]]; then + path="${SD_PARAM_PATH}/$key" + fi + if [[ ! -w $path ]]; then + return 1 + fi + + echo "$path" +} + +declare -a SCSI_DEBUG_HOSTS +declare -a SCSI_DEBUG_TARGETS +declare -a SCSI_DEBUG_DEVICES +declare -a ORIG_SCSI_DEBUG_HOSTS +declare -A ORIG_SCSI_DEBUG_PARAMS +declare SCSI_DEBUG_ADD_HOST_RESTORE_VALUE + _setup_scsi_debug_vars() { local host_sysfs host target_sysfs target + local -i i + SCSI_DEBUG_HOSTS=() SCSI_DEBUG_TARGETS=() SCSI_DEBUG_DEVICES=() + for host_sysfs in /sys/class/scsi_host/*; do if [[ "$(cat "${host_sysfs}/proc_name")" = scsi_debug ]]; then host="${host_sysfs#/sys/class/scsi_host/host}" + local orig_host=0 + for ((i=0;i<${#ORIG_SCSI_DEBUG_HOSTS[@]};i++)); do + if (( host == ORIG_SCSI_DEBUG_HOSTS[i])); then + orig_host=1 + fi + done + ((orig_host)) && continue SCSI_DEBUG_HOSTS+=("$host") for target_sysfs in /sys/class/scsi_device/"$host":*; do + [[ ! -e $target_sysfs ]] && break target="${target_sysfs#/sys/class/scsi_device/}" SCSI_DEBUG_TARGETS+=("$target") SCSI_DEBUG_DEVICES+=("$(ls "$target_sysfs/device/block")")
@@ -59,10 +94,85 @@ _init_scsi_debug() { _setup_scsi_debug_vars } +_configure_scsi_debug() { + local -a args=("$@") + local -a values + local key value path add_host_value=1 + local -i i + + udevadm settle + + # fall back to _init_scsi_debug because scsi_debug is loadable + if _module_file_exists scsi_debug; then + _init_scsi_debug "${args[@]}" + return + fi + + # zoned device is not yet configurable due to read-only zbc parameter + if (( RUN_FOR_ZONED )) && ! _have_module scsi_debug; then + return 1 + fi + + # List SCSI_DEBUG_HOSTS before configuration + ORIG_SCSI_DEBUG_HOSTS=() + _setup_scsi_debug_vars >& /dev/null + ORIG_SCSI_DEBUG_HOSTS=("${SCSI_DEBUG_HOSTS[@]}") + + # Save current values of all scsi_debug parameters except add_host + ORIG_SCSI_DEBUG_PARAMS=() + for path in "$SD_PSEUDO_PATH"/* "$SD_PARAM_PATH"/*; do + if [[ -f $path && ! $path =~ add_host ]] && + [[ $(stat -c "%A" "$path") =~ rw ]]; then + ORIG_SCSI_DEBUG_PARAMS["$path"]="$(<"$path")" + fi + done + + # Modify parameters specifeid with key=value arguments + for o in "$@"; do + key=${o%=*} + value=${o#*=} + values+=("${value}") + if ! path=$(_scsi_debug_key_path "$key"); then + echo "sysfs to write $key is not avaialbe" + return 1 + fi + if [[ $key == add_host ]]; then + add_host_value=${value} + else + echo "restore $path" >> /tmp/debug + echo -n "$value" > "$path" + fi + done + + echo "${add_host_value}" > ${SD_PSEUDO_PATH}/add_host + SCSI_DEBUG_ADD_HOST_RESTORE_VALUE="-${add_host_value}" + + udevadm settle + + _setup_scsi_debug_vars +} + _exit_scsi_debug() { + local path value + unset SCSI_DEBUG_HOSTS unset SCSI_DEBUG_TARGETS unset SCSI_DEBUG_DEVICES udevadm settle - modprobe -r scsi_debug + + if _module_file_exists scsi_debug; then + modprobe -r scsi_debug + return + fi + + echo "${SCSI_DEBUG_ADD_HOST_RESTORE_VALUE}" > ${SD_PSEUDO_PATH}/add_host + + # Restore parameters modified in _configure_scsi_debug or during test + for path in "${!ORIG_SCSI_DEBUG_PARAMS[@]}"; do + value=${ORIG_SCSI_DEBUG_PARAMS[$path]} + if [[ "$value" != $(<"$path") ]]; then + echo -n "$value" > "$path" + fi + done + unset ORIG_SCSI_DEBUG_PARAMS }
Signature · 1 line
2.40.0
PATCH v2 5/6 scsi/{004,005}: allow to run with built-in scsi_debug
In reply to Shin'ichiro KawasakiFrom: Shin'ichiro Kawasaki <[email protected]>
To allow the test case run with build-in scsi_debug, replace '_have_module scsi_debug' with _have_scsi_debug, and replace _init_scsi_debug with _configure_scsi_debug.
--- tests/scsi/004 | 4 ++-- tests/scsi/005 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
tests/scsi/004 +2 -2
@@ -18,13 +18,13 @@ DESCRIPTION="ensure repeated TASK SET FULL results in EIO on timing out command" CAN_BE_ZONED=1 requires() { - _have_module scsi_debug + _have_scsi_debug } test() { echo "Running ${TEST_NAME}" - if ! _init_scsi_debug add_host=1 max_luns=1 statistics=1 every_nth=1; then + if ! _configure_scsi_debug max_luns=1 statistics=1 every_nth=1; then return 1 fi echo 5 > "/sys/block/${SCSI_DEBUG_DEVICES[0]}/device/timeout"
tests/scsi/005 +2 -2
@@ -11,7 +11,7 @@ DESCRIPTION="test SCSI device blacklisting" QUICK=1 requires() { - _have_module scsi_debug + _have_scsi_debug _have_module_param scsi_debug inq_vendor }
@@ -33,7 +33,7 @@ test() { for inq in "${inqs[@]}"; do vendor="${inq:0:8}" model="${inq:8:16}" - if ! _init_scsi_debug inq_vendor="$vendor" inq_product="$model"; then + if ! _configure_scsi_debug inq_vendor="$vendor" inq_product="$model"; then continue fi vendor="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/device/vendor")"
Signature · 1 line
2.40.0
PATCH v2 6/6 block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod
In reply to Shin'ichiro KawasakiFrom: Shin'ichiro Kawasaki <[email protected]>
To allow the test cases run with build-in scsi_debug, replace '_have_module scsi_debug' with _have_scsi_debug, and replace _init_scsi_debug with _configure_scsi_debug.
Also to allow block/001 run with built-in sd_mod, replace '_have_module sd_mod' with '_have_kernel_option BLK_DEV_SD'. When sd_mod driver is built-in, /sys/module/sd_mod directory is not created. Then _have_driver() can not detect availability of the driver. Instead, refer the kernel config to check availability of the driver.
--- tests/block/001 | 6 +++--- tests/block/002 | 4 ++-- tests/block/027 | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
tests/block/001 +3 -3
@@ -13,13 +13,13 @@ DESCRIPTION="stress device hotplugging" TIMED=1 requires() { - _have_module scsi_debug - _have_driver sd_mod + _have_scsi_debug + _have_kernel_option BLK_DEV_SD _have_driver sr_mod } stress_scsi_debug() { - if ! _init_scsi_debug "$@"; then + if ! _configure_scsi_debug "$@"; then return fi
tests/block/002 +2 -2
@@ -13,13 +13,13 @@ QUICK=1 requires() { _have_blktrace - _have_module scsi_debug + _have_scsi_debug } test() { echo "Running ${TEST_NAME}" - if ! _init_scsi_debug delay=0; then + if ! _configure_scsi_debug delay=0; then return 1 fi
tests/block/027 +2 -2
@@ -20,12 +20,12 @@ CAN_BE_ZONED=1 requires() { _have_cgroup2_controller io - _have_module scsi_debug + _have_scsi_debug _have_fio } scsi_debug_stress_remove() { - if ! _init_scsi_debug "$@"; then + if ! _configure_scsi_debug "$@"; then return fi
Signature · 1 line
2.40.0
Re: [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod
Looks good,
Quoted 8 lines · Shin'ichiro Kawasaki
From: Shin'ichiro Kawasaki <[email protected]>
In the past, there was an issue related to
scsi_debugmodule unload [1]. At that time, it was suggested to modify blktests not to rely on module load and unload. Based on that discussion, blktests was modified not to load or unloadnull_blkdriver [2][3]. As of today, a number of test cases withnull_blkcan be run with built-innull_blk.
Quoted 4 lines
This series introduces similar support for built-in
scsi_debug. This patch adds a new helper function_configure_scsi_debugwhich can set upscsi_debugdevice without module load and unload. Also it enables 5 test cases to run with built- inscsi_debug.
FYI, I've applied this series with some more improvements in the 4th patch.
Quoted 5 lines
Of note is that still srp test group and 9 test cases in other test groups are left to require loadable
scsi_debug. The srp test group and 8 of the 9 test cases can not be run with built-inscsi_debugbecause the parameters they set are read-only on sysfs. The other one test case scsi/007 has other failure symptom now, so I leave it untouched at this moment.
I plan to work further on the 9 left test cases.