selftests: ublk: add user copy test cases
Subsystems (3)
v2 cover selftests: ublk: add user copy test cases
Fix some existing issues in the ublk selftest suite and add coverage for user copy, which is currently untested.
v2:
- Allow --zero_copy and --auto_zc to coexist for --auto_zc_fallback
- Don't add test cases to test_stress_05.sh as it's close to the timeout
- Add Reviewed-By tags
Caleb Sander Mateos (8):
selftests: ublk: correct last_rw map type in seq_io.bt
selftests: ublk: remove unused ios map in seq_io.bt
selftests: ublk: fix fio arguments in run_io_and_recover()
selftests: ublk: use auto_zc for PER_IO_DAEMON tests in stress_04
selftests: ublk: don't share backing files between ublk servers
selftests: ublk: forbid multiple data copy modes
selftests: ublk: add support for user copy to kublk
selftests: ublk: add user copy test cases
tools/testing/selftests/ublk/Makefile | 8 +++ tools/testing/selftests/ublk/file_backed.c | 7 +- tools/testing/selftests/ublk/kublk.c | 64 +++++++++++++++++-- tools/testing/selftests/ublk/kublk.h | 11 ++++ tools/testing/selftests/ublk/stripe.c | 2 +- tools/testing/selftests/ublk/test_common.sh | 5 +- .../testing/selftests/ublk/test_generic_04.sh | 2 +- .../testing/selftests/ublk/test_generic_05.sh | 2 +- .../testing/selftests/ublk/test_generic_11.sh | 2 +- .../testing/selftests/ublk/test_generic_14.sh | 40 ++++++++++++ tools/testing/selftests/ublk/test_loop_06.sh | 25 ++++++++ tools/testing/selftests/ublk/test_loop_07.sh | 21 ++++++ tools/testing/selftests/ublk/test_null_03.sh | 24 +++++++ .../testing/selftests/ublk/test_stress_04.sh | 12 ++-- .../testing/selftests/ublk/test_stress_05.sh | 10 +-- .../testing/selftests/ublk/test_stress_06.sh | 39 +++++++++++ .../testing/selftests/ublk/test_stress_07.sh | 39 +++++++++++ .../testing/selftests/ublk/test_stripe_05.sh | 26 ++++++++ .../testing/selftests/ublk/test_stripe_06.sh | 21 ++++++ tools/testing/selftests/ublk/trace/seq_io.bt | 3 +- 20 files changed, 336 insertions(+), 27 deletions(-) create mode 100755 tools/testing/selftests/ublk/test_generic_14.sh create mode 100755 tools/testing/selftests/ublk/test_loop_06.sh create mode 100755 tools/testing/selftests/ublk/test_loop_07.sh create mode 100755 tools/testing/selftests/ublk/test_null_03.sh create mode 100755 tools/testing/selftests/ublk/test_stress_06.sh create mode 100755 tools/testing/selftests/ublk/test_stress_07.sh create mode 100755 tools/testing/selftests/ublk/test_stripe_05.sh create mode 100755 tools/testing/selftests/ublk/test_stripe_06.sh
Signature · 1 line
2.45.2
PATCH v2 1/8 selftests: ublk: correct last_rw map type in seq_io.bt
The last_rw map is initialized with a value of 0 but later assigned the
value args.sector + args.nr_sector, which has type sector_t = u64.
bpftrace complains about the type mismatch between int64 and uint64:
trace/seq_io.bt:18:3-59: ERROR: Type mismatch for @last_rw: trying to assign value of type 'uint64' when map already contains a value of type 'int64'
@last_rw[$dev, str($2)] = (args.sector + args.nr_sector);
Cast the initial value to uint64 so bpftrace will load the program.
--- tools/testing/selftests/ublk/trace/seq_io.bt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ublk/trace/seq_io.bt +1 -1
@@ -2,11 +2,11 @@ $1: dev_t $2: RWBS $3: strlen($2) */ BEGIN { - @last_rw[$1, str($2)] = 0; + @last_rw[$1, str($2)] = (uint64)0; } tracepoint:block:block_rq_complete { $dev = $1; if ((int64)args.dev == $1 && !strncmp(args.rwbs, str($2), $3)) {
Signature · 1 line
2.45.2
PATCH v2 2/8 selftests: ublk: remove unused ios map in seq_io.bt
In reply to Caleb Sander MateosThe ios map populated by seq_io.bt is never read, so remove it.
--- tools/testing/selftests/ublk/trace/seq_io.bt | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/ublk/trace/seq_io.bt +0 -1
@@ -15,11 +15,10 @@ tracepoint:block:block_rq_complete printf("io_out_of_order: exp %llu actual %llu\n", args.sector, $last); } @last_rw[$dev, str($2)] = (args.sector + args.nr_sector); } - @ios = count(); } END { clear(@last_rw); }
Signature · 1 line
2.45.2
PATCH v2 3/8 selftests: ublk: fix fio arguments in run_io_and_recover()
In reply to Caleb Sander Mateosrun_io_and_recover() invokes fio with --size="${size}", but the variable size doesn't exist. Thus, the argument expands to --size=, which causes fio to exit immediately with an error without issuing any I/O. Pass the value for size as the first argument to the function.
--- tools/testing/selftests/ublk/test_common.sh | 5 +++-- tools/testing/selftests/ublk/test_generic_04.sh | 2 +- tools/testing/selftests/ublk/test_generic_05.sh | 2 +- tools/testing/selftests/ublk/test_generic_11.sh | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
tools/testing/selftests/ublk/test_common.sh +3 -2
@@ -331,15 +331,16 @@ run_io_and_kill_daemon() fi } run_io_and_recover() { - local action=$1 + local size=$1 + local action=$2 local state local dev_id - shift 1 + shift 2 dev_id=$(_add_ublk_dev "$@") _check_add_dev "$TID" $? fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \ --rw=randread --iodepth=256 --size="${size}" --numjobs=4 \
tools/testing/selftests/ublk/test_generic_04.sh +1 -1
@@ -6,11 +6,11 @@ TID="generic_04" ERR_CODE=0 ublk_run_recover_test() { - run_io_and_recover "kill_daemon" "$@" + run_io_and_recover 256M "kill_daemon" "$@" ERR_CODE=$? if [ ${ERR_CODE} -ne 0 ]; then echo "$TID failure: $*" _show_result $TID $ERR_CODE fi
tools/testing/selftests/ublk/test_generic_05.sh +1 -1
@@ -6,11 +6,11 @@ TID="generic_05" ERR_CODE=0 ublk_run_recover_test() { - run_io_and_recover "kill_daemon" "$@" + run_io_and_recover 256M "kill_daemon" "$@" ERR_CODE=$? if [ ${ERR_CODE} -ne 0 ]; then echo "$TID failure: $*" _show_result $TID $ERR_CODE fi
tools/testing/selftests/ublk/test_generic_11.sh +1 -1
@@ -6,11 +6,11 @@ TID="generic_11" ERR_CODE=0 ublk_run_quiesce_recover() { - run_io_and_recover "quiesce_dev" "$@" + run_io_and_recover 256M "quiesce_dev" "$@" ERR_CODE=$? if [ ${ERR_CODE} -ne 0 ]; then echo "$TID failure: $*" _show_result $TID $ERR_CODE fi
Signature · 1 line
2.45.2
PATCH v2 4/8 selftests: ublk: use auto_zc for PER_IO_DAEMON tests in stress_04
In reply to Caleb Sander Mateosstress_04 is described as "run IO and kill ublk server(zero copy)" but the --per_io_tasks tests cases don't use zero copy. Plus, one of the test cases is duplicated. Add --auto_zc to these test cases and --auto_zc_fallback to one of the duplicated ones. This matches the test cases in stress_03.
--- tools/testing/selftests/ublk/test_stress_04.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/ublk/test_stress_04.sh +4 -4
@@ -38,14 +38,14 @@ if _have_feature "AUTO_BUF_REG"; then ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --no_ublk_fixed_fd "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback & fi if _have_feature "PER_IO_DAEMON"; then - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & - ublk_io_and_kill_daemon 256M -t loop -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & - ublk_io_and_kill_daemon 256M -t stripe -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & + ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --auto_zc_fallback --nthreads 8 --per_io_tasks & fi wait _cleanup_test "stress" _show_result $TID $ERR_CODE
Signature · 1 line
2.45.2
Re: [PATCH v2 4/8] selftests: ublk: use auto_zc for PER_IO_DAEMON tests in stress_04
Quoted 7 lines · Caleb Sander Mateos
stress_04is described as "run IO and kill ublk server(zero copy)" but the --per_io_tasks tests cases don't use zero copy. Plus, one of the test cases is duplicated. Add --auto_zc to these test cases and --auto_zc_fallback to one of the duplicated ones. This matches the test cases instress_03.Signed-off-by Caleb Sander Mateos <[email protected]>
Thanks,
Ming
Re: [PATCH v2 4/8] selftests: ublk: use auto_zc for PER_IO_DAEMON tests in stress_04
In reply to Caleb Sander MateosQuoted 19 lines · Caleb Sander Mateos
stress_04is described as "run IO and kill ublk server(zero copy)" but the --per_io_tasks tests cases don't use zero copy. Plus, one of the test cases is duplicated. Add --auto_zc to these test cases and --auto_zc_fallback to one of the duplicated ones. This matches the test cases instress_03.Signed-off-by Caleb Sander Mateos <[email protected]>--- tools/testing/selftests/ublk/test_stress_04.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/testing/selftests/ublk/test_stress_04.sh +0
-0@@ -38,14 +38,14 @@ if _have_feature "AUTO_BUF_REG"; then ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --no_ublk_fixed_fd "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback & fi
tools/testing/selftests/ublk/test_stress_04.sh if _have_feature "AUTO_BUF_REG"; then · line 46
Quoted 10 lines
tools/testing/selftests/ublk/test_stress_04.sh +4
-4if _have_feature "PER_IO_DAEMON"; then - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & - ublk_io_and_kill_daemon 256M -t loop -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & - ublk_io_and_kill_daemon 256M -t stripe -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & + ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --auto_zc_fallback --nthreads 8 --per_io_tasks &
The last line needs -z, otherwise the following warning is dumped:
``` # selftests: ublk: test_stress_04.sh # main: auto_zc_fallback is set but neither F_AUTO_BUF_REG nor F_SUPPORT_ZERO_COPY is enabled # stress_04 : [FAIL] ```
Thanks,
Ming
Re: [PATCH v2 4/8] selftests: ublk: use auto_zc for PER_IO_DAEMON tests in stress_04
Quoted 34 lines · Ming Lei
Quoted 19 lines · Caleb Sander Mateos
stress_04is described as "run IO and kill ublk server(zero copy)" but the --per_io_tasks tests cases don't use zero copy. Plus, one of the test cases is duplicated. Add --auto_zc to these test cases and --auto_zc_fallback to one of the duplicated ones. This matches the test cases instress_03.Signed-off-by Caleb Sander Mateos <[email protected]>--- tools/testing/selftests/ublk/test_stress_04.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/testing/selftests/ublk/test_stress_04.sh +0
-0@@ -38,14 +38,14 @@ if _have_feature "AUTO_BUF_REG"; then ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --no_ublk_fixed_fd "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback & fitools/testing/selftests/ublk/test_stress_04.sh if _have_feature "AUTO_BUF_REG"; then · line 46
Quoted 10 lines
tools/testing/selftests/ublk/test_stress_04.sh +4
-4if _have_feature "PER_IO_DAEMON"; then - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & - ublk_io_and_kill_daemon 256M -t loop -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & - ublk_io_and_kill_daemon 256M -t stripe -q 4 --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & - ublk_io_and_kill_daemon 8G -t null -q 4 --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --nthreads 8 --per_io_tasks & + ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & + ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & + ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --auto_zc_fallback --nthreads 8 --per_io_tasks &The last line needs
-z, otherwise the following warning is dumped:
Quoted 5 lines
``` # selftests: ublk: test_stress_04.sh # main: auto_zc_fallback is set but neither F_AUTO_BUF_REG nor F_SUPPORT_ZERO_COPY is enabled # stress_04 : [FAIL] ```
Yeah, duh! I swear I tested this... Oh, it's because I had revised this patch following your initial feedback but replaced it with the version from v1 right before sending it. Will fix.
Thanks,
Caleb
PATCH v2 5/8 selftests: ublk: don't share backing files between ublk servers
In reply to Caleb Sander Mateosstress_04 is missing a wait between blocks of tests, meaning multiple ublk servers will be running in parallel using the same backing files. Add a wait after each section to ensure each backing file is in use by a single ublk server at a time.
--- tools/testing/selftests/ublk/test_stress_04.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/ublk/test_stress_04.sh +3 -1
@@ -29,23 +29,25 @@ _create_backfile 1 128M _create_backfile 2 128M ublk_io_and_kill_daemon 8G -t null -q 4 -z --no_ublk_fixed_fd & ublk_io_and_kill_daemon 256M -t loop -q 4 -z --no_ublk_fixed_fd "${UBLK_BACKFILES[0]}" & ublk_io_and_kill_daemon 256M -t stripe -q 4 -z "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait if _have_feature "AUTO_BUF_REG"; then ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc & ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc "${UBLK_BACKFILES[0]}" & ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --no_ublk_fixed_fd "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & ublk_io_and_kill_daemon 8G -t null -q 4 -z --auto_zc --auto_zc_fallback & + wait fi if _have_feature "PER_IO_DAEMON"; then ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --nthreads 8 --per_io_tasks & ublk_io_and_kill_daemon 256M -t loop -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & ublk_io_and_kill_daemon 256M -t stripe -q 4 --auto_zc --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & ublk_io_and_kill_daemon 8G -t null -q 4 --auto_zc --auto_zc_fallback --nthreads 8 --per_io_tasks & + wait fi -wait _cleanup_test "stress" _show_result $TID $ERR_CODE
Signature · 1 line
2.45.2
PATCH v2 6/8 selftests: ublk: forbid multiple data copy modes
In reply to Caleb Sander MateosThe kublk mock ublk server allows multiple data copy mode arguments to be passed on the command line (--zero_copy, --get_data, and --auto_zc). The ublk device will be created with all the requested feature flags, however kublk will only use one of the modes to interact with request data (arbitrarily preferring auto_zc over zero_copy over get_data). To clarify the intent of the test, don't allow multiple data copy modes to be specified. --zero_copy and --auto_zc are allowed together for --auto_zc_fallback, which uses both copy modes.
Don't set UBLK_F_USER_COPY for zero_copy, as it's a separate feature. Fix the test cases in test_stress_05 passing --get_data along with --zero_copy or --auto_zc.
--- tools/testing/selftests/ublk/kublk.c | 11 ++++++++++- tools/testing/selftests/ublk/test_stress_05.sh | 10 +++++----- 2 files changed, 15 insertions(+), 6 deletions(-)
tools/testing/selftests/ublk/kublk.c +10 -1
@@ -1611,11 +1611,11 @@ int main(int argc, char *argv[])break ;case 'd' : ctx.queue_depth =strtol (optarg,NULL ,10 );break ;case 'z' : - ctx.flags |=UBLK_F_SUPPORT_ZERO_COPY |UBLK_F_USER_COPY ; + ctx.flags |=UBLK_F_SUPPORT_ZERO_COPY ;break ;case 'r' : value =strtol (optarg,NULL ,10 );if (value) ctx.flags |=UBLK_F_USER_RECOVERY ;
@@ -1684,10 +1684,19 @@ int main(int argc, char *argv[])"F_AUTO_BUF_REG nor F_SUPPORT_ZERO_COPY is enabled\n" , __func__);return -EINVAL ; } +if (!!(ctx.flags &UBLK_F_NEED_GET_DATA ) + + !!(ctx.flags &UBLK_F_USER_COPY ) + + (ctx.flags &UBLK_F_SUPPORT_ZERO_COPY && !ctx.auto_zc_fallback) + + (ctx.flags &UBLK_F_AUTO_BUF_REG && !ctx.auto_zc_fallback) + + ctx.auto_zc_fallback >1 ) { +fprintf (stderr,"too many data copy modes specified\n" ); +return -EINVAL ; + } + i = optind;while (i < argc && ctx.nr_files <MAX_BACK_FILES ) { ctx.files[ctx.nr_files++] = argv[i++]; }
tools/testing/selftests/ublk/test_stress_05.sh +5 -5
@@ -56,21 +56,21 @@ for reissue in $(seq 0 1); do wait done if _have_feature "ZERO_COPY"; then for reissue in $(seq 0 1); do - ublk_io_and_remove 8G -t null -q 4 -g -z -r 1 -i "$reissue" & - ublk_io_and_remove 256M -t loop -q 4 -g -z -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" & + ublk_io_and_remove 8G -t null -q 4 -z -r 1 -i "$reissue" & + ublk_io_and_remove 256M -t loop -q 4 -z -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" & wait done fi if _have_feature "AUTO_BUF_REG"; then for reissue in $(seq 0 1); do - ublk_io_and_remove 8G -t null -q 4 -g --auto_zc -r 1 -i "$reissue" & - ublk_io_and_remove 256M -t loop -q 4 -g --auto_zc -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" & - ublk_io_and_remove 8G -t null -q 4 -g -z --auto_zc --auto_zc_fallback -r 1 -i "$reissue" & + ublk_io_and_remove 8G -t null -q 4 --auto_zc -r 1 -i "$reissue" & + ublk_io_and_remove 256M -t loop -q 4 --auto_zc -r 1 -i "$reissue" "${UBLK_BACKFILES[1]}" & + ublk_io_and_remove 8G -t null -q 4 -z --auto_zc --auto_zc_fallback -r 1 -i "$reissue" & wait done fi if _have_feature "PER_IO_DAEMON"; then
Signature · 1 line
2.45.2
Re: [PATCH v2 6/8] selftests: ublk: forbid multiple data copy modes
Quoted 12 lines · Caleb Sander Mateos
The kublk mock ublk server allows multiple data copy mode arguments to be passed on the command line (--zero_copy, --get_data, and --auto_zc). The ublk device will be created with all the requested feature flags, however kublk will only use one of the modes to interact with request data (arbitrarily preferring
auto_zcoverzero_copyoverget_data). To clarify the intent of the test, don't allow multiple data copy modes to be specified. --zero_copy and --auto_zc are allowed together for --auto_zc_fallback, which uses both copy modes.
Don't setUBLK_F_USER_COPYforzero_copy, as it's a separate feature. Fix the test cases intest_stress_05passing --get_data along with --zero_copy or --auto_zc.
Quoted 1 line
Signed-off-by Caleb Sander Mateos <[email protected]>
Thanks,
Ming
Re: [PATCH v2 6/8] selftests: ublk: forbid multiple data copy modes
In reply to Caleb Sander MateosQuoted 12 lines · Caleb Sander Mateos
The kublk mock ublk server allows multiple data copy mode arguments to be passed on the command line (--zero_copy, --get_data, and --auto_zc). The ublk device will be created with all the requested feature flags, however kublk will only use one of the modes to interact with request data (arbitrarily preferring
auto_zcoverzero_copyoverget_data). To clarify the intent of the test, don't allow multiple data copy modes to be specified. --zero_copy and --auto_zc are allowed together for --auto_zc_fallback, which uses both copy modes.
Don't setUBLK_F_USER_COPYforzero_copy, as it's a separate feature. Fix the test cases intest_stress_05passing --get_data along with --zero_copy or --auto_zc.
Quoted 1 line
Signed-off-by Caleb Sander Mateos <[email protected]>
Thanks,
Ming
PATCH v2 7/8 selftests: ublk: add support for user copy to kublk
In reply to Caleb Sander MateosThe ublk selftests mock ublk server kublk supports every data copy mode except user copy. Add support for user copy to kublk, enabled via the --user_copy (-u) command line argument. On writes, issue pread() calls to copy the write data into the ublk_io's buffer before dispatching the write to the target implementation. On reads, issue pwrite() calls to copy read data from the ublk_io's buffer before committing the request. Copy in 2 KB chunks to provide some coverage of the offseting logic.
--- tools/testing/selftests/ublk/file_backed.c | 7 +-- tools/testing/selftests/ublk/kublk.c | 53 ++++++++++++++++++++-- tools/testing/selftests/ublk/kublk.h | 11 +++++ tools/testing/selftests/ublk/stripe.c | 2 +- 4 files changed, 64 insertions(+), 9 deletions(-)
tools/testing/selftests/ublk/file_backed.c +4 -3
@@ -32,12 +32,13 @@ static int loop_queue_tgt_rw_io(struct ublk_thread *t, struct ublk_queue *q, {unsigned ublk_op =ublksrv_get_op (iod);unsigned zc =ublk_queue_use_zc (q);unsigned auto_zc =ublk_queue_use_auto_zc (q);enum io_uring_op op =ublk_to_uring_op (iod, zc | auto_zc); +struct ublk_io *io =ublk_get_io (q, tag);struct io_uring_sqe *sqe[3 ]; -void *addr = (zc | auto_zc) ?NULL : (void *)iod->addr; +void *addr = io->buf_addr;if (!zc || auto_zc) {ublk_io_alloc_sqes (t, sqe,1 );if (!sqe[0 ])return -ENOMEM ;
@@ -54,11 +55,11 @@ static int loop_queue_tgt_rw_io(struct ublk_thread *t, struct ublk_queue *q,return 1 ; }ublk_io_alloc_sqes (t, sqe,3 ); -io_uring_prep_buf_register (sqe[0 ], q, tag, q->q_id,ublk_get_io (q, tag)->buf_index); +io_uring_prep_buf_register (sqe[0 ], q, tag, q->q_id, io->buf_index); sqe[0 ]->flags |=IOSQE_CQE_SKIP_SUCCESS |IOSQE_IO_HARDLINK ; sqe[0 ]->user_data =build_user_data (tag,ublk_cmd_op_nr (sqe[0 ]->cmd_op),0 , q->q_id,1 ); io_uring_prep_rw(op, sqe[1], ublk_get_registered_fd(q, 1) /*fds[1]*/, 0,
@@ -66,11 +67,11 @@ static int loop_queue_tgt_rw_io(struct ublk_thread *t, struct ublk_queue *q, iod->start_sector << 9); sqe[1 ]->buf_index = tag; sqe[1 ]->flags |=IOSQE_FIXED_FILE |IOSQE_IO_HARDLINK ; sqe[1 ]->user_data =build_user_data (tag, ublk_op,0 , q->q_id,1 ); -io_uring_prep_buf_unregister (sqe[2 ], q, tag, q->q_id,ublk_get_io (q, tag)->buf_index); +io_uring_prep_buf_unregister (sqe[2 ], q, tag, q->q_id, io->buf_index); sqe[2 ]->user_data =build_user_data (tag,ublk_cmd_op_nr (sqe[2 ]->cmd_op),0 , q->q_id,1 );return 2 ; }
tools/testing/selftests/ublk/kublk.c +48 -5
134 lines not on this page · raw message
tools/testing/selftests/ublk/kublk.h +11 -0
@@ -206,10 +206,16 @@ extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io);static inline int ublk_io_auto_zc_fallback (const struct ublksrv_io_desc *iod) {return !!(iod->op_flags &UBLK_IO_F_NEED_REG_BUF ); } +static inline __u64 ublk_user_copy_offset (unsigned q_id,unsigned tag) +{ +return UBLKSRV_IO_BUF_OFFSET + + ((__u64 )q_id <<UBLK_QID_OFF | (__u64 )tag <<UBLK_TAG_OFF ); +} +static inline int is_target_io (__u64 user_data) {return (user_data & (1ULL <<63 )) !=0 ; }
@@ -403,10 +409,15 @@ static inline int ublk_queue_use_auto_zc(const struct ublk_queue *q)static inline int ublk_queue_auto_zc_fallback (const struct ublk_queue *q) {return q->flags &UBLKS_Q_AUTO_BUF_REG_FALLBACK ; } +static inline bool ublk_queue_use_user_copy (const struct ublk_queue *q) +{ +return !!(q->flags &UBLK_F_USER_COPY ); +} +static inline int ublk_queue_no_buf (const struct ublk_queue *q) {return ublk_queue_use_zc (q) ||ublk_queue_use_auto_zc (q); }
tools/testing/selftests/ublk/stripe.c +1 -1
@@ -132,11 +132,11 @@ static int stripe_queue_tgt_rw_io(struct ublk_thread *t, struct ublk_queue *q,enum io_uring_op op =stripe_to_uring_op (iod, zc | auto_zc);struct io_uring_sqe *sqe[NR_STRIPE ];struct stripe_array *s =alloc_stripe_array (conf, iod);struct ublk_io *io =ublk_get_io (q, tag);int i, extra = zc ?2 :0 ; -void *base = (zc | auto_zc) ?NULL : (void *)iod->addr; +void *base = io->buf_addr; io->private_data = s;calculate_stripe_array (conf, iod, s, base);ublk_io_alloc_sqes (t, sqe, s->nr + extra);
Signature · 1 line
2.45.2
Re: [PATCH v2 7/8] selftests: ublk: add support for user copy to kublk
Quoted 9 lines · Caleb Sander Mateos
The ublk selftests mock ublk server kublk supports every data copy mode except user copy. Add support for user copy to kublk, enabled via the --user_copy (-u) command line argument. On writes, issue
pread()calls to copy the write data into the ublk_io's buffer before dispatching the write to the target implementation. On reads, issuepwrite()calls to copy read data from the ublk_io's buffer before committing the request. Copy in 2 KB chunks to provide some coverage of the offseting logic.Signed-off-by Caleb Sander Mateos <[email protected]>
Thanks,
Ming
PATCH v2 8/8 selftests: ublk: add user copy test cases
In reply to Caleb Sander MateosThe ublk selftests cover every data copy mode except user copy. Add tests for user copy based on the existing test suite:
- generic_14 ("basic recover function verification (user copy)") based on generic_04 and generic_05
- null_03 ("basic IO test with user copy") based on null_01 and null_02
- loop_06 ("write and verify over user copy") based on loop_01 and loop_03
- loop_07 ("mkfs & mount & umount with user copy") based on loop_02 and loop_04
- stripe_05 ("write and verify test on user copy") based on stripe_03
- stripe_06 ("mkfs & mount & umount on user copy") based on stripe_02 and stripe_04
- stress_06 ("run IO and remove device (user copy)") based on stress_01 and stress_03
- stress_07 ("run IO and kill ublk server (user copy)") based on stress_02 and stress_04
--- tools/testing/selftests/ublk/Makefile | 8 ++++ .../testing/selftests/ublk/test_generic_14.sh | 40 +++++++++++++++++++ tools/testing/selftests/ublk/test_loop_06.sh | 25 ++++++++++++ tools/testing/selftests/ublk/test_loop_07.sh | 21 ++++++++++ tools/testing/selftests/ublk/test_null_03.sh | 24 +++++++++++ .../testing/selftests/ublk/test_stress_06.sh | 39 ++++++++++++++++++ .../testing/selftests/ublk/test_stress_07.sh | 39 ++++++++++++++++++ .../testing/selftests/ublk/test_stripe_05.sh | 26 ++++++++++++ .../testing/selftests/ublk/test_stripe_06.sh | 21 ++++++++++ 9 files changed, 243 insertions(+) create mode 100755 tools/testing/selftests/ublk/test_generic_14.sh create mode 100755 tools/testing/selftests/ublk/test_loop_06.sh create mode 100755 tools/testing/selftests/ublk/test_loop_07.sh create mode 100755 tools/testing/selftests/ublk/test_null_03.sh create mode 100755 tools/testing/selftests/ublk/test_stress_06.sh create mode 100755 tools/testing/selftests/ublk/test_stress_07.sh create mode 100755 tools/testing/selftests/ublk/test_stripe_05.sh create mode 100755 tools/testing/selftests/ublk/test_stripe_06.sh
tools/testing/selftests/ublk/Makefile +8 -0
@@ -19,28 +19,36 @@ TEST_PROGS += test_generic_08.sh TEST_PROGS += test_generic_09.sh TEST_PROGS += test_generic_10.sh TEST_PROGS += test_generic_11.sh TEST_PROGS += test_generic_12.sh TEST_PROGS += test_generic_13.sh +TEST_PROGS += test_generic_14.sh TEST_PROGS += test_null_01.sh TEST_PROGS += test_null_02.sh +TEST_PROGS += test_null_03.sh TEST_PROGS += test_loop_01.sh TEST_PROGS += test_loop_02.sh TEST_PROGS += test_loop_03.sh TEST_PROGS += test_loop_04.sh TEST_PROGS += test_loop_05.sh +TEST_PROGS += test_loop_06.sh +TEST_PROGS += test_loop_07.sh TEST_PROGS += test_stripe_01.sh TEST_PROGS += test_stripe_02.sh TEST_PROGS += test_stripe_03.sh TEST_PROGS += test_stripe_04.sh +TEST_PROGS += test_stripe_05.sh +TEST_PROGS += test_stripe_06.sh TEST_PROGS += test_stress_01.sh TEST_PROGS += test_stress_02.sh TEST_PROGS += test_stress_03.sh 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_GEN_PROGS_EXTENDED = kublk include ../lib.mk
tools/testing/selftests/ublk/test_generic_14.sh new file +40 -0
@@ -0,0 +1,40 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="generic_14" +ERR_CODE=0 + +ublk_run_recover_test() +{ + run_io_and_recover 256M "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 + +_prep_test "recover" "basic recover function verification (user copy)" + +_create_backfile 0 256M +_create_backfile 1 128M +_create_backfile 2 128M + +ublk_run_recover_test -t null -q 2 -r 1 -u & +ublk_run_recover_test -t loop -q 2 -r 1 -u "${UBLK_BACKFILES[0]}" & +ublk_run_recover_test -t stripe -q 2 -r 1 -u "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +ublk_run_recover_test -t null -q 2 -r 1 -u -i 1 & +ublk_run_recover_test -t loop -q 2 -r 1 -u -i 1 "${UBLK_BACKFILES[0]}" & +ublk_run_recover_test -t stripe -q 2 -r 1 -u -i 1 "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +_cleanup_test "recover" +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_loop_06.sh new file +25 -0
@@ -0,0 +1,25 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="loop_06" +ERR_CODE=0 + +if ! _have_program fio; then + exit "$UBLK_SKIP_CODE" +fi + +_prep_test "loop" "write and verify over user copy" + +_create_backfile 0 256M +dev_id=$(_add_ublk_dev -t loop -u "${UBLK_BACKFILES[0]}") +_check_add_dev $TID $? + +# run fio over the ublk disk +_run_fio_verify_io --filename=/dev/ublkb"${dev_id}" --size=256M +ERR_CODE=$? + +_cleanup_test "loop" + +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_loop_07.sh new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="loop_07" +ERR_CODE=0 + +_prep_test "loop" "mkfs & mount & umount with user copy" + +_create_backfile 0 256M + +dev_id=$(_add_ublk_dev -t loop -u "${UBLK_BACKFILES[0]}") +_check_add_dev $TID $? + +_mkfs_mount_test /dev/ublkb"${dev_id}" +ERR_CODE=$? + +_cleanup_test "loop" + +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_null_03.sh new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="null_03" +ERR_CODE=0 + +if ! _have_program fio; then + exit "$UBLK_SKIP_CODE" +fi + +_prep_test "null" "basic IO test with user copy" + +dev_id=$(_add_ublk_dev -t null -u) +_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 +ERR_CODE=$? + +_cleanup_test "null" + +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_stress_06.sh new file +39 -0
@@ -0,0 +1,39 @@ +#!/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 + +_prep_test "stress" "run IO and remove device (user copy)" + +_create_backfile 0 256M +_create_backfile 1 128M +_create_backfile 2 128M + +ublk_io_and_remove 8G -t null -q 4 -u & +ublk_io_and_remove 256M -t loop -q 4 -u "${UBLK_BACKFILES[0]}" & +ublk_io_and_remove 256M -t stripe -q 4 -u "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +ublk_io_and_remove 8G -t null -q 4 -u --nthreads 8 --per_io_tasks & +ublk_io_and_remove 256M -t loop -q 4 -u --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & +ublk_io_and_remove 256M -t stripe -q 4 -u --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +_cleanup_test "stress" +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_stress_07.sh new file +39 -0
@@ -0,0 +1,39 @@ +#!/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 + +_prep_test "stress" "run IO and kill ublk server (user copy)" + +_create_backfile 0 256M +_create_backfile 1 128M +_create_backfile 2 128M + +ublk_io_and_kill_daemon 8G -t null -q 4 -u --no_ublk_fixed_fd & +ublk_io_and_kill_daemon 256M -t loop -q 4 -u --no_ublk_fixed_fd "${UBLK_BACKFILES[0]}" & +ublk_io_and_kill_daemon 256M -t stripe -q 4 -u "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +ublk_io_and_kill_daemon 8G -t null -q 4 -u --nthreads 8 --per_io_tasks & +ublk_io_and_kill_daemon 256M -t loop -q 4 -u --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[0]}" & +ublk_io_and_kill_daemon 256M -t stripe -q 4 -u --nthreads 8 --per_io_tasks "${UBLK_BACKFILES[1]}" "${UBLK_BACKFILES[2]}" & +wait + +_cleanup_test "stress" +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_stripe_05.sh new file +26 -0
@@ -0,0 +1,26 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="stripe_05" +ERR_CODE=0 + +if ! _have_program fio; then + exit "$UBLK_SKIP_CODE" +fi + +_prep_test "stripe" "write and verify test on user copy" + +_create_backfile 0 256M +_create_backfile 1 256M + +dev_id=$(_add_ublk_dev -t stripe -q 2 -u "${UBLK_BACKFILES[0]}" "${UBLK_BACKFILES[1]}") +_check_add_dev $TID $? + +# run fio over the ublk disk +_run_fio_verify_io --filename=/dev/ublkb"${dev_id}" --size=512M +ERR_CODE=$? + +_cleanup_test "stripe" +_show_result $TID $ERR_CODE
tools/testing/selftests/ublk/test_stripe_06.sh new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh + +TID="stripe_06" +ERR_CODE=0 + +_prep_test "stripe" "mkfs & mount & umount on user copy" + +_create_backfile 0 256M +_create_backfile 1 256M + +dev_id=$(_add_ublk_dev -t stripe -u -q 2 "${UBLK_BACKFILES[0]}" "${UBLK_BACKFILES[1]}") +_check_add_dev $TID $? + +_mkfs_mount_test /dev/ublkb"${dev_id}" +ERR_CODE=$? + +_cleanup_test "stripe" +_show_result $TID $ERR_CODE
Signature · 1 line
2.45.2
Quoted 17 lines · Caleb Sander Mateos
The ublk selftests cover every data copy mode except user copy. Add tests for user copy based on the existing test suite:
-generic_14("basic recover function verification (user copy)") based ongeneric_04andgeneric_05
-null_03("basic IO test with user copy") based onnull_01andnull_02
-loop_06("write and verify over user copy") based onloop_01andloop_03
-loop_07("mkfs & mount & umount with user copy") based onloop_02andloop_04
-stripe_05("write and verify test on user copy") based onstripe_03
-stripe_06("mkfs & mount & umount on user copy") based onstripe_02andstripe_04
-stress_06("run IO and remove device (user copy)") based onstress_01andstress_03
-stress_07("run IO and kill ublk server (user copy)") based onstress_02andstress_04
Quoted 1 line
Signed-off-by Caleb Sander Mateos <[email protected]>
Thanks,
Ming