• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: MIT or GPL-2.0-only
3
4. common/fio_common
5
6echo -e "\ttest nosrv (state after ublk server is killed) and recovery behavior"
7echo -e "\tfor all valid recovery options"
8echo
9
10DD_PID=0
11
12# submit an I/O async and store pid into DD_PID
13submit_io()
14{
15	dd if=$1 of=/dev/null iflag=direct count=1 bs=4k 2>/dev/null &
16	DD_PID=$!
17}
18
19# check the status of the I/O issued by DD_PID
20# 0 - I/O succeeded
21# 1 - I/O error
22# 2 - I/O queued
23check_io_status()
24{
25	sleep 1
26	# if process is still alive after 1 second, I/O is likely queued
27	if ps -p $DD_PID > /dev/null 2>/dev/null; then
28		return 2
29	else
30		if wait $DD_PID; then return 0; else return 1; fi
31	fi
32}
33
34del_dev()
35{
36	sleep 2
37	RES=`__remove_ublk_dev_return $1`
38	if [ $RES -ne 0 ]; then
39		echo -e "\t\tdelete $1 failed"
40		return 1
41	fi
42	wait
43	sleep 3
44}
45
46ublk_run_recovery_test()
47{
48	export T_TYPE_PARAMS="-t null -r $RECOVERY -i $RECOVERY_REISSUE -e $RECOVERY_FAIL_IO"
49	echo -e "\trunning with params: $T_TYPE_PARAMS"
50	DEV=`__create_ublk_dev`
51
52	echo -e "\t\tcheck behavior before nosrv - expect no error"
53	submit_io $DEV
54	check_io_status
55	RES=$?
56	if [ $RES -ne 0 ]; then
57		echo -e "\t\tI/O error while ublk server still up!"
58		return 1
59	fi
60
61	pid1=`__ublk_get_pid $DEV`
62	kill -9 $pid1
63	sleep 2
64	echo -ne "\t\tcheck behavior during nosrv - "
65	submit_io $DEV
66	check_io_status
67	RES=$?
68	if [ $RECOVERY_FAIL_IO -ne 0 ]; then
69		echo "expect I/O error"
70		if [ $RES -ne 1 ]; then
71			echo -e "\t\tincorrect nosrv behavior!"
72			echo -e "\t\texpected io error, got $RES"
73			return 1
74		fi
75	elif [ $RECOVERY -ne 0 ]; then
76		echo "expect I/O queued"
77		if [ $RES -ne 2 ]; then
78			echo -e "\t\tincorrect nosrv behavior!"
79			echo -e "\t\texpected queued io, got $RES"
80			return 1
81		fi
82	else
83		echo "expect I/O error" # because device should be gone
84		if [ $RES -ne 1 ]; then
85			echo -e "\t\tincorrect nosrv behavior!"
86			echo -e "\t\texpected io error, got $RES"
87			return 1
88		fi
89	fi
90
91	echo -e "\t\ttry to recover the device"
92	secs=0
93	while [ $secs -lt 10 ]; do
94		RES=`__recover_ublk_dev $DEV`
95		[ $RES -eq 0 ] && break
96		sleep 1
97		let secs++
98	done
99	if [ $RES -ne 0 ]; then
100		echo -e "\t\tfailed to recover device!"
101		if [ $RECOVERY -ne 0 ]; then
102			return 1
103		else
104			echo -e "\t\tforgiving expected recovery failure"
105			del_dev $DEV
106			echo
107			return 0
108		fi
109	else
110		if [ $RECOVERY -eq 0 ]; then
111			echo -e "\t\trecovery unexpectedly succeeded!"
112			return 1
113		fi
114	fi
115
116	# if I/O queued before, make sure it completes now
117	if [ $RECOVERY_FAIL_IO -eq 0 ] && [ $RECOVERY -ne 0 ]; then
118		echo -e "\t\tchecking that I/O completed after recovery"
119		check_io_status
120		RES=$?
121		if [ $RES -ne 0 ]; then
122			echo -e "\t\tpreviously queued I/O did not succeed!"
123			echo -e "\t\texpected success got $RES"
124			return 1
125		fi
126	fi
127
128	echo -e "\t\tcheck behavior after recovery - expect no error"
129	submit_io $DEV
130	check_io_status
131	RES=$?
132	if [ $RES -ne 0 ]; then
133		echo -e "\t\tI/O error after recovery!"
134		return 1
135	fi
136
137	# cleanup
138	pid2=`__ublk_get_pid $DEV`
139	kill -9 $pid2
140	del_dev $DEV
141
142	echo
143}
144
145RECOVERY=0
146RECOVERY_REISSUE=0
147RECOVERY_FAIL_IO=0
148ublk_run_recovery_test
149
150RECOVERY=1
151RECOVERY_REISSUE=0
152RECOVERY_FAIL_IO=0
153ublk_run_recovery_test
154
155RECOVERY=1
156RECOVERY_REISSUE=1
157RECOVERY_FAIL_IO=0
158ublk_run_recovery_test
159
160RECOVERY=1
161RECOVERY_REISSUE=0
162RECOVERY_FAIL_IO=1
163ublk_run_recovery_test
164