1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# All rights reserved. 4# 5 6testdir=$(readlink -f "$(dirname "$0")") 7rootdir=$(readlink -f "$testdir/../../") 8source "$testdir/common.sh" 9 10cleanup() { 11 rm $aio_disk 12 rm $file1 13 rm $file2 14 rm $file3 15} 16 17prepare() { 18 truncate $aio_disk --size 104857600 19 20 dd if=/dev/zero of=$file1 bs=4M count=1 21 dd if=/dev/zero of=$file1 bs=4M count=1 seek=4 22 dd if=/dev/zero of=$file1 bs=4M count=1 seek=8 23} 24 25file_to_file() { 26 local stat1_s stat1_b 27 local stat2_s stat2_b 28 29 local -A method_bdev_aio_create_0=( 30 ["filename"]=$aio_disk 31 ["name"]=$aio_bdev 32 ["block_size"]=4096 33 ) 34 35 local -A method_bdev_lvol_create_lvstore_1=( 36 ["bdev_name"]=$aio_bdev 37 ["lvs_name"]=$lvstore 38 ) 39 40 "${DD_APP[@]}" \ 41 --if="$file1" \ 42 --of="$file2" \ 43 --bs=12582912 \ 44 --sparse \ 45 --json <(gen_conf) 46 47 stat1_s=$(stat --printf='%s' $file1) 48 stat2_s=$(stat --printf='%s' $file2) 49 50 [[ $stat1_s == "$stat2_s" ]] 51 52 stat1_b=$(stat --printf='%b' $file1) 53 stat2_b=$(stat --printf='%b' $file2) 54 55 [[ $stat1_b == "$stat2_b" ]] 56} 57 58file_to_bdev() { 59 local -A method_bdev_aio_create_0=( 60 ["filename"]=$aio_disk 61 ["name"]=$aio_bdev 62 ["block_size"]=4096 63 ) 64 65 local -A method_bdev_lvol_create_1=( 66 ["lvs_name"]=$lvstore 67 ["lvol_name"]=$lvol 68 ["size_in_mib"]=36 69 ["thin_provision"]=true 70 ) 71 72 "${DD_APP[@]}" \ 73 --if="$file2" \ 74 --ob="$lvstore/$lvol" \ 75 --bs=12582912 \ 76 --sparse \ 77 --json <(gen_conf) 78} 79 80bdev_to_file() { 81 local stat2_s stat2_b 82 local stat3_s stat3_b 83 84 local -A method_bdev_aio_create_0=( 85 ["filename"]=$aio_disk 86 ["name"]=$aio_bdev 87 ["block_size"]=4096 88 ) 89 90 "${DD_APP[@]}" \ 91 --ib="$lvstore/$lvol" \ 92 --of="$file3" \ 93 --bs=12582912 \ 94 --sparse \ 95 --json <(gen_conf) 96 97 stat2_s=$(stat --printf='%s' $file2) 98 stat3_s=$(stat --printf='%s' $file3) 99 100 [[ $stat2_s == "$stat3_s" ]] 101 102 stat2_b=$(stat --printf='%b' $file2) 103 stat3_b=$(stat --printf='%b' $file3) 104 105 [[ $stat2_b == "$stat3_b" ]] 106} 107 108aio_disk="dd_sparse_aio_disk" 109aio_bdev="dd_aio" 110file1="file_zero1" 111file2="file_zero2" 112file3="file_zero3" 113lvstore="dd_lvstore" 114lvol="dd_lvol" 115 116trap "cleanup" EXIT 117 118prepare 119 120run_test "dd_sparse_file_to_file" file_to_file 121run_test "dd_sparse_file_to_bdev" file_to_bdev 122run_test "dd_sparse_bdev_to_file" bdev_to_file 123