1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2021 Intel Corporation 4# All rights reserved. 5# 6 7testdir=$(readlink -f "$(dirname "$0")") 8rootdir=$(readlink -f "$testdir/../../") 9source "$testdir/common.sh" 10 11uring_zram_copy() { 12 # Use zram for backend device - this is done in order to make the IO as fast 13 # as possible. 14 15 local zram_dev_id 16 local magic 17 local magic_file0=$SPDK_TEST_STORAGE/magic.dump0 18 local magic_file1=$SPDK_TEST_STORAGE/magic.dump1 19 local verify_magic 20 21 init_zram 22 zram_dev_id=$(create_zram_dev) 23 set_zram_dev "$zram_dev_id" 512M 24 25 local ubdev=uring0 ufile=/dev/zram$zram_dev_id 26 27 local -A method_bdev_uring_create_0=( 28 ["filename"]=$ufile 29 ["name"]=$ubdev 30 ) 31 32 # Add extra malloc bdev 33 local mbdev=malloc0 mbdev_b=1048576 mbdev_bs=512 34 35 local -A method_bdev_malloc_create_0=( 36 ["name"]=$mbdev 37 ["num_blocks"]=$mbdev_b 38 ["block_size"]=$mbdev_bs 39 ) 40 41 magic=$(gen_bytes $((mbdev_bs * 2))) 42 echo "$magic" > "$magic_file0" 43 44 # Inflate the magic file to fill up entire zram of 512MB. 45 "${DD_APP[@]}" \ 46 --if=/dev/zero \ 47 --of="$magic_file0" \ 48 --oflag=append \ 49 --bs=$((mbdev_b * mbdev_bs - ${#magic} - 1)) \ 50 --count=1 51 52 # Copy magic file to uring bdev 53 "${DD_APP[@]}" \ 54 --if="$magic_file0" \ 55 --ob="$ubdev" \ 56 --json <(gen_conf) 57 58 # Copy the whole uring bdev back to a file 59 "${DD_APP[@]}" \ 60 --ib="$ubdev" \ 61 --of="$magic_file1" \ 62 --json <(gen_conf) 63 64 # Verify integrity of each copy 65 read -rn${#magic} verify_magic < "$magic_file1" 66 [[ $verify_magic == "$magic" ]] 67 68 read -rn${#magic} verify_magic < "/dev/zram$zram_dev_id" 69 [[ $verify_magic == "$magic" ]] 70 71 diff -q "$magic_file0" "$magic_file1" 72 73 # Copy contents of uring bdev to malloc bdev 74 "${DD_APP[@]}" \ 75 --ib="$ubdev" \ 76 --ob="$mbdev" \ 77 --json <(gen_conf) 78 79 # HACK: small trick to utilize bdev_uring_delete and keep spdk_dd happy - 80 # read/write from 0-length files. 81 82 local -A method_bdev_uring_delete_0=( 83 ["name"]="$ubdev" 84 ) 85 86 "${DD_APP[@]}" \ 87 --if=<(:) \ 88 --of=<(:) \ 89 --json <(gen_conf) 90 91 # Now try to copy to uring bdev which is explicitly deleted. We expect it 92 # to fail. 93 94 NOT "${DD_APP[@]}" \ 95 --ib="$ubdev" \ 96 --of=<(:) \ 97 --json <(gen_conf) 98 99 remove_zram_dev "$zram_dev_id" 100 rm -f "$magic_file0" "$magic_file1" 101} 102 103run_test "dd_uring_copy" uring_zram_copy 104