Skip to content

Commit 20aeab0

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add --batch/-b for enabling F_BATCH_IO
Add --batch/-b for enabling F_BATCH_IO. Add batch_01 for covering its basic function. Add stress_08 and stress_09 for covering stress test. Add recovery test for F_BATCH_IO in generic_04 and generic_05. Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4968fb7 commit 20aeab0

7 files changed

Lines changed: 148 additions & 2 deletions

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ TEST_PROGS += test_generic_14.sh
2525
TEST_PROGS += test_generic_15.sh
2626
TEST_PROGS += test_generic_16.sh
2727

28+
TEST_PROGS += test_batch_01.sh
29+
2830
TEST_PROGS += test_null_01.sh
2931
TEST_PROGS += test_null_02.sh
3032
TEST_PROGS += test_null_03.sh
@@ -51,6 +53,8 @@ TEST_PROGS += test_stress_04.sh
5153
TEST_PROGS += test_stress_05.sh
5254
TEST_PROGS += test_stress_06.sh
5355
TEST_PROGS += test_stress_07.sh
56+
TEST_PROGS += test_stress_08.sh
57+
TEST_PROGS += test_stress_09.sh
5458

5559
TEST_FILES := settings
5660

tools/testing/selftests/ublk/kublk.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,8 @@ static int cmd_dev_get_features(void)
15931593
FEAT_NAME(UBLK_F_PER_IO_DAEMON),
15941594
FEAT_NAME(UBLK_F_BUF_REG_OFF_DAEMON),
15951595
FEAT_NAME(UBLK_F_INTEGRITY),
1596-
FEAT_NAME(UBLK_F_SAFE_STOP_DEV)
1596+
FEAT_NAME(UBLK_F_SAFE_STOP_DEV),
1597+
FEAT_NAME(UBLK_F_BATCH_IO),
15971598
};
15981599
struct ublk_dev *dev;
15991600
__u64 features = 0;
@@ -1691,6 +1692,7 @@ static void __cmd_create_help(char *exe, bool recovery)
16911692
printf("\t[--nthreads threads] [--per_io_tasks]\n");
16921693
printf("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
16931694
"[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n");
1695+
printf("\t[--batch|-b]\n");
16941696
printf("\t[target options] [backfile1] [backfile2] ...\n");
16951697
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
16961698
printf("\tdefault: nthreads=nr_queues");
@@ -1763,6 +1765,7 @@ int main(int argc, char *argv[])
17631765
{ "csum_type", 1, NULL, 0 },
17641766
{ "tag_size", 1, NULL, 0 },
17651767
{ "safe", 0, NULL, 0 },
1768+
{ "batch", 0, NULL, 'b'},
17661769
{ 0, 0, 0, 0 }
17671770
};
17681771
const struct ublk_tgt_ops *ops = NULL;
@@ -1785,12 +1788,15 @@ int main(int argc, char *argv[])
17851788

17861789
opterr = 0;
17871790
optind = 2;
1788-
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazu",
1791+
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazub",
17891792
longopts, &option_idx)) != -1) {
17901793
switch (opt) {
17911794
case 'a':
17921795
ctx.all = 1;
17931796
break;
1797+
case 'b':
1798+
ctx.flags |= UBLK_F_BATCH_IO;
1799+
break;
17941800
case 'n':
17951801
ctx.dev_id = strtol(optarg, NULL, 10);
17961802
break;
@@ -1895,6 +1901,11 @@ int main(int argc, char *argv[])
18951901
}
18961902
}
18971903

1904+
if (ctx.per_io_tasks && (ctx.flags & UBLK_F_BATCH_IO)) {
1905+
ublk_err("per_io_task and F_BATCH_IO conflict\n");
1906+
return -EINVAL;
1907+
}
1908+
18981909
/* auto_zc_fallback depends on F_AUTO_BUF_REG & F_SUPPORT_ZERO_COPY */
18991910
if (ctx.auto_zc_fallback &&
19001911
!((ctx.flags & UBLK_F_AUTO_BUF_REG) &&
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="batch_01"
7+
ERR_CODE=0
8+
9+
if ! _have_feature "BATCH_IO"; then
10+
exit "$UBLK_SKIP_CODE"
11+
fi
12+
13+
_prep_test "generic" "test basic function of UBLK_F_BATCH_IO"
14+
15+
_create_backfile 0 256M
16+
_create_backfile 1 256M
17+
18+
dev_id=$(_add_ublk_dev -t loop -q 2 -b "${UBLK_BACKFILES[0]}")
19+
_check_add_dev $TID $?
20+
21+
if ! _mkfs_mount_test /dev/ublkb"${dev_id}"; then
22+
_cleanup_test "generic"
23+
_show_result $TID 255
24+
fi
25+
26+
dev_id=$(_add_ublk_dev -t stripe -b --auto_zc "${UBLK_BACKFILES[0]}" "${UBLK_BACKFILES[1]}")
27+
_check_add_dev $TID $?
28+
_mkfs_mount_test /dev/ublkb"${dev_id}"
29+
ERR_CODE=$?
30+
31+
_cleanup_test "generic"
32+
_show_result $TID $ERR_CODE

tools/testing/selftests/ublk/test_generic_04.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ _create_backfile 0 256M
2626
_create_backfile 1 128M
2727
_create_backfile 2 128M
2828

29+
ublk_run_recover_test -t null -q 2 -r 1 -b &
30+
ublk_run_recover_test -t loop -q 2 -r 1 -b "${UBLK_BACKFILES[0]}" &
31+
ublk_run_recover_test -t stripe -q 2 -r 1 -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
32+
wait
33+
2934
ublk_run_recover_test -t null -q 2 -r 1 &
3035
ublk_run_recover_test -t loop -q 2 -r 1 "${UBLK_BACKFILES[0]}" &
3136
ublk_run_recover_test -t stripe -q 2 -r 1 "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &

tools/testing/selftests/ublk/test_generic_05.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ _create_backfile 0 256M
3030
_create_backfile 1 128M
3131
_create_backfile 2 128M
3232

33+
ublk_run_recover_test -t null -q 2 -r 1 -z -b &
34+
ublk_run_recover_test -t loop -q 2 -r 1 -z -b "${UBLK_BACKFILES[0]}" &
35+
ublk_run_recover_test -t stripe -q 2 -r 1 -z -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
36+
wait
37+
3338
ublk_run_recover_test -t null -q 2 -r 1 -z &
3439
ublk_run_recover_test -t loop -q 2 -r 1 -z "${UBLK_BACKFILES[0]}" &
3540
ublk_run_recover_test -t stripe -q 2 -r 1 -z "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
TID="stress_06"
6+
ERR_CODE=0
7+
8+
ublk_io_and_remove()
9+
{
10+
run_io_and_remove "$@"
11+
ERR_CODE=$?
12+
if [ ${ERR_CODE} -ne 0 ]; then
13+
echo "$TID failure: $*"
14+
_show_result $TID $ERR_CODE
15+
fi
16+
}
17+
18+
if ! _have_program fio; then
19+
exit "$UBLK_SKIP_CODE"
20+
fi
21+
22+
if ! _have_feature "ZERO_COPY"; then
23+
exit "$UBLK_SKIP_CODE"
24+
fi
25+
if ! _have_feature "AUTO_BUF_REG"; then
26+
exit "$UBLK_SKIP_CODE"
27+
fi
28+
if ! _have_feature "BATCH_IO"; then
29+
exit "$UBLK_SKIP_CODE"
30+
fi
31+
32+
_prep_test "stress" "run IO and remove device(zero copy)"
33+
34+
_create_backfile 0 256M
35+
_create_backfile 1 128M
36+
_create_backfile 2 128M
37+
38+
ublk_io_and_remove 8G -t null -q 4 -b &
39+
ublk_io_and_remove 256M -t loop -q 4 --auto_zc -b "${UBLK_BACKFILES[0]}" &
40+
ublk_io_and_remove 256M -t stripe -q 4 --auto_zc -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
41+
ublk_io_and_remove 8G -t null -q 4 -z --auto_zc --auto_zc_fallback -b &
42+
wait
43+
44+
_cleanup_test "stress"
45+
_show_result $TID $ERR_CODE
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+
TID="stress_07"
6+
ERR_CODE=0
7+
8+
ublk_io_and_kill_daemon()
9+
{
10+
run_io_and_kill_daemon "$@"
11+
ERR_CODE=$?
12+
if [ ${ERR_CODE} -ne 0 ]; then
13+
echo "$TID failure: $*"
14+
_show_result $TID $ERR_CODE
15+
fi
16+
}
17+
18+
if ! _have_program fio; then
19+
exit "$UBLK_SKIP_CODE"
20+
fi
21+
if ! _have_feature "ZERO_COPY"; then
22+
exit "$UBLK_SKIP_CODE"
23+
fi
24+
if ! _have_feature "AUTO_BUF_REG"; then
25+
exit "$UBLK_SKIP_CODE"
26+
fi
27+
if ! _have_feature "BATCH_IO"; then
28+
exit "$UBLK_SKIP_CODE"
29+
fi
30+
31+
_prep_test "stress" "run IO and kill ublk server(zero copy)"
32+
33+
_create_backfile 0 256M
34+
_create_backfile 1 128M
35+
_create_backfile 2 128M
36+
37+
ublk_io_and_kill_daemon 8G -t null -q 4 -z -b &
38+
ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc -b "${UBLK_BACKFILES[0]}" &
39+
ublk_io_and_kill_daemon 256M -t stripe -q 4 -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
40+
ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback -b &
41+
wait
42+
43+
_cleanup_test "stress"
44+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)