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