]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: ublk: add --batch/-b for enabling F_BATCH_IO
authorMing Lei <ming.lei@redhat.com>
Fri, 16 Jan 2026 14:18:56 +0000 (22:18 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 23 Jan 2026 03:05:41 +0000 (20:05 -0700)
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 <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/Makefile
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/test_batch_01.sh [new file with mode: 0755]
tools/testing/selftests/ublk/test_generic_04.sh
tools/testing/selftests/ublk/test_generic_05.sh
tools/testing/selftests/ublk/test_stress_08.sh [new file with mode: 0755]
tools/testing/selftests/ublk/test_stress_09.sh [new file with mode: 0755]

index f2da8b403537279b7a781ac9f58bf15e3fd3ce7a..520e18e224f28c22f9dddf2f3c69604647779adc 100644 (file)
@@ -25,6 +25,8 @@ TEST_PROGS += test_generic_14.sh
 TEST_PROGS += test_generic_15.sh
 TEST_PROGS += test_generic_16.sh
 
+TEST_PROGS += test_batch_01.sh
+
 TEST_PROGS += test_null_01.sh
 TEST_PROGS += test_null_02.sh
 TEST_PROGS += test_null_03.sh
@@ -51,6 +53,8 @@ TEST_PROGS += test_stress_04.sh
 TEST_PROGS += test_stress_05.sh
 TEST_PROGS += test_stress_06.sh
 TEST_PROGS += test_stress_07.sh
+TEST_PROGS += test_stress_08.sh
+TEST_PROGS += test_stress_09.sh
 
 TEST_FILES := settings
 
index c77205bac7a9a4f8097d0c2fc4ca1f3f793039df..5d84000872a0ef35dd1e18ecfe25987cf888ab23 100644 (file)
@@ -1593,7 +1593,8 @@ static int cmd_dev_get_features(void)
                FEAT_NAME(UBLK_F_PER_IO_DAEMON),
                FEAT_NAME(UBLK_F_BUF_REG_OFF_DAEMON),
                FEAT_NAME(UBLK_F_INTEGRITY),
-               FEAT_NAME(UBLK_F_SAFE_STOP_DEV)
+               FEAT_NAME(UBLK_F_SAFE_STOP_DEV),
+               FEAT_NAME(UBLK_F_BATCH_IO),
        };
        struct ublk_dev *dev;
        __u64 features = 0;
@@ -1691,6 +1692,7 @@ static void __cmd_create_help(char *exe, bool recovery)
        printf("\t[--nthreads threads] [--per_io_tasks]\n");
        printf("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
                 "[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n");
+       printf("\t[--batch|-b]\n");
        printf("\t[target options] [backfile1] [backfile2] ...\n");
        printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
        printf("\tdefault: nthreads=nr_queues");
@@ -1763,6 +1765,7 @@ int main(int argc, char *argv[])
                { "csum_type",          1,      NULL,  0 },
                { "tag_size",           1,      NULL,  0 },
                { "safe",               0,      NULL,  0 },
+               { "batch",              0,      NULL, 'b'},
                { 0, 0, 0, 0 }
        };
        const struct ublk_tgt_ops *ops = NULL;
@@ -1785,12 +1788,15 @@ int main(int argc, char *argv[])
 
        opterr = 0;
        optind = 2;
-       while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazu",
+       while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazub",
                                  longopts, &option_idx)) != -1) {
                switch (opt) {
                case 'a':
                        ctx.all = 1;
                        break;
+               case 'b':
+                       ctx.flags |= UBLK_F_BATCH_IO;
+                       break;
                case 'n':
                        ctx.dev_id = strtol(optarg, NULL, 10);
                        break;
@@ -1895,6 +1901,11 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (ctx.per_io_tasks && (ctx.flags & UBLK_F_BATCH_IO)) {
+               ublk_err("per_io_task and F_BATCH_IO conflict\n");
+               return -EINVAL;
+       }
+
        /* auto_zc_fallback depends on F_AUTO_BUF_REG & F_SUPPORT_ZERO_COPY */
        if (ctx.auto_zc_fallback &&
            !((ctx.flags & UBLK_F_AUTO_BUF_REG) &&
diff --git a/tools/testing/selftests/ublk/test_batch_01.sh b/tools/testing/selftests/ublk/test_batch_01.sh
new file mode 100755 (executable)
index 0000000..9fa9fff
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
+
+TID="batch_01"
+ERR_CODE=0
+
+if ! _have_feature "BATCH_IO"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+
+_prep_test "generic" "test basic function of UBLK_F_BATCH_IO"
+
+_create_backfile 0 256M
+_create_backfile 1 256M
+
+dev_id=$(_add_ublk_dev -t loop -q 2 -b "${UBLK_BACKFILES[0]}")
+_check_add_dev $TID $?
+
+if ! _mkfs_mount_test /dev/ublkb"${dev_id}"; then
+       _cleanup_test "generic"
+       _show_result $TID 255
+fi
+
+dev_id=$(_add_ublk_dev -t stripe -b --auto_zc "${UBLK_BACKFILES[0]}" "${UBLK_BACKFILES[1]}")
+_check_add_dev $TID $?
+_mkfs_mount_test /dev/ublkb"${dev_id}"
+ERR_CODE=$?
+
+_cleanup_test "generic"
+_show_result $TID $ERR_CODE
index baf5b156193de565a2625ac959ce608cfc269d9b..be2292822bbe8262ec064324c75bf13385973d20 100755 (executable)
@@ -26,6 +26,11 @@ _create_backfile 0 256M
 _create_backfile 1 128M
 _create_backfile 2 128M
 
+ublk_run_recover_test -t null -q 2 -r 1 -b &
+ublk_run_recover_test -t loop -q 2 -r 1 -b "${UBLK_BACKFILES[0]}" &
+ublk_run_recover_test -t stripe -q 2 -r 1 -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
+wait
+
 ublk_run_recover_test -t null -q 2 -r 1 &
 ublk_run_recover_test -t loop -q 2 -r 1 "${UBLK_BACKFILES[0]}" &
 ublk_run_recover_test -t stripe -q 2 -r 1 "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
index 7b5083afc02abe8267a6dd32656cc4f6551296f0..9b7f71c16d82c917712f5cad28140e029f414c90 100755 (executable)
@@ -30,6 +30,11 @@ _create_backfile 0 256M
 _create_backfile 1 128M
 _create_backfile 2 128M
 
+ublk_run_recover_test -t null -q 2 -r 1 -z -b &
+ublk_run_recover_test -t loop -q 2 -r 1 -z -b "${UBLK_BACKFILES[0]}" &
+ublk_run_recover_test -t stripe -q 2 -r 1 -z -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
+wait
+
 ublk_run_recover_test -t null -q 2 -r 1 -z &
 ublk_run_recover_test -t loop -q 2 -r 1 -z "${UBLK_BACKFILES[0]}" &
 ublk_run_recover_test -t stripe -q 2 -r 1 -z "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
diff --git a/tools/testing/selftests/ublk/test_stress_08.sh b/tools/testing/selftests/ublk/test_stress_08.sh
new file mode 100755 (executable)
index 0000000..190db0b
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
+TID="stress_06"
+ERR_CODE=0
+
+ublk_io_and_remove()
+{
+       run_io_and_remove "$@"
+       ERR_CODE=$?
+       if [ ${ERR_CODE} -ne 0 ]; then
+               echo "$TID failure: $*"
+               _show_result $TID $ERR_CODE
+       fi
+}
+
+if ! _have_program fio; then
+       exit "$UBLK_SKIP_CODE"
+fi
+
+if ! _have_feature "ZERO_COPY"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+if ! _have_feature "AUTO_BUF_REG"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+if ! _have_feature "BATCH_IO"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+
+_prep_test "stress" "run IO and remove device(zero copy)"
+
+_create_backfile 0 256M
+_create_backfile 1 128M
+_create_backfile 2 128M
+
+ublk_io_and_remove 8G -t null -q 4 -b &
+ublk_io_and_remove 256M -t loop -q 4 --auto_zc -b "${UBLK_BACKFILES[0]}" &
+ublk_io_and_remove 256M -t stripe -q 4 --auto_zc -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
+ublk_io_and_remove 8G -t null -q 4 -z --auto_zc --auto_zc_fallback -b &
+wait
+
+_cleanup_test "stress"
+_show_result $TID $ERR_CODE
diff --git a/tools/testing/selftests/ublk/test_stress_09.sh b/tools/testing/selftests/ublk/test_stress_09.sh
new file mode 100755 (executable)
index 0000000..1b6bdb3
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
+TID="stress_07"
+ERR_CODE=0
+
+ublk_io_and_kill_daemon()
+{
+       run_io_and_kill_daemon "$@"
+       ERR_CODE=$?
+       if [ ${ERR_CODE} -ne 0 ]; then
+               echo "$TID failure: $*"
+               _show_result $TID $ERR_CODE
+       fi
+}
+
+if ! _have_program fio; then
+       exit "$UBLK_SKIP_CODE"
+fi
+if ! _have_feature "ZERO_COPY"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+if ! _have_feature "AUTO_BUF_REG"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+if ! _have_feature "BATCH_IO"; then
+       exit "$UBLK_SKIP_CODE"
+fi
+
+_prep_test "stress" "run IO and kill ublk server(zero copy)"
+
+_create_backfile 0 256M
+_create_backfile 1 128M
+_create_backfile 2 128M
+
+ublk_io_and_kill_daemon 8G -t null -q 4 -z -b &
+ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc -b "${UBLK_BACKFILES[0]}" &
+ublk_io_and_kill_daemon 256M -t stripe -q 4 -b "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" &
+ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback -b &
+wait
+
+_cleanup_test "stress"
+_show_result $TID $ERR_CODE