Skip to content

Commit c60ac48

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add one stress test for covering IO vs. removing device
Add stress_test_01 for running IO vs. removing device for verifying that ublk device removal can work as expected when heavy IO workloads are in progress. null, loop and loop/zc are covered in this tests. Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250303124324.3563605-10-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 87a9265 commit c60ac48

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ TEST_PROGS += test_loop_02.sh
99
TEST_PROGS += test_loop_03.sh
1010
TEST_PROGS += test_loop_04.sh
1111

12+
TEST_PROGS += test_stress_01.sh
13+
1214
TEST_GEN_PROGS_EXTENDED = kublk
1315

1416
include ../lib.mk

tools/testing/selftests/ublk/test_common.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,31 @@ _add_ublk_dev() {
155155
echo "${dev_id}"
156156
}
157157

158+
__remove_ublk_dev_return() {
159+
local dev_id=$1
160+
161+
${UBLK_PROG} del -n "${dev_id}"
162+
local res=$?
163+
udevadm settle
164+
return ${res}
165+
}
166+
167+
__run_io_and_remove()
168+
{
169+
local dev_id=$1
170+
local size=$2
171+
172+
fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \
173+
--rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \
174+
--runtime=20 --time_based > /dev/null 2>&1 &
175+
sleep 2
176+
if ! __remove_ublk_dev_return "${dev_id}"; then
177+
echo "delete dev ${dev_id} failed"
178+
return 255
179+
fi
180+
wait
181+
}
182+
183+
158184
UBLK_PROG=$(pwd)/kublk
159185
export UBLK_PROG
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. test_common.sh
5+
TID="stress_01"
6+
ERR_CODE=0
7+
DEV_ID=-1
8+
9+
ublk_io_and_remove()
10+
{
11+
local size=$1
12+
shift 1
13+
local backfile=""
14+
if echo "$@" | grep -q "loop"; then
15+
backfile=${*: -1}
16+
fi
17+
DEV_ID=$(_add_ublk_dev "$@")
18+
_check_add_dev $TID $? "${backfile}"
19+
20+
echo "run ublk IO vs. remove device(ublk add $*)"
21+
if ! __run_io_and_remove "${DEV_ID}" "${size}"; then
22+
echo "/dev/ublkc${DEV_ID} isn't removed"
23+
_remove_backfile "${backfile}"
24+
exit 255
25+
fi
26+
}
27+
28+
_prep_test "stress" "run IO and remove device"
29+
30+
ublk_io_and_remove 8G -t null
31+
ERR_CODE=$?
32+
if [ ${ERR_CODE} -ne 0 ]; then
33+
_show_result $TID $ERR_CODE
34+
fi
35+
36+
BACK_FILE=$(_create_backfile 256M)
37+
ublk_io_and_remove 256M -t loop "${BACK_FILE}"
38+
ERR_CODE=$?
39+
if [ ${ERR_CODE} -ne 0 ]; then
40+
_show_result $TID $ERR_CODE
41+
fi
42+
43+
ublk_io_and_remove 256M -t loop -z "${BACK_FILE}"
44+
ERR_CODE=$?
45+
_cleanup_test "stress"
46+
_remove_backfile "${BACK_FILE}"
47+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)