Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ublk: add stress test for covering IO vs. killing ublk server

Add stress_test_01 for running IO vs. killing ublk server, so io_uring exit &
cancel code path can be covered, same with ublk's cancel code path.

Especially IO buffer lifetime is one big thing for ublk zero copy, the added
test can verify if this area works as expected.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250303124324.3563605-11-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
af83ccc7 c60ac48e

+78 -1
+1
tools/testing/selftests/ublk/Makefile
··· 10 10 TEST_PROGS += test_loop_04.sh 11 11 12 12 TEST_PROGS += test_stress_01.sh 13 + TEST_PROGS += test_stress_02.sh 13 14 14 15 TEST_GEN_PROGS_EXTENDED = kublk 15 16
+29
tools/testing/selftests/ublk/test_common.sh
··· 155 155 echo "${dev_id}" 156 156 } 157 157 158 + # kill the ublk daemon and return ublk device state 159 + __ublk_kill_daemon() 160 + { 161 + local dev_id=$1 162 + local exp_state=$2 163 + local daemon_pid 164 + local state 165 + 166 + daemon_pid=$(_get_ublk_daemon_pid "${dev_id}") 167 + state=$(_get_ublk_dev_state "${dev_id}") 168 + 169 + for ((j=0;j<50;j++)); do 170 + [ "$state" == "$exp_state" ] && break 171 + kill -9 "$daemon_pid" > /dev/null 2>&1 172 + sleep 1 173 + state=$(_get_ublk_dev_state "${dev_id}") 174 + done 175 + echo "$state" 176 + } 177 + 158 178 __remove_ublk_dev_return() { 159 179 local dev_id=$1 160 180 ··· 188 168 { 189 169 local dev_id=$1 190 170 local size=$2 171 + local kill_server=$3 191 172 192 173 fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \ 193 174 --rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \ 194 175 --runtime=20 --time_based > /dev/null 2>&1 & 195 176 sleep 2 177 + if [ "${kill_server}" = "yes" ]; then 178 + local state 179 + state=$(__ublk_kill_daemon "${dev_id}" "DEAD") 180 + if [ "$state" != "DEAD" ]; then 181 + echo "device isn't dead($state) after killing daemon" 182 + return 255 183 + fi 184 + fi 196 185 if ! __remove_ublk_dev_return "${dev_id}"; then 197 186 echo "delete dev ${dev_id} failed" 198 187 return 255
+1 -1
tools/testing/selftests/ublk/test_stress_01.sh
··· 18 18 _check_add_dev $TID $? "${backfile}" 19 19 20 20 echo "run ublk IO vs. remove device(ublk add $*)" 21 - if ! __run_io_and_remove "${DEV_ID}" "${size}"; then 21 + if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then 22 22 echo "/dev/ublkc${DEV_ID} isn't removed" 23 23 _remove_backfile "${backfile}" 24 24 exit 255
+47
tools/testing/selftests/ublk/test_stress_02.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + . test_common.sh 5 + TID="stress_02" 6 + ERR_CODE=0 7 + DEV_ID=-1 8 + 9 + ublk_io_and_kill_daemon() 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 kill ublk server(ublk add $*)" 21 + if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then 22 + echo "/dev/ublkc${DEV_ID} isn't removed res ${res}" 23 + _remove_backfile "${backfile}" 24 + exit 255 25 + fi 26 + } 27 + 28 + _prep_test "stress" "run IO and kill ublk server" 29 + 30 + ublk_io_and_kill_daemon 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_kill_daemon 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_kill_daemon 256M -t loop -z "${BACK_FILE}" 44 + ERR_CODE=$? 45 + _cleanup_test "stress" 46 + _remove_backfile "${BACK_FILE}" 47 + _show_result $TID $ERR_CODE