Linux-Block Archive mirror
 help / color / mirror / Atom feed
* [PATCH blktests v2 0/6] support built-in scsi_debug
@ 2023-04-25 11:47 Shin'ichiro Kawasaki
  2023-04-25 11:47 ` [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist Shin'ichiro Kawasaki
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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/bc0b2c10-10e6-a1d9-4139-ac93ad3512b2@interlog.com/
[2] https://lore.kernel.org/linux-block/20220601064837.3473709-1-hch@lst.de/
[3] https://lore.kernel.org/linux-block/20220607124739.1259977-1-hch@lst.de/

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(-)

-- 
2.40.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
@ 2023-04-25 11:47 ` Shin'ichiro Kawasaki
  2023-05-23  9:17   ` Johannes Thumshirn
  2023-04-25 11:47 ` [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug Shin'ichiro Kawasaki
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 common/rc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/rc b/common/rc
index af4c0b1..f67b434 100644
--- a/common/rc
+++ b/common/rc
@@ -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
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
  2023-04-25 11:47 ` [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist Shin'ichiro Kawasaki
@ 2023-04-25 11:47 ` Shin'ichiro Kawasaki
  2023-05-23  9:19   ` Johannes Thumshirn
  2023-04-25 11:47 ` [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars Shin'ichiro Kawasaki
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 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(-)

diff --git a/common/scsi_debug b/common/scsi_debug
index ae13bb6..5f73354 100644
--- a/common/scsi_debug
+++ b/common/scsi_debug
@@ -5,7 +5,7 @@
 # scsi_debug helper functions.
 
 _have_scsi_debug() {
-	_have_module scsi_debug
+	_have_driver scsi_debug
 }
 
 _init_scsi_debug() {
diff --git a/tests/block/001 b/tests/block/001
index fb93932..2ea3754 100755
--- a/tests/block/001
+++ b/tests/block/001
@@ -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
 }
diff --git a/tests/block/002 b/tests/block/002
index 05d00d2..a5f3ee5 100755
--- a/tests/block/002
+++ b/tests/block/002
@@ -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() {
diff --git a/tests/block/009 b/tests/block/009
index df36edb..d3ea42a 100755
--- a/tests/block/009
+++ b/tests/block/009
@@ -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() {
diff --git a/tests/block/025 b/tests/block/025
index f746c1c..4c48e9f 100755
--- a/tests/block/025
+++ b/tests/block/025
@@ -12,7 +12,7 @@
 DESCRIPTION="do a huge discard with 4k sector size"
 
 requires() {
-	_have_scsi_debug
+	_have_module scsi_debug
 }
 
 test() {
diff --git a/tests/block/027 b/tests/block/027
index b60f62c..ab6369b 100755
--- a/tests/block/027
+++ b/tests/block/027
@@ -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() {
diff --git a/tests/block/028 b/tests/block/028
index 5140d94..13b3278 100755
--- a/tests/block/028
+++ b/tests/block/028
@@ -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() {
diff --git a/tests/block/032 b/tests/block/032
index b07b7ab..8975879 100755
--- a/tests/block/032
+++ b/tests/block/032
@@ -13,7 +13,8 @@ DESCRIPTION="remove one mounted device"
 QUICK=1
 
 requires() {
-	_have_xfs && _have_scsi_debug
+	_have_xfs
+	_have_module scsi_debug
 }
 
 test() {
diff --git a/tests/loop/004 b/tests/loop/004
index fab34e8..ca52d80 100755
--- a/tests/loop/004
+++ b/tests/loop/004
@@ -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() {
diff --git a/tests/scsi/004 b/tests/scsi/004
index b5ef2dd..f0845c1 100755
--- a/tests/scsi/004
+++ b/tests/scsi/004
@@ -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() {
diff --git a/tests/scsi/005 b/tests/scsi/005
index 22fb495..efd3d82 100755
--- a/tests/scsi/005
+++ b/tests/scsi/005
@@ -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() {
diff --git a/tests/scsi/007 b/tests/scsi/007
index e7088a1..547a735 100755
--- a/tests/scsi/007
+++ b/tests/scsi/007
@@ -12,7 +12,7 @@ DESCRIPTION="Trigger the SCSI error handler"
 QUICK=1
 
 requires() {
-	_have_scsi_debug
+	_have_module scsi_debug
 }
 
 config_hz() {
diff --git a/tests/zbd/008 b/tests/zbd/008
index c625bad..55b5b6c 100755
--- a/tests/zbd/008
+++ b/tests/zbd/008
@@ -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() {
diff --git a/tests/zbd/009 b/tests/zbd/009
index 483cbf6..c0ce1f2 100755
--- a/tests/zbd/009
+++ b/tests/zbd/009
@@ -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
 }
 
diff --git a/tests/zbd/010 b/tests/zbd/010
index 35143b8..c5cb76a 100755
--- a/tests/zbd/010
+++ b/tests/zbd/010
@@ -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() {
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
  2023-04-25 11:47 ` [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist Shin'ichiro Kawasaki
  2023-04-25 11:47 ` [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug Shin'ichiro Kawasaki
@ 2023-04-25 11:47 ` Shin'ichiro Kawasaki
  2023-05-23  9:21   ` Johannes Thumshirn
  2023-04-25 11:47 ` [PATCH blktests v2 4/6] common/scsi_debug: introduce _configure_scsi_debug Shin'ichiro Kawasaki
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 common/scsi_debug | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/common/scsi_debug b/common/scsi_debug
index 5f73354..0bf768a 100644
--- a/common/scsi_debug
+++ b/common/scsi_debug
@@ -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
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 4/6] common/scsi_debug: introduce _configure_scsi_debug
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
                   ` (2 preceding siblings ...)
  2023-04-25 11:47 ` [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars Shin'ichiro Kawasaki
@ 2023-04-25 11:47 ` Shin'ichiro Kawasaki
  2023-04-25 11:47 ` [PATCH blktests v2 5/6] scsi/{004,005}: allow to run with built-in scsi_debug Shin'ichiro Kawasaki
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/scsi_debug | 112 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 111 insertions(+), 1 deletion(-)

diff --git a/common/scsi_debug b/common/scsi_debug
index 0bf768a..3d83d8a 100644
--- a/common/scsi_debug
+++ b/common/scsi_debug
@@ -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
 }
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 5/6] scsi/{004,005}: allow to run with built-in scsi_debug
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
                   ` (3 preceding siblings ...)
  2023-04-25 11:47 ` [PATCH blktests v2 4/6] common/scsi_debug: introduce _configure_scsi_debug Shin'ichiro Kawasaki
@ 2023-04-25 11:47 ` Shin'ichiro Kawasaki
  2023-04-26 10:06 ` [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod Shin'ichiro Kawasaki
  2023-05-23  8:37 ` [PATCH blktests v2 0/6] support built-in scsi_debug Shinichiro Kawasaki
  6 siblings, 0 replies; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-25 11:47 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 tests/scsi/004 | 4 ++--
 tests/scsi/005 | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/scsi/004 b/tests/scsi/004
index f0845c1..7d0af54 100755
--- a/tests/scsi/004
+++ b/tests/scsi/004
@@ -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"
diff --git a/tests/scsi/005 b/tests/scsi/005
index efd3d82..bfa1014 100755
--- a/tests/scsi/005
+++ b/tests/scsi/005
@@ -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")"
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
                   ` (4 preceding siblings ...)
  2023-04-25 11:47 ` [PATCH blktests v2 5/6] scsi/{004,005}: allow to run with built-in scsi_debug Shin'ichiro Kawasaki
@ 2023-04-26 10:06 ` Shin'ichiro Kawasaki
  2023-05-23  9:22   ` Johannes Thumshirn
  2023-05-23  8:37 ` [PATCH blktests v2 0/6] support built-in scsi_debug Shinichiro Kawasaki
  6 siblings, 1 reply; 12+ messages in thread
From: Shin'ichiro Kawasaki @ 2023-04-26 10:06 UTC (permalink / raw
  To: linux-block, linux-scsi
  Cc: Chaitanya Kulkarni, Shin'ichiro Kawasaki,
	Shin'ichiro Kawasaki

From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 tests/block/001 | 6 +++---
 tests/block/002 | 4 ++--
 tests/block/027 | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/block/001 b/tests/block/001
index 2ea3754..32dd22f 100755
--- a/tests/block/001
+++ b/tests/block/001
@@ -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
 
diff --git a/tests/block/002 b/tests/block/002
index a5f3ee5..b16d014 100755
--- a/tests/block/002
+++ b/tests/block/002
@@ -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
 
diff --git a/tests/block/027 b/tests/block/027
index ab6369b..a79a115 100755
--- a/tests/block/027
+++ b/tests/block/027
@@ -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
 
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH blktests v2 0/6] support built-in scsi_debug
  2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
                   ` (5 preceding siblings ...)
  2023-04-26 10:06 ` [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod Shin'ichiro Kawasaki
@ 2023-05-23  8:37 ` Shinichiro Kawasaki
  6 siblings, 0 replies; 12+ messages in thread
From: Shinichiro Kawasaki @ 2023-05-23  8:37 UTC (permalink / raw
  To: Shin'ichiro Kawasaki
  Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	Chaitanya Kulkarni

On Apr 25, 2023 / 20:47, Shin'ichiro Kawasaki wrote:
> From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> 
> 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.

FYI, I've applied this series with some more improvements in the 4th patch.

> 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.

I plan to work further on the 9 left test cases.

> 
> [1] https://lore.kernel.org/linux-block/bc0b2c10-10e6-a1d9-4139-ac93ad3512b2@interlog.com/
> [2] https://lore.kernel.org/linux-block/20220601064837.3473709-1-hch@lst.de/
> [3] https://lore.kernel.org/linux-block/20220607124739.1259977-1-hch@lst.de/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist
  2023-04-25 11:47 ` [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist Shin'ichiro Kawasaki
@ 2023-05-23  9:17   ` Johannes Thumshirn
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2023-05-23  9:17 UTC (permalink / raw
  To: Shin'ichiro Kawasaki, linux-block@vger.kernel.org,
	linux-scsi@vger.kernel.org
  Cc: Chaitanya Kulkarni, Shinichiro Kawasaki

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug
  2023-04-25 11:47 ` [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug Shin'ichiro Kawasaki
@ 2023-05-23  9:19   ` Johannes Thumshirn
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2023-05-23  9:19 UTC (permalink / raw
  To: Shin'ichiro Kawasaki, linux-block@vger.kernel.org,
	linux-scsi@vger.kernel.org
  Cc: Chaitanya Kulkarni, Shinichiro Kawasaki

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars
  2023-04-25 11:47 ` [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars Shin'ichiro Kawasaki
@ 2023-05-23  9:21   ` Johannes Thumshirn
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2023-05-23  9:21 UTC (permalink / raw
  To: Shin'ichiro Kawasaki, linux-block@vger.kernel.org,
	linux-scsi@vger.kernel.org
  Cc: Chaitanya Kulkarni, Shinichiro Kawasaki

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod
  2023-04-26 10:06 ` [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod Shin'ichiro Kawasaki
@ 2023-05-23  9:22   ` Johannes Thumshirn
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2023-05-23  9:22 UTC (permalink / raw
  To: Shin'ichiro Kawasaki, linux-block@vger.kernel.org,
	linux-scsi@vger.kernel.org
  Cc: Chaitanya Kulkarni, Shinichiro Kawasaki

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-23  9:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 11:47 [PATCH blktests v2 0/6] support built-in scsi_debug Shin'ichiro Kawasaki
2023-04-25 11:47 ` [PATCH blktests v2 1/6] common/rc: skip module file check if modules path does not exist Shin'ichiro Kawasaki
2023-05-23  9:17   ` Johannes Thumshirn
2023-04-25 11:47 ` [PATCH blktests v2 2/6] common/scsi_debug, tests/*: re-define _have_scsi_debug Shin'ichiro Kawasaki
2023-05-23  9:19   ` Johannes Thumshirn
2023-04-25 11:47 ` [PATCH blktests v2 3/6] common/scsi_debug: factor out _setup_scsi_debug_vars Shin'ichiro Kawasaki
2023-05-23  9:21   ` Johannes Thumshirn
2023-04-25 11:47 ` [PATCH blktests v2 4/6] common/scsi_debug: introduce _configure_scsi_debug Shin'ichiro Kawasaki
2023-04-25 11:47 ` [PATCH blktests v2 5/6] scsi/{004,005}: allow to run with built-in scsi_debug Shin'ichiro Kawasaki
2023-04-26 10:06 ` [PATCH blktests v2 6/6] block/{001,002,027}: allow to run with built-in scsi_debug and sd_mod Shin'ichiro Kawasaki
2023-05-23  9:22   ` Johannes Thumshirn
2023-05-23  8:37 ` [PATCH blktests v2 0/6] support built-in scsi_debug Shinichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).