Skip to content

Commit 723977c

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add generic_01 for verifying sequential IO order
block layer, ublk and io_uring might re-order IO in the past - plug - queue ublk io command via task work Add one test for verifying if sequential WRITE IO is dispatched in order. - null target is taken, so we can just observe io order from `tracepoint:block:block_rq_complete` which represents the dispatch order - WRITE IO is taken because READ may come from system-wide utility Cc: Uday Shankar <ushankar@purestorage.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250322093218.431419-2-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ffde32a commit 723977c

4 files changed

Lines changed: 94 additions & 1 deletion

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)
44
LDLIBS += -lpthread -lm -luring
55

6-
TEST_PROGS := test_null_01.sh
6+
TEST_PROGS := test_generic_01.sh
7+
8+
TEST_PROGS += test_null_01.sh
79
TEST_PROGS += test_loop_01.sh
810
TEST_PROGS += test_loop_02.sh
911
TEST_PROGS += test_loop_03.sh

tools/testing/selftests/ublk/test_common.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33

44
UBLK_SKIP_CODE=4
55

6+
_have_program() {
7+
if command -v "$1" >/dev/null 2>&1; then
8+
return 0
9+
fi
10+
return 1
11+
}
12+
13+
_get_disk_dev_t() {
14+
local dev_id=$1
15+
local dev
16+
local major
17+
local minor
18+
19+
dev=/dev/ublkb"${dev_id}"
20+
major=$(stat -c '%Hr' "$dev")
21+
minor=$(stat -c '%Lr' "$dev")
22+
23+
echo $(( (major & 0xfff) << 20 | (minor & 0xfffff) ))
24+
}
25+
626
_create_backfile() {
727
local my_size=$1
828
local my_file
@@ -121,6 +141,7 @@ _check_add_dev()
121141

122142
_cleanup_test() {
123143
"${UBLK_PROG}" del -a
144+
rm -f "$UBLK_TMP"
124145
}
125146

126147
_have_feature()
@@ -216,6 +237,7 @@ _ublk_test_top_dir()
216237
cd "$(dirname "$0")" && pwd
217238
}
218239

240+
UBLK_TMP=$(mktemp ublk_test_XXXXX)
219241
UBLK_PROG=$(_ublk_test_top_dir)/kublk
220242
UBLK_TEST_QUIET=1
221243
UBLK_TEST_SHOW_RESULT=1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_01"
7+
ERR_CODE=0
8+
9+
if ! _have_program bpftrace; then
10+
exit "$UBLK_SKIP_CODE"
11+
fi
12+
13+
_prep_test "null" "sequential io order"
14+
15+
dev_id=$(_add_ublk_dev -t null)
16+
_check_add_dev $TID $?
17+
18+
dev_t=$(_get_disk_dev_t "$dev_id")
19+
bpftrace trace/seq_io.bt "$dev_t" "W" 1 > "$UBLK_TMP" 2>&1 &
20+
btrace_pid=$!
21+
sleep 2
22+
23+
if ! kill -0 "$btrace_pid" > /dev/null 2>&1; then
24+
_cleanup_test "null"
25+
exit "$UBLK_SKIP_CODE"
26+
fi
27+
28+
# run fio over this ublk disk
29+
fio --name=write_seq \
30+
--filename=/dev/ublkb"${dev_id}" \
31+
--ioengine=libaio --iodepth=16 \
32+
--rw=write \
33+
--size=512M \
34+
--direct=1 \
35+
--bs=4k > /dev/null 2>&1
36+
ERR_CODE=$?
37+
kill "$btrace_pid"
38+
wait
39+
if grep -q "io_out_of_order" "$UBLK_TMP"; then
40+
cat "$UBLK_TMP"
41+
ERR_CODE=255
42+
fi
43+
_cleanup_test "null"
44+
_show_result $TID $ERR_CODE
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
$1: dev_t
3+
$2: RWBS
4+
$3: strlen($2)
5+
*/
6+
BEGIN {
7+
@last_rw[$1, str($2)] = 0;
8+
}
9+
tracepoint:block:block_rq_complete
10+
{
11+
$dev = $1;
12+
if ((int64)args.dev == $1 && !strncmp(args.rwbs, str($2), $3)) {
13+
$last = @last_rw[$dev, str($2)];
14+
if ((uint64)args.sector != $last) {
15+
printf("io_out_of_order: exp %llu actual %llu\n",
16+
args.sector, $last);
17+
}
18+
@last_rw[$dev, str($2)] = (args.sector + args.nr_sector);
19+
}
20+
@ios = count();
21+
}
22+
23+
END {
24+
clear(@last_rw);
25+
}

0 commit comments

Comments
 (0)