selftests: ublk: track created devices for per-test cleanup

Track device IDs in UBLK_DEVS array when created. Update
_cleanup_test() to only delete devices created by this test
instead of using 'del -a' which removes all devices.

This prepares for running tests concurrently where each test
should only clean up its own devices.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Ming Lei 2026-02-01 00:23:35 +08:00 committed by Jens Axboe
parent 92734a4f3a
commit 2021e6109d

View File

@ -164,7 +164,12 @@ _check_add_dev()
}
_cleanup_test() {
"${UBLK_PROG}" del -a
if [ -f "${UBLK_TEST_DIR}/.ublk_devs" ]; then
while read -r dev_id; do
${UBLK_PROG} del -n "${dev_id}"
done < "${UBLK_TEST_DIR}/.ublk_devs"
rm -f "${UBLK_TEST_DIR}/.ublk_devs"
fi
_remove_files
rmdir ${UBLK_TEST_DIR}
@ -205,6 +210,7 @@ _create_ublk_dev() {
fi
if [[ "$dev_id" =~ ^[0-9]+$ ]]; then
echo "$dev_id" >> "${UBLK_TEST_DIR}/.ublk_devs"
echo "${dev_id}"
else
return 255
@ -276,6 +282,11 @@ _ublk_del_dev() {
local dev_id=$1
${UBLK_PROG} del -n "${dev_id}"
# Remove from tracking file
if [ -f "${UBLK_TEST_DIR}/.ublk_devs" ]; then
sed -i "/^${dev_id}$/d" "${UBLK_TEST_DIR}/.ublk_devs"
fi
}
__remove_ublk_dev_return() {