[blktests] tests/srp/014: Add a test that triggers a SCSI reset while I/O is ongoing
diff mbox series

Message ID 20190801220937.133392-1-bvanassche@acm.org
State New
Headers show
Series
  • [blktests] tests/srp/014: Add a test that triggers a SCSI reset while I/O is ongoing
Related show

Commit Message

Bart Van Assche Aug. 1, 2019, 10:09 p.m. UTC
This test triggers the task management function handling code in the SRP
initiator and target drivers. This test verifies the following kernel
patch: fd5614124406 ("scsi: RDMA/srp: Fix a sleep-in-invalid-context
bug") # v5.3.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---

A note regarding the copyright notice: I wrote this patch more than a year
ago. Hence the copyright attribution to Western Digital.

 tests/srp/014     | 104 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/srp/014.out |   2 +
 2 files changed, 106 insertions(+)
 create mode 100755 tests/srp/014
 create mode 100644 tests/srp/014.out

Comments

Omar Sandoval Aug. 7, 2019, 12:11 a.m. UTC | #1
On Thu, Aug 01, 2019 at 03:09:37PM -0700, Bart Van Assche wrote:

Hi, Bart, a few comments.

> This test triggers the task management function handling code in the SRP
> initiator and target drivers. This test verifies the following kernel
> patch: fd5614124406 ("scsi: RDMA/srp: Fix a sleep-in-invalid-context
> bug") # v5.3.

The commit reference belongs in the test file itself (see, e.g.,
block/001).

> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> 
> A note regarding the copyright notice: I wrote this patch more than a year
> ago. Hence the copyright attribution to Western Digital.
> 
>  tests/srp/014     | 104 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/srp/014.out |   2 +
>  2 files changed, 106 insertions(+)
>  create mode 100755 tests/srp/014
>  create mode 100644 tests/srp/014.out

> diff --git a/tests/srp/014 b/tests/srp/014
> new file mode 100755
> index 000000000000..bc2e844abdd2
> --- /dev/null
> +++ b/tests/srp/014
> @@ -0,0 +1,104 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0+
> +# Copyright (c) 2016-2018 Western Digital Corporation or its affiliates
> +
> +. tests/srp/rc
> +
> +DESCRIPTION="Run sg_reset while I/O is ongoing"
> +TIMED=1
> +

[snip]

> +test_sg_reset() {
> +	local dev fio_status m job jobfile
> +
> +	use_blk_mq y y || return $?
> +	dev=$(get_bdev 0) || return $?
> +	sg_reset_loop "$dev" "$TIMEOUT" &

TIMEOUT is only set if the user configured it, so you should set a
default (see block/001).

> +	jobfile=$(mktemp)
> +	# Redirect stderr to suppress the bash "Terminated" message.
> +	(set_running_loop "$dev" 2>/dev/null & echo $! > "$jobfile")

Why is the subshell/jobfile necessary here? The following seems to work,
am I missing something?

	set_running_loop "$dev" 2>/dev/null &
	job=$!

Thanks!

> +	job=$(<"$jobfile")
> +	rm -f "$jobfile"
> +	run_fio --verify=md5 --rw=randwrite --bs=64K --loops=$((10**6)) \
> +		--iodepth=16 --group_reporting --sync=1 --direct=1 \
> +		--ioengine=libaio --runtime="${TIMEOUT}" \
> +		--filename="$dev" --name=sg-reset-test --thread --numjobs=1 \
> +		--output="${RESULTS_DIR}/srp/fio-output-014.txt" \
> +		>>"$FULL"
> +	fio_status=$?
> +	kill "$job"
> +	make_all_running "$dev"
> +	wait
> +	return $fio_status
> +}
> +
> +test() {
> +	trap 'trap "" EXIT; teardown' EXIT
> +	setup && test_sg_reset && echo Passed
> +}
> diff --git a/tests/srp/014.out b/tests/srp/014.out
> new file mode 100644
> index 000000000000..5e25d8e8672d
> --- /dev/null
> +++ b/tests/srp/014.out
> @@ -0,0 +1,2 @@
> +Configured SRP target driver
> +Passed
> -- 
> 2.22.0.770.g0f2c4a37fd-goog
>

Patch
diff mbox series

diff --git a/tests/srp/014 b/tests/srp/014
new file mode 100755
index 000000000000..bc2e844abdd2
--- /dev/null
+++ b/tests/srp/014
@@ -0,0 +1,104 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2016-2018 Western Digital Corporation or its affiliates
+
+. tests/srp/rc
+
+DESCRIPTION="Run sg_reset while I/O is ongoing"
+TIMED=1
+
+# $1: SCSI device of which to change the state to running, e.g. sdc.
+make_running() {
+	local dev=$1 sp state
+
+	for sp in /sys/class/scsi_device/*/device/block/"$dev"; do
+		if [ -e "$sp" ]; then
+			break
+		else
+			return 1
+		fi
+	done
+	sp=$(dirname "$(dirname "$sp")")/state
+	# If the SCSI error handler changed the device state to offline,
+	# change the state back to running.
+	state=$(<"$sp")
+	if [ "$state" = offline ]; then
+		echo running > "$sp"
+		echo "$dev: state $state -> running" >>"$FULL"
+	else
+		echo "$dev: state $state" >>"$FULL"
+	fi
+}
+
+# $1: dm device to examine, e.g.
+# /dev/disk/by-id/dm-uuid-mpath-360014056e756c6c62300000000000000
+make_all_running() {
+	local d h dev=$1
+
+	while [ -L "$dev" ]; do
+		dev=$(realpath "$dev")
+	done
+	dev=${dev#/dev/}
+	for h in /sys/class/block/*/holders/"$dev"; do
+		[ -e "$h" ] || continue
+		d=$(basename "$(dirname "$(dirname "$h")")")
+		make_running "$d"
+	done
+}
+
+# $1: dm device to act on.
+set_running_loop() {
+	local dev="$1"
+
+	[ -e "$dev" ] || return $?
+	while true; do
+		sleep 1
+		make_all_running "$dev"
+	done
+	echo "set_running_loop $dev finished" >>"$FULL"
+}
+
+# $1: dm device to reset periodically; $2: how long the reset loop should run.
+sg_reset_loop() {
+	local cmd dev="$1" duration="$2" deadline i=0 reset_type
+
+	[ -e "$dev" ] || return $?
+	[ -n "$duration" ] || return $?
+	reset_type=(-d -b)
+	deadline=$(($(uptime_s) + duration))
+	while true; do
+		sleep_until 1 ${deadline} || break
+		cmd="sg_reset --no-esc ${reset_type[i++ % 2]} $dev"
+		{ echo "+ $cmd"; eval "$cmd"; } >>"$FULL" 2>&1
+	done
+	echo "sg_reset_loop $dev finished" >>"$FULL"
+}
+
+test_sg_reset() {
+	local dev fio_status m job jobfile
+
+	use_blk_mq y y || return $?
+	dev=$(get_bdev 0) || return $?
+	sg_reset_loop "$dev" "$TIMEOUT" &
+	jobfile=$(mktemp)
+	# Redirect stderr to suppress the bash "Terminated" message.
+	(set_running_loop "$dev" 2>/dev/null & echo $! > "$jobfile")
+	job=$(<"$jobfile")
+	rm -f "$jobfile"
+	run_fio --verify=md5 --rw=randwrite --bs=64K --loops=$((10**6)) \
+		--iodepth=16 --group_reporting --sync=1 --direct=1 \
+		--ioengine=libaio --runtime="${TIMEOUT}" \
+		--filename="$dev" --name=sg-reset-test --thread --numjobs=1 \
+		--output="${RESULTS_DIR}/srp/fio-output-014.txt" \
+		>>"$FULL"
+	fio_status=$?
+	kill "$job"
+	make_all_running "$dev"
+	wait
+	return $fio_status
+}
+
+test() {
+	trap 'trap "" EXIT; teardown' EXIT
+	setup && test_sg_reset && echo Passed
+}
diff --git a/tests/srp/014.out b/tests/srp/014.out
new file mode 100644
index 000000000000..5e25d8e8672d
--- /dev/null
+++ b/tests/srp/014.out
@@ -0,0 +1,2 @@ 
+Configured SRP target driver
+Passed