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