Skip to content

Commit 730d837

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: fix UBLK_F_NEED_GET_DATA
Commit 57e13a2 ("selftests: ublk: support user recovery") starts to support UBLK_F_NEED_GET_DATA for covering recovery feature, however the ublk utility implementation isn't done correctly. Fix it by supporting UBLK_F_NEED_GET_DATA correctly. Also add test generic_07 for covering UBLK_F_NEED_GET_DATA. Reviewed-by: Caleb Sander Mateos <csander@purestorage.com> Fixes: 57e13a2 ("selftests: ublk: support user recovery") Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250429022941.1718671-2-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f40139f commit 730d837

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ TEST_PROGS += test_generic_03.sh
99
TEST_PROGS += test_generic_04.sh
1010
TEST_PROGS += test_generic_05.sh
1111
TEST_PROGS += test_generic_06.sh
12+
TEST_PROGS += test_generic_07.sh
1213

1314
TEST_PROGS += test_null_01.sh
1415
TEST_PROGS += test_null_02.sh

tools/testing/selftests/ublk/kublk.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,17 @@ int ublk_queue_io_cmd(struct ublk_queue *q, struct ublk_io *io, unsigned tag)
536536
if (!(io->flags & UBLKSRV_IO_FREE))
537537
return 0;
538538

539-
/* we issue because we need either fetching or committing */
539+
/*
540+
* we issue because we need either fetching or committing or
541+
* getting data
542+
*/
540543
if (!(io->flags &
541-
(UBLKSRV_NEED_FETCH_RQ | UBLKSRV_NEED_COMMIT_RQ_COMP)))
544+
(UBLKSRV_NEED_FETCH_RQ | UBLKSRV_NEED_COMMIT_RQ_COMP | UBLKSRV_NEED_GET_DATA)))
542545
return 0;
543546

544-
if (io->flags & UBLKSRV_NEED_COMMIT_RQ_COMP)
547+
if (io->flags & UBLKSRV_NEED_GET_DATA)
548+
cmd_op = UBLK_U_IO_NEED_GET_DATA;
549+
else if (io->flags & UBLKSRV_NEED_COMMIT_RQ_COMP)
545550
cmd_op = UBLK_U_IO_COMMIT_AND_FETCH_REQ;
546551
else if (io->flags & UBLKSRV_NEED_FETCH_RQ)
547552
cmd_op = UBLK_U_IO_FETCH_REQ;
@@ -658,6 +663,9 @@ static void ublk_handle_cqe(struct io_uring *r,
658663
assert(tag < q->q_depth);
659664
if (q->tgt_ops->queue_io)
660665
q->tgt_ops->queue_io(q, tag);
666+
} else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
667+
io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
668+
ublk_queue_io_cmd(q, io, tag);
661669
} else {
662670
/*
663671
* COMMIT_REQ will be completed immediately since no fetching
@@ -1237,7 +1245,7 @@ static void __cmd_create_help(char *exe, bool recovery)
12371245

12381246
printf("%s %s -t [null|loop|stripe|fault_inject] [-q nr_queues] [-d depth] [-n dev_id]\n",
12391247
exe, recovery ? "recover" : "add");
1240-
printf("\t[--foreground] [--quiet] [-z] [--debug_mask mask] [-r 0|1 ] [-g 0|1]\n");
1248+
printf("\t[--foreground] [--quiet] [-z] [--debug_mask mask] [-r 0|1 ] [-g]\n");
12411249
printf("\t[-e 0|1 ] [-i 0|1]\n");
12421250
printf("\t[target options] [backfile1] [backfile2] ...\n");
12431251
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
@@ -1313,7 +1321,7 @@ int main(int argc, char *argv[])
13131321

13141322
opterr = 0;
13151323
optind = 2;
1316-
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:az",
1324+
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:gaz",
13171325
longopts, &option_idx)) != -1) {
13181326
switch (opt) {
13191327
case 'a':
@@ -1351,9 +1359,7 @@ int main(int argc, char *argv[])
13511359
ctx.flags |= UBLK_F_USER_RECOVERY | UBLK_F_USER_RECOVERY_REISSUE;
13521360
break;
13531361
case 'g':
1354-
value = strtol(optarg, NULL, 10);
1355-
if (value)
1356-
ctx.flags |= UBLK_F_NEED_GET_DATA;
1362+
ctx.flags |= UBLK_F_NEED_GET_DATA;
13571363
break;
13581364
case 0:
13591365
if (!strcmp(longopts[option_idx].name, "debug_mask"))

tools/testing/selftests/ublk/kublk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct ublk_io {
115115
#define UBLKSRV_NEED_FETCH_RQ (1UL << 0)
116116
#define UBLKSRV_NEED_COMMIT_RQ_COMP (1UL << 1)
117117
#define UBLKSRV_IO_FREE (1UL << 2)
118+
#define UBLKSRV_NEED_GET_DATA (1UL << 3)
118119
unsigned short flags;
119120
unsigned short refs; /* used by target code only */
120121

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_07"
7+
ERR_CODE=0
8+
9+
if ! _have_program fio; then
10+
exit "$UBLK_SKIP_CODE"
11+
fi
12+
13+
_prep_test "generic" "test UBLK_F_NEED_GET_DATA"
14+
15+
_create_backfile 0 256M
16+
dev_id=$(_add_ublk_dev -t loop -q 2 -g "${UBLK_BACKFILES[0]}")
17+
_check_add_dev $TID $?
18+
19+
# run fio over the ublk disk
20+
_run_fio_verify_io --filename=/dev/ublkb"${dev_id}" --size=256M
21+
ERR_CODE=$?
22+
if [ "$ERR_CODE" -eq 0 ]; then
23+
_mkfs_mount_test /dev/ublkb"${dev_id}"
24+
ERR_CODE=$?
25+
fi
26+
27+
_cleanup_test "generic"
28+
_show_result $TID $ERR_CODE

tools/testing/selftests/ublk/test_stress_05.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ _create_backfile 0 256M
4747
_create_backfile 1 256M
4848

4949
for reissue in $(seq 0 1); do
50-
ublk_io_and_remove 8G -t null -q 4 -g 1 -r 1 -i "$reissue" &
51-
ublk_io_and_remove 256M -t loop -q 4 -g 1 -r 1 -i "$reissue" "${UBLK_BACKFILES[0]}" &
50+
ublk_io_and_remove 8G -t null -q 4 -g -r 1 -i "$reissue" &
51+
ublk_io_and_remove 256M -t loop -q 4 -g -r 1 -i "$reissue" "${UBLK_BACKFILES[0]}" &
5252
wait
5353
done
5454

5555
if _have_feature "ZERO_COPY"; then
5656
for reissue in $(seq 0 1); do
57-
ublk_io_and_remove 8G -t null -q 4 -g 1 -z -r 1 -i "$reissue" &
58-
ublk_io_and_remove 256M -t loop -q 4 -g 1 -z -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" &
57+
ublk_io_and_remove 8G -t null -q 4 -g -z -r 1 -i "$reissue" &
58+
ublk_io_and_remove 256M -t loop -q 4 -g -z -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" &
5959
wait
6060
done
6161
fi

0 commit comments

Comments
 (0)