From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Caleb Sander Mateos <csander@purestorage.com>,
Uday Shankar <ushankar@purestorage.com>,
Alexander Atanasov <alex@zazolabs.com>,
linux-kselftest@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 3/9] selftests: ublk: add _ublk_del_dev helper function
Date: Sun, 1 Feb 2026 00:23:34 +0800 [thread overview]
Message-ID: <20260131162342.13872-4-ming.lei@redhat.com> (raw)
In-Reply-To: <20260131162342.13872-1-ming.lei@redhat.com>
Add _ublk_del_dev() to delete a specific ublk device by ID and
use it in all test scripts instead of calling UBLK_PROG directly.
Also remove unused _remove_ublk_devices() function.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
tools/testing/selftests/ublk/test_common.sh | 13 +++++++------
tools/testing/selftests/ublk/test_generic_16.sh | 4 ++--
tools/testing/selftests/ublk/test_null_04.sh | 8 ++++----
tools/testing/selftests/ublk/test_part_02.sh | 4 ++--
4 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh
index 8d298a7ee7b1..0f1fdb0892b4 100755
--- a/tools/testing/selftests/ublk/test_common.sh
+++ b/tools/testing/selftests/ublk/test_common.sh
@@ -106,11 +106,6 @@ _check_root() {
fi
}
-_remove_ublk_devices() {
- ${UBLK_PROG} del -a
- modprobe -r ublk_drv > /dev/null 2>&1
-}
-
_get_ublk_dev_state() {
${UBLK_PROG} list -n "$1" | grep "state" | awk '{print $11}'
}
@@ -277,10 +272,16 @@ __ublk_kill_daemon()
echo "$state"
}
-__remove_ublk_dev_return() {
+_ublk_del_dev() {
local dev_id=$1
${UBLK_PROG} del -n "${dev_id}"
+}
+
+__remove_ublk_dev_return() {
+ local dev_id=$1
+
+ _ublk_del_dev "${dev_id}"
local res=$?
udevadm settle
return ${res}
diff --git a/tools/testing/selftests/ublk/test_generic_16.sh b/tools/testing/selftests/ublk/test_generic_16.sh
index 42e8d2e16ec9..3ef367836ac5 100755
--- a/tools/testing/selftests/ublk/test_generic_16.sh
+++ b/tools/testing/selftests/ublk/test_generic_16.sh
@@ -24,7 +24,7 @@ if ! ${UBLK_PROG} stop -n "${dev_id}" --safe; then
fi
# Clean up device
-${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
+_ublk_del_dev "${dev_id}" > /dev/null 2>&1
udevadm settle
# Test 2: stop --safe on device with active opener should fail
@@ -49,7 +49,7 @@ kill $dd_pid 2>/dev/null
wait $dd_pid 2>/dev/null
# Now device should be idle, regular delete should work
-${UBLK_PROG} del -n "${dev_id}"
+_ublk_del_dev "${dev_id}"
udevadm settle
_cleanup_test "null"
diff --git a/tools/testing/selftests/ublk/test_null_04.sh b/tools/testing/selftests/ublk/test_null_04.sh
index a5599d38583a..6713b280a6ff 100755
--- a/tools/testing/selftests/ublk/test_null_04.sh
+++ b/tools/testing/selftests/ublk/test_null_04.sh
@@ -34,7 +34,7 @@ _test_metadata_only() {
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
- ${UBLK_PROG} del -n "${dev_id}"
+ _ublk_del_dev "${dev_id}"
}
_test_integrity_capable_ip() {
@@ -53,7 +53,7 @@ _test_integrity_capable_ip() {
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
- ${UBLK_PROG} del -n "${dev_id}"
+ _ublk_del_dev "${dev_id}"
}
_test_integrity_reftag_t10dif() {
@@ -72,7 +72,7 @@ _test_integrity_reftag_t10dif() {
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
- ${UBLK_PROG} del -n "${dev_id}"
+ _ublk_del_dev "${dev_id}"
}
_test_nvme_csum() {
@@ -91,7 +91,7 @@ _test_nvme_csum() {
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 8
- ${UBLK_PROG} del -n "${dev_id}"
+ _ublk_del_dev "${dev_id}"
}
_prep_test "null" "integrity params"
diff --git a/tools/testing/selftests/ublk/test_part_02.sh b/tools/testing/selftests/ublk/test_part_02.sh
index 727d0f4610d6..acd098deda3a 100755
--- a/tools/testing/selftests/ublk/test_part_02.sh
+++ b/tools/testing/selftests/ublk/test_part_02.sh
@@ -46,13 +46,13 @@ _test_partition_scan_no_hang()
if [ "$state" != "${expected_state}" ]; then
echo "FAIL: Device state is $state, expected ${expected_state}"
ERR_CODE=255
- ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
+ _ublk_del_dev "${dev_id}" > /dev/null 2>&1
return
fi
echo "PASS: Device transitioned to ${expected_state} in ${elapsed}s without hanging"
# Clean up the device
- ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
+ _ublk_del_dev "${dev_id}" > /dev/null 2>&1
}
_prep_test "partition_scan" "verify async partition scan prevents IO hang"
--
2.47.0
next prev parent reply other threads:[~2026-01-31 16:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 16:23 [PATCH 0/9] selftests: ublk: test infrastructure improvements Ming Lei
2026-01-31 16:23 ` [PATCH 1/9] selftests: ublk: simplify UBLK_TEST_DIR handling Ming Lei
2026-01-31 16:23 ` [PATCH 2/9] selftests: ublk: refactor test_loop_08 into separate functions Ming Lei
2026-01-31 16:23 ` Ming Lei [this message]
2026-01-31 16:23 ` [PATCH 4/9] selftests: ublk: track created devices for per-test cleanup Ming Lei
2026-01-31 16:23 ` [PATCH 5/9] selftests: ublk: add group-based test targets Ming Lei
2026-01-31 16:23 ` [PATCH 6/9] selftests: ublk: add _ublk_sleep helper for parallel execution Ming Lei
2026-01-31 16:23 ` [PATCH 7/9] selftests: ublk: increase timeouts for parallel test execution Ming Lei
2026-01-31 16:23 ` [PATCH 8/9] selftests: ublk: reorganize tests into integrity and recover groups Ming Lei
2026-01-31 16:23 ` [PATCH 9/9] selftests: ublk: improve I/O ordering test with bpftrace Ming Lei
2026-01-31 21:56 ` [PATCH 0/9] selftests: ublk: test infrastructure improvements Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260131162342.13872-4-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=alex@zazolabs.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=ushankar@purestorage.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox