xref: /linux/tools/testing/selftests/ublk/test_stress_05.sh (revision 6d8854216ebb60959ddb6f4ea4123bd449ba6cf6)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5TID="stress_05"
6ERR_CODE=0
7
8run_io_and_remove()
9{
10	local size=$1
11	local dev_id
12	local dev_pid
13	shift 1
14
15	dev_id=$(_add_ublk_dev "$@")
16	_check_add_dev $TID $?
17
18	[ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs. remove device(ublk add $*)"
19
20	fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \
21		--rw=readwrite --iodepth=128 --size="${size}" --numjobs=4 \
22		--runtime=40 --time_based > /dev/null 2>&1 &
23	sleep 4
24
25	dev_pid=$(_get_ublk_daemon_pid "$dev_id")
26	kill -9 "$dev_pid"
27
28	if ! __remove_ublk_dev_return "${dev_id}"; then
29		echo "delete dev ${dev_id} failed"
30		return 255
31	fi
32}
33
34ublk_io_and_remove()
35{
36	run_io_and_remove "$@"
37	ERR_CODE=$?
38	if [ ${ERR_CODE} -ne 0 ]; then
39		echo "$TID failure: $*"
40		_show_result $TID $ERR_CODE
41	fi
42}
43
44_prep_test "stress" "run IO and remove device with recovery enabled"
45
46_create_backfile 0 256M
47_create_backfile 1 256M
48
49for reissue in $(seq 0 1); do
50	ublk_io_and_remove 8G -t null -q 4 -g -r 1 -i "$reissue" &
51	ublk_io_and_remove 256M -t loop -q 4 -g -r 1 -i "$reissue" "${UBLK_BACKFILES[0]}" &
52	wait
53done
54
55if _have_feature "ZERO_COPY"; then
56	for reissue in $(seq 0 1); do
57		ublk_io_and_remove 8G -t null -q 4 -g -z -r 1 -i "$reissue" &
58		ublk_io_and_remove 256M -t loop -q 4 -g -z -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" &
59		wait
60	done
61fi
62
63if _have_feature "AUTO_BUF_REG"; then
64	for reissue in $(seq 0 1); do
65		ublk_io_and_remove 8G -t null -q 4 -g --auto_zc -r 1 -i "$reissue" &
66		ublk_io_and_remove 256M -t loop -q 4 -g --auto_zc -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" &
67		ublk_io_and_remove 8G -t null -q 4 -g -z --auto_zc --auto_zc_fallback -r 1 -i "$reissue" &
68		wait
69	done
70fi
71
72if _have_feature "PER_IO_DAEMON"; then
73	ublk_io_and_remove 8G -t null -q 4 --nthreads 8 --per_io_tasks -r 1 -i "$reissue" &
74	ublk_io_and_remove 256M -t loop -q 4 --nthreads 8 --per_io_tasks -r 1 -i "$reissue" "${UBLK_BACKFILES[0]}" &
75	ublk_io_and_remove 8G -t null -q 4 --nthreads 8 --per_io_tasks -r 1 -i "$reissue"  &
76fi
77wait
78
79_cleanup_test "stress"
80_show_result $TID $ERR_CODE
81