Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / script / smr_benchmark / linearCopy.sh
1 #! /bin/bash
2
3 # copy a linear file from srcFile to destination disk in a loop until writeSize MBs is written
4 # destinationDisk is a SMR Host Aware Disk eg. /dev/sdb
5
6 if [ "$#" -lt 3 ]; then
7         echo "Usage ./linearCopy.sh srcFile destinationDisk writeSize(MB)"
8         exit
9 fi
10
11 if [ "$(id -u)" != "0" ]; then
12         echo "Please run as sudo user"
13         exit
14 fi
15
16 srcFile=$1
17 destDisk=$2
18 writeSize=$3
19 verbose=true
20
21 if [ -f time ]; then
22         rm -rf time
23 fi
24
25 #chunkSize=4096 # in bytes
26 chunkSize=1048576 # in bytes
27 fileSize=`stat --printf="%s" $srcFile`
28
29 numChunksInFile=`echo "$fileSize * (1048576 / $chunkSize)" | bc`
30 chunksLeft=$(( $(($writeSize * 1048576)) / $chunkSize))
31
32
33 echo "fileSize = $fileSize"
34
35 if [ "$(($fileSize % 512))" -ne 0 ]; then
36         echo "$srcFile not 512 byte aligned"
37         exit
38 fi
39
40 if [ "$(($chunkSize % 512))" -ne 0 ]; then
41         echo "$chunkSize not 512 byte aligned"
42         exit
43 fi
44
45 if [ "$fileSize" -lt "$chunkSize" ]; then
46         echo "filesize $fileSize should be greater than chunkSize $chunkSize"
47         exit
48 fi
49
50
51 numFileChunks=$(($fileSize / $chunkSize))
52 if [ $verbose == true ]; then
53         echo "numFileChunks = $numFileChunks"
54 fi
55
56 smrLBAStart=33554432 # TODO query from SMR Drive
57 #smrLBAStart=37224448
58
59 offset=$(( $smrLBAStart / $(( $chunkSize / 512)) ))
60
61 if [ $verbose == true ]; then
62         echo "chunksLeft = $chunksLeft, offset = $offset"
63 fi
64
65 chunkNum=0
66
67 while [ "$chunksLeft" -gt 0 ]; do
68         chunkNum=$(($chunkNum + 1))
69         if [ $verbose == true ]; then
70                 echo "CHUNK $chunkNum `date +%H:%M:%S`" >> time
71         fi
72         dd if=$srcFile of=$destDisk seek=$offset bs=$chunkSize 2> tmp 
73         cat tmp | grep MB >> time # > /dev/null 2>&1
74         if [ $verbose == true ]; then
75                 echo "chunksLeft = $chunksLeft, offset = $offset"
76         fi
77         chunksLeft=$(($chunksLeft - $numFileChunks))
78         offset=$(($offset + $numFileChunks))
79 done
80
81 if [ -f tmp ]; then
82         rm tmp
83 fi
84
85 if [ $verbose == false ]; then
86         rm time
87 else
88         echo "Time Stamp for Chunk Writes"
89         cat time
90         rm time
91 fi