diff --git a/test/dd/common.sh b/test/dd/common.sh index 5c63c1ebaa..2205f7a7e6 100644 --- a/test/dd/common.sh +++ b/test/dd/common.sh @@ -159,3 +159,30 @@ check_liburing() { fi done < <(LD_TRACE_LOADED_OBJECTS=1 "${DD_APP[@]}") >&2 } + +init_zram() { + [[ -e /sys/class/zram-control ]] || modprobe zram num_devices=0 + return +} + +create_zram_dev() { + cat /sys/class/zram-control/hot_add +} + +remove_zram_dev() { + local id=$1 + + [[ -e /sys/block/zram$id ]] + + echo 1 > "/sys/block/zram$id/reset" + echo "$id" > "/sys/class/zram-control/hot_remove" +} + +set_zram_dev() { + local id=$1 + local size=${2:-64M} + + [[ -e /sys/block/zram$id ]] + + echo "$size" > "/sys/block/zram$id/disksize" +} diff --git a/test/dd/dd.sh b/test/dd/dd.sh index 011c9799e3..cbd10212e6 100755 --- a/test/dd/dd.sh +++ b/test/dd/dd.sh @@ -17,3 +17,6 @@ run_test "spdk_dd_basic_rw" "$testdir/basic_rw.sh" "${nvmes[@]}" run_test "spdk_dd_posix" "$testdir/posix.sh" run_test "spdk_dd_malloc" "$testdir/malloc.sh" run_test "spdk_dd_bdev_to_bdev" "$testdir/bdev_to_bdev.sh" "${nvmes[@]}" +if ((SPDK_TEST_URING == 1)); then + run_test "spdk_dd_uring" "$testdir/uring.sh" +fi diff --git a/test/dd/uring.sh b/test/dd/uring.sh new file mode 100755 index 0000000000..4d2b78bcef --- /dev/null +++ b/test/dd/uring.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +testdir=$(readlink -f "$(dirname "$0")") +rootdir=$(readlink -f "$testdir/../../") +source "$testdir/common.sh" + +uring_zram_copy() { + # Use zram for backend device - this is done in order to make the IO as fast + # as possible. + + local zram_dev_id + local magic + local magic_file0=$SPDK_TEST_STORAGE/magic.dump0 + local magic_file1=$SPDK_TEST_STORAGE/magic.dump1 + local verify_magic + + init_zram + zram_dev_id=$(create_zram_dev) + set_zram_dev "$zram_dev_id" 512M + + local ubdev=uring0 ufile=/dev/zram$zram_dev_id + + local -A method_bdev_uring_create_0=( + ["filename"]=$ufile + ["name"]=$ubdev + ) + + # Add extra malloc bdev + local mbdev=malloc0 mbdev_b=1048576 mbdev_bs=512 + + local -A method_bdev_malloc_create_0=( + ["name"]=$mbdev + ["num_blocks"]=$mbdev_b + ["block_size"]=$mbdev_bs + ) + + magic=$(gen_bytes $((mbdev_bs * 2))) + echo "$magic" > "$magic_file0" + + # Inflate the magic file to fill up entire zram of 512MB. + "${DD_APP[@]}" \ + --if=/dev/zero \ + --of="$magic_file0" \ + --oflag=append \ + --bs=$((mbdev_b * mbdev_bs - ${#magic} - 1)) \ + --count=1 + + # Copy magic file to uring bdev + "${DD_APP[@]}" \ + --if="$magic_file0" \ + --ob="$ubdev" \ + --json <(gen_conf) + + # Copy the whole uring bdev back to a file + "${DD_APP[@]}" \ + --ib="$ubdev" \ + --of="$magic_file1" \ + --json <(gen_conf) + + # Verify integrity of each copy + read -rn${#magic} verify_magic < "$magic_file1" + [[ $verify_magic == "$magic" ]] + + read -rn${#magic} verify_magic < "/dev/zram$zram_dev_id" + [[ $verify_magic == "$magic" ]] + + diff -q "$magic_file0" "$magic_file1" + + # Copy cotents of uring bdev to malloc bdev + "${DD_APP[@]}" \ + --ib="$ubdev" \ + --ob="$mbdev" \ + --json <(gen_conf) + + # HACK: small trick to utilize bdev_uring_delete and keep spdk_dd happy - + # read/write from 0-length files. + + local -A method_bdev_uring_delete_0=( + ["name"]="$ubdev" + ) + + "${DD_APP[@]}" \ + --if=<(:) \ + --of=<(:) \ + --json <(gen_conf) + + # Now try to copy to uring bdev which is explicitly deleted. We expect it + # to fail. + + NOT "${DD_APP[@]}" \ + --ib="$ubdev" \ + --of=<(:) \ + --json <(gen_conf) + + remove_zram_dev "$zram_dev_id" + rm -f "$magic_file0" "$magic_file1" +} + +run_test "dd_uring_copy" uring_zram_copy