Skip to content

Commit 92734a4

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add _ublk_del_dev helper function
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> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 842b652 commit 92734a4

4 files changed

Lines changed: 15 additions & 14 deletions

File tree

tools/testing/selftests/ublk/test_common.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ _check_root() {
106106
fi
107107
}
108108

109-
_remove_ublk_devices() {
110-
${UBLK_PROG} del -a
111-
modprobe -r ublk_drv > /dev/null 2>&1
112-
}
113-
114109
_get_ublk_dev_state() {
115110
${UBLK_PROG} list -n "$1" | grep "state" | awk '{print $11}'
116111
}
@@ -277,10 +272,16 @@ __ublk_kill_daemon()
277272
echo "$state"
278273
}
279274

280-
__remove_ublk_dev_return() {
275+
_ublk_del_dev() {
281276
local dev_id=$1
282277

283278
${UBLK_PROG} del -n "${dev_id}"
279+
}
280+
281+
__remove_ublk_dev_return() {
282+
local dev_id=$1
283+
284+
_ublk_del_dev "${dev_id}"
284285
local res=$?
285286
udevadm settle
286287
return ${res}

tools/testing/selftests/ublk/test_generic_16.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if ! ${UBLK_PROG} stop -n "${dev_id}" --safe; then
2424
fi
2525

2626
# Clean up device
27-
${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
27+
_ublk_del_dev "${dev_id}" > /dev/null 2>&1
2828
udevadm settle
2929

3030
# Test 2: stop --safe on device with active opener should fail
@@ -49,7 +49,7 @@ kill $dd_pid 2>/dev/null
4949
wait $dd_pid 2>/dev/null
5050

5151
# Now device should be idle, regular delete should work
52-
${UBLK_PROG} del -n "${dev_id}"
52+
_ublk_del_dev "${dev_id}"
5353
udevadm settle
5454

5555
_cleanup_test "null"

tools/testing/selftests/ublk/test_null_04.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _test_metadata_only() {
3434
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
3535
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
3636

37-
${UBLK_PROG} del -n "${dev_id}"
37+
_ublk_del_dev "${dev_id}"
3838
}
3939

4040
_test_integrity_capable_ip() {
@@ -53,7 +53,7 @@ _test_integrity_capable_ip() {
5353
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
5454
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
5555

56-
${UBLK_PROG} del -n "${dev_id}"
56+
_ublk_del_dev "${dev_id}"
5757
}
5858

5959
_test_integrity_reftag_t10dif() {
@@ -72,7 +72,7 @@ _test_integrity_reftag_t10dif() {
7272
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
7373
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 0
7474

75-
${UBLK_PROG} del -n "${dev_id}"
75+
_ublk_del_dev "${dev_id}"
7676
}
7777

7878
_test_nvme_csum() {
@@ -91,7 +91,7 @@ _test_nvme_csum() {
9191
"$(cat "/sys/block/ublkb$dev_id/integrity/protection_interval_bytes")" 512 &&
9292
_check_value "tag_size" "$(cat "/sys/block/ublkb$dev_id/integrity/tag_size")" 8
9393

94-
${UBLK_PROG} del -n "${dev_id}"
94+
_ublk_del_dev "${dev_id}"
9595
}
9696

9797
_prep_test "null" "integrity params"

tools/testing/selftests/ublk/test_part_02.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ _test_partition_scan_no_hang()
4646
if [ "$state" != "${expected_state}" ]; then
4747
echo "FAIL: Device state is $state, expected ${expected_state}"
4848
ERR_CODE=255
49-
${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
49+
_ublk_del_dev "${dev_id}" > /dev/null 2>&1
5050
return
5151
fi
5252
echo "PASS: Device transitioned to ${expected_state} in ${elapsed}s without hanging"
5353

5454
# Clean up the device
55-
${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
55+
_ublk_del_dev "${dev_id}" > /dev/null 2>&1
5656
}
5757

5858
_prep_test "partition_scan" "verify async partition scan prevents IO hang"

0 commit comments

Comments
 (0)