xref: /spdk/test/dd/bdev_to_bdev.sh (revision 60982c759db49b4f4579f16e3b24df0725ba4b94)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2020 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f "$(dirname "$0")")
7rootdir=$(readlink -f "$testdir/../../")
8source "$testdir/common.sh"
9
10nvmes=("$@")
11
12offset_magic() {
13	local magic_check
14	local offsets offset
15
16	offsets=(16 64) # * bs
17
18	for offset in "${offsets[@]}"; do
19		"${DD_APP[@]}" \
20			--ib="$bdev0" \
21			--ob="$bdev1" \
22			--count="$count" \
23			--seek="$offset" \
24			--bs="$bs" \
25			--json <(gen_conf)
26
27		"${DD_APP[@]}" \
28			--ib="$bdev1" \
29			--of="$test_file1" \
30			--count=1 \
31			--skip="$offset" \
32			--bs="$bs" \
33			--json <(gen_conf)
34
35		read -rn${#magic} magic_check < "$test_file1"
36		[[ $magic_check == "$magic" ]]
37	done
38}
39
40cleanup() {
41	# Zero up to 64M on input|output bdev
42	clear_nvme "$bdev0" "" $((0x400000 + ${#magic}))
43	clear_nvme "$bdev1" "" $((0x400000 + ${#magic}))
44	rm -f "$test_file0" "$test_file1" "$aio1"
45}
46
47trap "cleanup" EXIT
48
49bs=$((1024 << 10))
50
51if ((${#nvmes[@]} > 1)); then
52	nvme0=Nvme0 bdev0=Nvme0n1 nvme0_pci=${nvmes[0]} # input bdev
53	nvme1=Nvme1 bdev1=Nvme1n1 nvme1_pci=${nvmes[1]} # output bdev
54
55	declare -A method_bdev_nvme_attach_controller_0=(
56		["name"]=$nvme0
57		["traddr"]=$nvme0_pci
58		["trtype"]=pcie
59	)
60	declare -A method_bdev_nvme_attach_controller_1=(
61		["name"]=$nvme1
62		["traddr"]=$nvme1_pci
63		["trtype"]=pcie
64	)
65else
66	# Use AIO to compensate lack of actual hardware
67	nvme0=Nvme0 bdev0=Nvme0n1 nvme0_pci=${nvmes[0]} # input bdev
68	aio1=$SPDK_TEST_STORAGE/aio1 bdev1=aio1         # output bdev
69
70	declare -A method_bdev_nvme_attach_controller_1=(
71		["name"]=$nvme0
72		["traddr"]=$nvme0_pci
73		["trtype"]=pcie
74	)
75	declare -A method_bdev_aio_create_0=(
76		["name"]=$bdev1
77		["filename"]=$aio1
78		["block_size"]=4096
79	)
80
81	# 256MB AIO file
82	"${DD_APP[@]}" \
83		--if=/dev/zero \
84		--of="$aio1" \
85		--bs="$bs" \
86		--count=256
87fi
88
89test_file0=$SPDK_TEST_STORAGE/dd.dump0
90test_file1=$SPDK_TEST_STORAGE/dd.dump1
91
92magic="This Is Our Magic, find it"
93echo "$magic" > "$test_file0"
94
95# Make the file a bit bigger (~64MB)
96run_test "dd_inflate_file" \
97	"${DD_APP[@]}" \
98	--if=/dev/zero \
99	--of="$test_file0" \
100	--oflag=append \
101	--bs="$bs" \
102	--count=64
103
104test_file0_size=$(wc -c < "$test_file0")
105
106# Now, copy it over to first nvme with default bs (4k)
107run_test "dd_copy_to_out_bdev" \
108	"${DD_APP[@]}" \
109	--if="$test_file0" \
110	--ob="$bdev0" \
111	--json <(gen_conf)
112
113count=$(((test_file0_size / bs) + 1))
114
115run_test "dd_offset_magic" offset_magic
116