selftests: ublk: bug fixes & consolidation
Subsystems (3)
cover selftests: ublk: bug fixes & consolidation
Hello Jens and guys,
This patchset fixes several issues(1, 2, 4) and consolidate & improve the tests in the following ways:
- support shellcheck and fixes all warning
- misc cleanup
- improve cleanup code path(module load/unload, cleanup temp files)
- help to reuse the same test source code and scripts for other projects(liburing[1], blktest, ...)
- add two stress tests for covering IO workloads vs. removing device & killing ublk server, given buffer lifetime is one big thing for ublk-zc
[1] https://github.com/ming1/liburing/commits/ublk-zc
- just need one line change for overriding skip_code, libring uses 77 and kselftests takes 4
Ming Lei (11):
selftests: ublk: make ublk_stop_io_daemon() more reliable
selftests: ublk: fix build failure
selftests: ublk: add --foreground command line
selftests: ublk: fix parsing '-a' argument
selftests: ublk: support shellcheck and fix all warning
selftests: ublk: don't pass ${dev_id} to _cleanup_test()
selftests: ublk: move zero copy feature check into _add_ublk_dev()
selftests: ublk: load/unload ublk_drv when preparing & cleaning up
tests
selftests: ublk: add one stress test for covering IO vs. removing
device
selftests: ublk: add stress test for covering IO vs. killing ublk
server
selftests: ublk: improve test usability
tools/testing/selftests/ublk/Makefile | 6 + tools/testing/selftests/ublk/kublk.c | 43 +++-- tools/testing/selftests/ublk/kublk.h | 2 + tools/testing/selftests/ublk/test_common.sh | 167 ++++++++++++++---- tools/testing/selftests/ublk/test_loop_01.sh | 13 +- tools/testing/selftests/ublk/test_loop_02.sh | 14 +- tools/testing/selftests/ublk/test_loop_03.sh | 16 +- tools/testing/selftests/ublk/test_loop_04.sh | 14 +- tools/testing/selftests/ublk/test_null_01.sh | 9 +- .../testing/selftests/ublk/test_stress_01.sh | 47 +++++ .../testing/selftests/ublk/test_stress_02.sh | 47 +++++ 11 files changed, 300 insertions(+), 78 deletions(-) create mode 100755 tools/testing/selftests/ublk/test_stress_01.sh create mode 100755 tools/testing/selftests/ublk/test_stress_02.sh
Signature · 1 line
2.47.0
PATCH 1/11 selftests: ublk: make ublk_stop_io_daemon() more reliable
Improve ublk_stop_io_daemon() in the following ways:
- don't wait if ->ublksrv_pid becomes -1, which means that the disk has been stopped
- don't wait if ublk char device doesn't exist any more, so we can avoid to rely on inoitfy for wait until the char device is closed
And this way may reduce time of delete command a lot.
--- tools/testing/selftests/ublk/kublk.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
tools/testing/selftests/ublk/kublk.c +14 -10
@@ -691,13 +691,14 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)return ret; } -static int wait_ublk_dev (char *dev_name,int evt_mask,unsigned timeout) +static int wait_ublk_dev (const char *path,int evt_mask,unsigned timeout) {#define EV_SIZE (sizeof(struct inotify_event))#define EV_BUF_LEN (128 * (EV_SIZE + 16))struct pollfd pfd;int fd, wd;int ret = -EINVAL ; +const char *dev_name =basename (path); fd =inotify_init ();if (fd <0 ) {
@@ -761,18 +762,23 @@ static int ublk_stop_io_daemon(const struct ublk_dev *dev)char ublkc[64 ];int ret =0 ; +if (daemon_pid <0 ) +return 0 ; +/* daemon may be dead already */ if (kill (daemon_pid,0 ) <0 ) goto wait; -/* -* Wait until ublk char device is closed, when our daemon is shutdown -*/ -snprintf (ublkc,sizeof (ublkc),"%s%d" ,"ublkc" , dev_id); - ret =wait_ublk_dev (ublkc,IN_CLOSE_WRITE ,10 ); -/* double check and inotify may not be 100% reliable */ +snprintf (ublkc,sizeof (ublkc),"/dev/%s%d" ,"ublkc" , dev_id); + +/* ublk char device may be gone already */ +if (access (ublkc,F_OK ) !=0 ) + goto wait; + +/* Wait until ublk char device is closed, when the daemon is shutdown */ + ret =wait_ublk_dev (ublkc,IN_CLOSE ,10 ); +/* double check and since it may be closed before starting inotify */ if (ret == -ETIMEDOUT ) -/* the daemon doesn't exist now if kill(0) fails */ ret =kill (daemon_pid,0 ) <0 ; wait:waitpid (daemon_pid,NULL ,0 );
@@ -910,8 +916,6 @@ static int __cmd_dev_del(struct dev_ctx *ctx) __func__, dev->dev_info.ublksrv_pid, number, ret);ublk_ctrl_del_dev (dev); fail: -if (ret >=0 ) - ret =ublk_ctrl_get_info (dev);ublk_ctrl_deinit (dev);return (ret >=0 ) ?0 : ret;
Signature · 1 line
2.47.0
Re: [PATCH 01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable
Quoted 9 lines · Ming Lei
Improve
ublk_stop_io_daemon()in the following ways:- don't wait if ->ublksrv_pid becomes -1, which means that the disk has been stopped
- don't wait if ublk char device doesn't exist any more, so we can avoid to rely on inoitfy for wait until the char device is closed
And this way may reduce time of delete command a lot.
Looks good,
PATCH 2/11 selftests: ublk: fix build failure
In reply to Ming LeiFixes the following build failure:
ublk//file_backed.c: In function ‘backing_file_tgt_init’:ublk//file_backed.c:28:42: error: ‘O_DIRECT’ undeclared (first use in this function); did you mean ‘O_DIRECTORY’?
28 | fd = open(file, O_RDWR | O_DIRECT);
| ^~~~~~~~
| O_DIRECTORYwhen trying to reuse this same utility for liburing test.
--- tools/testing/selftests/ublk/kublk.h | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/ublk/kublk.h +1 -0
@@ -12,6 +12,7 @@#include <getopt.h> #include <limits.h> #include <poll.h> +#include <fcntl.h> #include <sys/syscall.h> #include <sys/mman.h> #include <sys/ioctl.h>
Signature · 1 line
2.47.0
Re: [PATCH 02/11] selftests: ublk: fix build failure
Quoted 9 lines · Ming Lei
Fixes the following build failure:
ublk//file_backed.c: In function `backing_file_tgt_init´:ublk//file_backed.c:28:42: error:O_DIRECT´ undeclared (first use in this function); did you meanO_DIRECTORY´?28 | fd = open(file, O_RDWR | O_DIRECT); | ^~~~~~~~ | O_DIRECTORYwhen trying to reuse this same utility for liburing test.
Looks good,
PATCH 3/11 selftests: ublk: add --foreground command line
In reply to Ming LeiAdd --foreground command for helping to debug.
--- tools/testing/selftests/ublk/kublk.c | 17 +++++++++++++---- tools/testing/selftests/ublk/kublk.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-)
tools/testing/selftests/ublk/kublk.c +13 -4
@@ -679,7 +679,10 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev) }ublk_ctrl_get_info (dev); -ublk_send_dev_event (ctx, dev->dev_info.dev_id); +if (ctx->fg) +ublk_ctrl_dump (dev); +else +ublk_send_dev_event (ctx, dev->dev_info.dev_id);/* wait until we are terminated */ for (i =0 ; i < dinfo->nr_hw_queues; i++)
@@ -867,6 +870,9 @@ static int cmd_dev_add(struct dev_ctx *ctx) {int res; +if (ctx->fg) + goto run; + ctx->_evtfd =eventfd (0 ,0 );if (ctx->_evtfd <0 ) {ublk_err ("%s: failed to create eventfd %s\n" , __func__,strerror (errno));
@@ -876,8 +882,9 @@ static int cmd_dev_add(struct dev_ctx *ctx)setsid (); res =fork ();if (res ==0 ) { -__cmd_dev_add (ctx); -exit (EXIT_SUCCESS ); +run: + res =__cmd_dev_add (ctx); +return res; }else if (res >0 ) {uint64_t id;
@@ -1044,6 +1051,7 @@ int main(int argc, char *argv[]) { "debug_mask", 1, NULL, 0 }, { "quiet", 0, NULL, 0 }, { "zero_copy", 1, NULL, 'z' }, + { "foreground", 0, NULL, 0 }, { 0, 0, 0, 0 } };int option_idx, opt;
@@ -1087,7 +1095,8 @@ int main(int argc, char *argv[]) ublk_dbg_mask =strtol (optarg,NULL ,16 );if (!strcmp (longopts[option_idx].name,"quiet" )) ublk_dbg_mask =0 ; -break ; +if (!strcmp (longopts[option_idx].name,"foreground" )) + ctx.fg =1 ; } }
tools/testing/selftests/ublk/kublk.h +1 -0
@@ -67,6 +67,7 @@ struct dev_ctx {char *files[MAX_BACK_FILES ]; unsigned int logging:1; unsigned int all:1; + unsigned int fg:1;int _evtfd; };
Signature · 1 line
2.47.0
Re: [PATCH 03/11] selftests: ublk: add --foreground command line
Quoted 1 line · Ming Lei
Add --foreground command for helping to debug.
Looks good,
PATCH 4/11 selftests: ublk: fix parsing '-a' argument
In reply to Ming LeiThe argument of '-a' doesn't follow any value, so fix it by putting it with '-z' together.
--- tools/testing/selftests/ublk/kublk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ublk/kublk.c +1 -1
@@ -1068,7 +1068,7 @@ int main(int argc, char *argv[])return ret; optind =2 ; -while ((opt =getopt_long (argc, argv,"t:n:d:q:a:z" , +while ((opt =getopt_long (argc, argv,"t:n:d:q:az" , longopts, &option_idx)) !=-1 ) {switch (opt) {case 'a' :
Signature · 1 line
2.47.0
Re: [PATCH 04/11] selftests: ublk: fix parsing '-a' argument
Quoted 4 lines · Ming Lei
The argument of '-a' doesn't follow any value, so fix it by putting it with '-z' together.
Fixes ed5820a7e918 ("selftests: ublk: add ublk zero copy test")
Looks good.
PATCH 5/11 selftests: ublk: support shellcheck and fix all warning
In reply to Ming LeiAdd shellcheck, meantime fixes all warnings.
--- tools/testing/selftests/ublk/Makefile | 3 ++ tools/testing/selftests/ublk/test_common.sh | 57 +++++++++++--------- tools/testing/selftests/ublk/test_loop_01.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_02.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_03.sh | 10 ++-- tools/testing/selftests/ublk/test_loop_04.sh | 10 ++-- tools/testing/selftests/ublk/test_null_01.sh | 6 +-- 7 files changed, 58 insertions(+), 48 deletions(-)
tools/testing/selftests/ublk/Makefile +3 -0
@@ -14,3 +14,6 @@ TEST_GEN_PROGS_EXTENDED = kublk include ../lib.mk $(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c + +check: + shellcheck -x -f gcc *.sh
tools/testing/selftests/ublk/test_common.sh +32 -25
118 lines not on this page · raw message
tools/testing/selftests/ublk/test_loop_01.sh +5 -5
@@ -8,13 +8,13 @@ ERR_CODE=0 _prep_test "loop" "write and verify test" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0` +dev_id=$(_add_ublk_dev -t loop "$backfile_0") # run fio over the ublk disk fio --name=write_and_verify \ - --filename=/dev/ublkb${dev_id} \ + --filename=/dev/ublkb"${dev_id}" \ --ioengine=libaio --iodepth=16 \ --rw=write \ --size=256M \
@@ -24,8 +24,8 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_loop_02.sh +5 -5
@@ -8,15 +8,15 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0` +dev_id=$(_add_ublk_dev -t loop "$backfile_0") -_mkfs_mount_test /dev/ublkb${dev_id} +_mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_loop_03.sh +5 -5
@@ -10,13 +10,13 @@ _have_feature "ZERO_COPY" || exit 4 _prep_test "loop" "write and verify over zero copy" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop $backfile_0 -z` +dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") # run fio over the ublk disk fio --name=write_and_verify \ - --filename=/dev/ublkb${dev_id} \ + --filename=/dev/ublkb"${dev_id}" \ --ioengine=libaio --iodepth=64 \ --rw=write \ --size=256M \
@@ -26,8 +26,8 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_loop_04.sh +5 -5
@@ -8,15 +8,15 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount with zero copy" -backfile_0=`_create_backfile 256M` +backfile_0=$(_create_backfile 256M) -dev_id=`_add_ublk_dev -t loop -z $backfile_0` +dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") -_mkfs_mount_test /dev/ublkb${dev_id} +_mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test ${dev_id} "loop" +_cleanup_test "${dev_id}" "loop" -_remove_backfile $backfile_0 +_remove_backfile "$backfile_0" _show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_null_01.sh +3 -3
@@ -8,12 +8,12 @@ ERR_CODE=0 _prep_test "null" "basic IO test" -dev_id=`_add_ublk_dev -t null` +dev_id=$(_add_ublk_dev -t null) # run fio over the two disks -fio --name=job1 --filename=/dev/ublkb${dev_id} --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 +fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test ${dev_id} "null" +_cleanup_test "${dev_id}" "null" _show_result $TID $ERR_CODE
Signature · 1 line
2.47.0
PATCH 6/11 selftests: ublk: don't pass ${dev_id} to _cleanup_test()
In reply to Ming LeiMore devices can be created in single tests, so simply remove all ublk devices in _cleanup_test(), meantime remove the ${dev_id} argument of _cleanup_test().
--- tools/testing/selftests/ublk/test_common.sh | 2 +- tools/testing/selftests/ublk/test_loop_01.sh | 2 +- tools/testing/selftests/ublk/test_loop_02.sh | 2 +- tools/testing/selftests/ublk/test_loop_03.sh | 2 +- tools/testing/selftests/ublk/test_loop_04.sh | 2 +- tools/testing/selftests/ublk/test_null_01.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/ublk/test_common.sh +1 -1
@@ -89,7 +89,7 @@ _show_result() } _cleanup_test() { - "${UBLK_PROG}" del -n "$1" + "${UBLK_PROG}" del -a } _add_ublk_dev() {
tools/testing/selftests/ublk/test_loop_01.sh +1 -1
@@ -24,7 +24,7 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test "${dev_id}" "loop" +_cleanup_test "loop" _remove_backfile "$backfile_0"
tools/testing/selftests/ublk/test_loop_02.sh +1 -1
@@ -15,7 +15,7 @@ dev_id=$(_add_ublk_dev -t loop "$backfile_0") _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test "${dev_id}" "loop" +_cleanup_test "loop" _remove_backfile "$backfile_0"
tools/testing/selftests/ublk/test_loop_03.sh +1 -1
@@ -26,7 +26,7 @@ fio --name=write_and_verify \ --bs=4k > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test "${dev_id}" "loop" +_cleanup_test "loop" _remove_backfile "$backfile_0"
tools/testing/selftests/ublk/test_loop_04.sh +1 -1
@@ -15,7 +15,7 @@ dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$? -_cleanup_test "${dev_id}" "loop" +_cleanup_test "loop" _remove_backfile "$backfile_0"
tools/testing/selftests/ublk/test_null_01.sh +1 -1
@@ -14,6 +14,6 @@ dev_id=$(_add_ublk_dev -t null) fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1 ERR_CODE=$? -_cleanup_test "${dev_id}" "null" +_cleanup_test "null" _show_result $TID $ERR_CODE
Signature · 1 line
2.47.0
PATCH 7/11 selftests: ublk: move zero copy feature check into _add_ublk_dev()
In reply to Ming LeiMove zero copy feature check into _add_ublk_dev() since we will have more tests which requires to cover zero copy.
Then one check function of _check_add_dev() has to be added for dealing with cleanup since '_add_ublk_dev()' is run in sub-shell, and we can't exit from it to terminal shell.
Meantime always return error code from _add_ublk_dev().
--- tools/testing/selftests/ublk/test_common.sh | 56 ++++++++++++++++---- tools/testing/selftests/ublk/test_loop_01.sh | 1 + tools/testing/selftests/ublk/test_loop_02.sh | 2 +- tools/testing/selftests/ublk/test_loop_03.sh | 4 +- tools/testing/selftests/ublk/test_loop_04.sh | 2 +- tools/testing/selftests/ublk/test_null_01.sh | 1 + 6 files changed, 50 insertions(+), 16 deletions(-)
tools/testing/selftests/ublk/test_common.sh +45 -11
@@ -1,6 +1,8 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 +UBLK_SKIP_CODE=4 + _create_backfile() { local my_size=$1 local my_file
@@ -79,12 +81,37 @@ _prep_test() { echo "ublk $type: $*" } +_remove_test_files() +{ + local files=$* + + for file in ${files}; do + [ -f "${file}" ] && rm -f "${file}" + done +} + _show_result() { - if [ "$2" -ne 0 ]; then - echo "$1 : [FAIL]" - else + if [ "$2" -eq 0 ]; then echo "$1 : [PASS]" + elif [ "$2" -eq 4 ]; then + echo "$1 : [SKIP]" + else + echo "$1 : [FAIL]" + fi + [ "$2" -ne 0 ] && exit "$2" + return 0 +} + +# don't call from sub-shell, otherwise can't exit +_check_add_dev() +{ + local tid=$1 + local code=$2 + shift 2 + if [ "${code}" -ne 0 ]; then + _remove_test_files "$@" + _show_result "${tid}" "${code}" fi }
@@ -92,13 +119,28 @@ _cleanup_test() { "${UBLK_PROG}" del -a } +_have_feature() +{ + if $UBLK_PROG "features" | grep "$1" > /dev/null 2>&1; then + return 0 + fi + return 1 +} + _add_ublk_dev() { local kublk_temp; local dev_id; + if echo "$@" | grep -q "\-z"; then + if ! _have_feature "ZERO_COPY"; then + return ${UBLK_SKIP_CODE} + fi + fi + kublk_temp=$(mktemp /tmp/kublk-XXXXXX) if ! "${UBLK_PROG}" add "$@" > "${kublk_temp}" 2>&1; then echo "fail to add ublk dev $*" + rm -f "${kublk_temp}" return 255 fi
@@ -108,13 +150,5 @@ _add_ublk_dev() { echo "${dev_id}" } -_have_feature() -{ - if "$UBLK_PROG" "features" | grep "$1" > /dev/null 2>&1; then - return 0 - fi - return 1 -} - UBLK_PROG=$(pwd)/kublk export UBLK_PROG
tools/testing/selftests/ublk/test_loop_01.sh +1 -0
@@ -11,6 +11,7 @@ _prep_test "loop" "write and verify test" backfile_0=$(_create_backfile 256M) dev_id=$(_add_ublk_dev -t loop "$backfile_0") +_check_add_dev $TID $? "${backfile_0}" # run fio over the ublk disk fio --name=write_and_verify \
tools/testing/selftests/ublk/test_loop_02.sh +1 -1
@@ -9,8 +9,8 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop "$backfile_0") +_check_add_dev $TID $? "$backfile_0" _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$?
tools/testing/selftests/ublk/test_loop_03.sh +1 -3
@@ -6,13 +6,11 @@ TID="loop_03" ERR_CODE=0 -_have_feature "ZERO_COPY" || exit 4 - _prep_test "loop" "write and verify over zero copy" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") +_check_add_dev $TID $? "$backfile_0" # run fio over the ublk disk fio --name=write_and_verify \
tools/testing/selftests/ublk/test_loop_04.sh +1 -1
@@ -9,8 +9,8 @@ ERR_CODE=0 _prep_test "loop" "mkfs & mount & umount with zero copy" backfile_0=$(_create_backfile 256M) - dev_id=$(_add_ublk_dev -t loop -z "$backfile_0") +_check_add_dev $TID $? "$backfile_0" _mkfs_mount_test /dev/ublkb"${dev_id}" ERR_CODE=$?
tools/testing/selftests/ublk/test_null_01.sh +1 -0
@@ -9,6 +9,7 @@ ERR_CODE=0 _prep_test "null" "basic IO test" dev_id=$(_add_ublk_dev -t null) +_check_add_dev $TID $? # run fio over the two disks fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1
Signature · 1 line
2.47.0
PATCH 8/11 selftests: ublk: load/unload ublk_drv when preparing & cleaning up tests
In reply to Ming LeiLoad ublk_drv module in _prep_test(), and unload it in _cleanup_test(), so that test can always be done in consistent state.
--- tools/testing/selftests/ublk/test_common.sh | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/ublk/test_common.sh +5 -0
@@ -64,6 +64,7 @@ _check_root() { _remove_ublk_devices() { ${UBLK_PROG} del -a + modprobe -r ublk_drv } _get_ublk_dev_state() {
@@ -78,6 +79,7 @@ _prep_test() { _check_root local type=$1 shift 1 + modprobe ublk_drv echo "ublk $type: $*" }
@@ -131,6 +133,9 @@ _add_ublk_dev() { local kublk_temp; local dev_id; + if [ ! -c /dev/ublk-control ]; then + return ${UBLK_SKIP_CODE} + fi if echo "$@" | grep -q "\-z"; then if ! _have_feature "ZERO_COPY"; then return ${UBLK_SKIP_CODE}
Signature · 1 line
2.47.0
PATCH 9/11 selftests: ublk: add one stress test for covering IO vs. removing device
In reply to Ming LeiAdd stress_test_01 for running IO vs. removing device for verifying that ublk device removal can work as expected when heavy IO workloads are in progress.
null, loop and loop/zc are covered in this tests.
--- tools/testing/selftests/ublk/Makefile | 2 + tools/testing/selftests/ublk/test_common.sh | 26 ++++++++++ .../testing/selftests/ublk/test_stress_01.sh | 47 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100755 tools/testing/selftests/ublk/test_stress_01.sh
tools/testing/selftests/ublk/Makefile +2 -0
@@ -9,6 +9,8 @@ TEST_PROGS += test_loop_02.sh TEST_PROGS += test_loop_03.sh TEST_PROGS += test_loop_04.sh +TEST_PROGS += test_stress_01.sh + TEST_GEN_PROGS_EXTENDED = kublk include ../lib.mk
tools/testing/selftests/ublk/test_common.sh +26 -0
@@ -155,5 +155,31 @@ _add_ublk_dev() { echo "${dev_id}" } +__remove_ublk_dev_return() { + local dev_id=$1 + + ${UBLK_PROG} del -n "${dev_id}" + local res=$? + udevadm settle + return ${res} +} + +__run_io_and_remove() +{ + local dev_id=$1 + local size=$2 + + fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \ + --rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \ + --runtime=20 --time_based > /dev/null 2>&1 & + sleep 2 + if ! __remove_ublk_dev_return "${dev_id}"; then + echo "delete dev ${dev_id} failed" + return 255 + fi + wait +} + + UBLK_PROG=$(pwd)/kublk export UBLK_PROG
tools/testing/selftests/ublk/test_stress_01.sh new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH 10/11 selftests: ublk: add stress test for covering IO vs. killing ublk server
In reply to Ming LeiAdd stress_test_01 for running IO vs. killing ublk server, so io_uring exit & cancel code path can be covered, same with ublk's cancel code path.
Especially IO buffer lifetime is one big thing for ublk zero copy, the added test can verify if this area works as expected.
--- tools/testing/selftests/ublk/Makefile | 1 + tools/testing/selftests/ublk/test_common.sh | 29 ++++++++++++ .../testing/selftests/ublk/test_stress_01.sh | 2 +- .../testing/selftests/ublk/test_stress_02.sh | 47 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/ublk/test_stress_02.sh
tools/testing/selftests/ublk/Makefile +1 -0
@@ -10,6 +10,7 @@ TEST_PROGS += test_loop_03.sh TEST_PROGS += test_loop_04.sh TEST_PROGS += test_stress_01.sh +TEST_PROGS += test_stress_02.sh TEST_GEN_PROGS_EXTENDED = kublk
tools/testing/selftests/ublk/test_common.sh +29 -0
@@ -155,6 +155,26 @@ _add_ublk_dev() { echo "${dev_id}" } +# kill the ublk daemon and return ublk device state +__ublk_kill_daemon() +{ + local dev_id=$1 + local exp_state=$2 + local daemon_pid + local state + + daemon_pid=$(_get_ublk_daemon_pid "${dev_id}") + state=$(_get_ublk_dev_state "${dev_id}") + + for ((j=0;j<50;j++)); do + [ "$state" == "$exp_state" ] && break + kill -9 "$daemon_pid" > /dev/null 2>&1 + sleep 1 + state=$(_get_ublk_dev_state "${dev_id}") + done + echo "$state" +} + __remove_ublk_dev_return() { local dev_id=$1
@@ -168,11 +188,20 @@ __run_io_and_remove() { local dev_id=$1 local size=$2 + local kill_server=$3 fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \ --rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \ --runtime=20 --time_based > /dev/null 2>&1 & sleep 2 + if [ "${kill_server}" = "yes" ]; then + local state + state=$(__ublk_kill_daemon "${dev_id}" "DEAD") + if [ "$state" != "DEAD" ]; then + echo "device isn't dead($state) after killing daemon" + return 255 + fi + fi if ! __remove_ublk_dev_return "${dev_id}"; then echo "delete dev ${dev_id} failed" return 255
tools/testing/selftests/ublk/test_stress_01.sh +1 -1
@@ -18,7 +18,7 @@ ublk_io_and_remove() _check_add_dev $TID $? "${backfile}" echo "run ublk IO vs. remove device(ublk add $*)" - if ! __run_io_and_remove "${DEV_ID}" "${size}"; then + if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then echo "/dev/ublkc${DEV_ID} isn't removed" _remove_backfile "${backfile}" exit 255
tools/testing/selftests/ublk/test_stress_02.sh new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH 11/11 selftests: ublk: improve test usability
In reply to Ming LeiAdd UBLK_TEST_QUIET, so we can print test result(PASS/SKIP/FAIL) only.
Also always run from test script's current directory, then the same test script can be started from other work directory.
This way helps a lot to reuse this test source code and scripts for other projects(liburing, blktests, ...)
--- tools/testing/selftests/ublk/test_common.sh | 10 ++++++++-- tools/testing/selftests/ublk/test_loop_01.sh | 2 +- tools/testing/selftests/ublk/test_loop_02.sh | 2 +- tools/testing/selftests/ublk/test_loop_03.sh | 2 +- tools/testing/selftests/ublk/test_loop_04.sh | 2 +- tools/testing/selftests/ublk/test_null_01.sh | 2 +- tools/testing/selftests/ublk/test_stress_01.sh | 4 ++-- tools/testing/selftests/ublk/test_stress_02.sh | 4 ++-- 8 files changed, 17 insertions(+), 11 deletions(-)
tools/testing/selftests/ublk/test_common.sh +8 -2
@@ -80,7 +80,7 @@ _prep_test() { local type=$1 shift 1 modprobe ublk_drv - echo "ublk $type: $*" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "ublk $type: $*" } _remove_test_files()
@@ -209,6 +209,12 @@ __run_io_and_remove() wait } +_ublk_test_top_dir() +{ + cd "$(dirname "$0")" && pwd +} -UBLK_PROG=$(pwd)/kublk +UBLK_PROG=$(_ublk_test_top_dir)/kublk +UBLK_TEST_QUIET=1 export UBLK_PROG +export UBLK_TEST_QUIET
tools/testing/selftests/ublk/test_loop_01.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_01" ERR_CODE=0
tools/testing/selftests/ublk/test_loop_02.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_02" ERR_CODE=0
tools/testing/selftests/ublk/test_loop_03.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_03" ERR_CODE=0
tools/testing/selftests/ublk/test_loop_04.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="loop_04" ERR_CODE=0
tools/testing/selftests/ublk/test_null_01.sh +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="null_01" ERR_CODE=0
tools/testing/selftests/ublk/test_stress_01.sh +2 -2
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="stress_01" ERR_CODE=0 DEV_ID=-1
@@ -17,7 +17,7 @@ ublk_io_and_remove() DEV_ID=$(_add_ublk_dev "$@") _check_add_dev $TID $? "${backfile}" - echo "run ublk IO vs. remove device(ublk add $*)" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs. remove device(ublk add $*)" if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then echo "/dev/ublkc${DEV_ID} isn't removed" _remove_backfile "${backfile}"
tools/testing/selftests/ublk/test_stress_02.sh +2 -2
@@ -1,7 +1,7 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -. test_common.sh +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh TID="stress_02" ERR_CODE=0 DEV_ID=-1
@@ -17,7 +17,7 @@ ublk_io_and_kill_daemon() DEV_ID=$(_add_ublk_dev "$@") _check_add_dev $TID $? "${backfile}" - echo "run ublk IO vs kill ublk server(ublk add $*)" + [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs kill ublk server(ublk add $*)" if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then echo "/dev/ublkc${DEV_ID} isn't removed res ${res}" _remove_backfile "${backfile}"
Signature · 1 line
2.47.0
Quoted 15 lines · Ming Lei
Hello Jens and guys,
This patchset fixes several
issues(1, 2, 4)and consolidate & improve the tests in the following ways:- support shellcheck and fixes all warning
- misc cleanup
- improve cleanup code
path(module load/unload, cleanup temp files)- help to reuse the same test source code and scripts for other
projects(liburing[1], blktest, ...)
Quoted 8 lines
- add two stress tests for covering IO workloads vs. removing device & killing ublk server, given buffer lifetime is one big thing for ublk-zc
[1] https://github.com/ming1/liburing/commits/ublk-zc
- just need one line change for overriding
skip_code, libring uses 77 and kselftests takes 4
Hi Jens,
Can you merge this patchset if you are fine?
Thanks,
Jens Axboe
maintainerQuoted 20 lines · Ming Lei
Quoted 19 lines · On Mon, Mar 3, 2025 at 8:43?PM Ming Lei <[email protected]> wrote:
Hello Jens and guys,
This patchset fixes several
issues(1, 2, 4)and consolidate & improve the tests in the following ways:- support shellcheck and fixes all warning
- misc cleanup
- improve cleanup code
path(module load/unload, cleanup temp files)- help to reuse the same test source code and scripts for other
projects(liburing[1], blktest, ...)- add two stress tests for covering IO workloads vs. removing device & killing ublk server, given buffer lifetime is one big thing for ublk-zc
Quoted 8 lines
Quoted 4 lines
[1] https://github.com/ming1/liburing/commits/ublk-zc
- just need one line change for overriding
skip_code, libring uses 77 and kselftests takes 4Hi Jens,
Can you merge this patchset if you are fine?
Yep sorry, was pondering how best to get it staged. Should go into block, but depends on the other bits that I staged for io_uring. So I'll just put it there, not a big deal.
Signature · 1 line
Jens Axboe
Quoted 26 lines · Jens Axboe
Quoted 25 lines · Ming Lei
Quoted 23 lines · On Mon, Mar 3, 2025 at 8:43?PM Ming Lei <[email protected]> wrote:
Hello Jens and guys,
This patchset fixes several
issues(1, 2, 4)and consolidate & improve the tests in the following ways:- support shellcheck and fixes all warning
- misc cleanup
- improve cleanup code
path(module load/unload, cleanup temp files)- help to reuse the same test source code and scripts for other
projects(liburing[1], blktest, ...)- add two stress tests for covering IO workloads vs. removing device & killing ublk server, given buffer lifetime is one big thing for ublk-zc
[1] https://github.com/ming1/liburing/commits/ublk-zc
- just need one line change for overriding
skip_code, libring uses 77 and kselftests takes 4
Quoted 7 lines
Quoted 3 lines
Hi Jens,
Can you merge this patchset if you are fine?
Yep sorry, was pondering how best to get it staged. Should go into block, but depends on the other bits that I staged for
io_uring. So I'll just put it there, not a big deal.
Thanks for pulling it in!
BTW, the test behavior depends on block too, otherwise it may fail because ublk zc actually depends on the fix of "ublk: complete command synchronously on error".
So if anyone wants to try the test, please do it against next tree.
Thanks,
Ming
Jens Axboe
maintainerQuoted 35 lines · Ming Lei
Quoted 26 lines · Jens Axboe
Quoted 25 lines · Ming Lei
Quoted 23 lines · On Mon, Mar 3, 2025 at 8:43?PM Ming Lei <[email protected]> wrote:
Hello Jens and guys,
This patchset fixes several
issues(1, 2, 4)and consolidate & improve the tests in the following ways:- support shellcheck and fixes all warning
- misc cleanup
- improve cleanup code
path(module load/unload, cleanup temp files)- help to reuse the same test source code and scripts for other
projects(liburing[1], blktest, ...)- add two stress tests for covering IO workloads vs. removing device & killing ublk server, given buffer lifetime is one big thing for ublk-zc
[1] https://github.com/ming1/liburing/commits/ublk-zc
- just need one line change for overriding
skip_code, libring uses 77 and kselftests takes 4Quoted 7 lines
Quoted 3 lines
Hi Jens,
Can you merge this patchset if you are fine?
Yep sorry, was pondering how best to get it staged. Should go into block, but depends on the other bits that I staged for
io_uring. So I'll just put it there, not a big deal.
Quoted 7 lines
Thanks for pulling it in!
BTW, the test behavior depends on block too, otherwise it may fail because ublk zc actually depends on the fix of "ublk: complete command synchronously on error".
So if anyone wants to try the test, please do it against next tree.
Indeed - not a huge deal, as they will go into the main tree at roughly the same time anyway. But good to note.
Signature · 1 line
Jens Axboe
Quoted 8 lines · Ming Lei
This patchset fixes several
issues(1, 2, 4)and consolidate & improve the tests in the following ways:- support shellcheck and fixes all warning
- misc cleanup
[...]
Applied, thanks!
[01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable
commit: 9894e0eaae980df1ed3f2e86a487fe4c8ef1ab46
[02/11] selftests: ublk: fix build failure
commit: 9d80f48c5e08b2e003e506c6e5326a35a652ea2f
[03/11] selftests: ublk: add --foreground command line
commit: 2ecdcdfee58c028c15ed00b691104249370db075
[04/11] selftests: ublk: fix parsing '-a' argument
commit: cf2132935639813a0b88e55074e6e52a4b82f26a
[05/11] selftests: ublk: support shellcheck and fix all warning
commit: 30aab83035048c70e09ff058a73e8428de9bd103
[06/11] selftests: ublk: don't pass ${dev_id} to _cleanup_test()
commit: 8da9f88fee59fe5aa99014a2621b07347edd5780
[07/11] selftests: ublk: move zero copy feature check into _add_ublk_dev()
commit: b95b47eaa8d7c8b595d93397d1b85f1559c2d220
[08/11] selftests: ublk: load/unload ublk_drv when preparing & cleaning up tests
commit: 9e71305495d1b79f96729b8d77d4d823a6bd998a
[09/11] selftests: ublk: add one stress test for covering IO vs. removing device
commit: 6f3004e78b59e98a903e20e2240ae77e76dfde77
[10/11] selftests: ublk: add stress test for covering IO vs. killing ublk server
commit: 4fcd5b5a6dff71cf82212dd208dc1765ca8a8088
[11/11] selftests: ublk: improve test usability
commit: 22c880f446a149f5ee11260690a34d4b3f95c221Best regards,
Signature · 1 line
Jens Axboe