279: test mkfs with various sector sizes & alignments
[xfstests-dev.git] / 251
1 #!/bin/bash
2 # FS QA Test No. 251
3 #
4 # This test was created in order to verify filesystem FITRIM implementation.
5 # By many concurrent copy and remove operations and checking that files
6 # does not change after copied into SCRATCH_MNT test if FITRIM implementation
7 # corrupts the filesystem (data/metadata).
8 #
9 #-----------------------------------------------------------------------
10 # Copyright 2010 (C) Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 owner=lczerner@redhat.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=`mktemp -d`
33 status=1    # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 3
35 trap "_destroy; exit \$status" 2 15
36 chpid=0
37 mypid=$$
38
39 # get standard environment, filters and checks
40 . ./common.rc
41 . ./common.filter
42
43 # real QA test starts here
44 _supported_fs generic
45 _supported_os Linux
46 _require_scratch
47 _scratch_mkfs >/dev/null 2>&1
48 _scratch_mount
49
50 _cleanup()
51 {
52         rm -rf $tmp
53 }
54
55 _destroy()
56 {
57         kill $pids $fstrim_pid
58         wait $pids $fstrim_pid
59         rm -rf $tmp
60 }
61
62 _destroy_fstrim()
63 {
64         kill $fpid
65         wait $fpid
66 }
67
68 _fail()
69 {
70         echo "$1"
71         kill $mypid
72 }
73
74 _check_fstrim_support()
75 {
76         $here/src/fstrim -l 10M $SCRATCH_MNT &> /dev/null
77 }
78
79 ##
80 # Background FSTRIM loop. We are trimming the device in the loop and for
81 # test coverage, we are doing whole device trim followed by several smaller
82 # trims.
83 ##
84 fstrim_loop()
85 {
86         trap "_destroy_fstrim; exit \$status" 2 15
87         fsize=$(df | grep $SCRATCH_MNT | grep $SCRATCH_DEV  | awk '{print $2}')
88
89         while true ; do
90                 step=1048576
91                 start=0
92                 $here/src/fstrim $SCRATCH_MNT &
93                 fpid=$!
94                 wait $fpid
95                 while [ $start -lt $fsize ] ; do
96                         $here/src/fstrim -s ${start}k -l ${step}k $SCRATCH_MNT &
97                         fpid=$!
98                         wait $fpid
99                         start=$(( $start + $step ))
100                 done
101         done
102 }
103
104 function check_sums() {
105         (
106         cd $SCRATCH_MNT/$p
107         find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/stress.$$.$p
108         )
109
110         diff $tmp/content.sums $tmp/stress.$$.$p
111         if [ $? -ne 0 ]; then
112                 _fail "!!!Checksums has changed - Filesystem possibly corrupted!!!\n"
113         fi
114         rm -f $tmp/stress.$$.$p
115 }
116
117 function run_process() {
118         local p=$1
119         repeat=10
120
121         sleep $((5*$p))s &
122         export chpid=$! && wait $chpid &> /dev/null
123         chpid=0
124
125         while [ $repeat -gt 0 ]; do
126
127                 # Remove old directories.
128                 rm -rf $SCRATCH_MNT/$p
129                 export chpid=$! && wait $chpid &> /dev/null
130
131                 # Copy content -> partition.
132                 mkdir $SCRATCH_MNT/$p
133                 cp -axT $content $SCRATCH_MNT/$p
134                 export chpid=$! && wait $chpid &> /dev/null
135
136                 check_sums
137                 repeat=$(( $repeat - 1 ))
138         done
139 }
140
141 nproc=20
142 content=$here
143
144 # Check for FITRIM support
145 echo -n "Checking FITRIM support: "
146 _check_fstrim_support || _notrun "FSTRIM is not supported"
147 echo "done."
148
149 mkdir -p $tmp
150
151 (
152 cd $content
153 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/content.sums
154 )
155
156 echo -n "Running the test: "
157 pids=""
158 fstrim_loop &
159 fstrim_pid=$!
160 p=1
161 while [ $p -le $nproc ]; do
162         run_process $p &
163         pids="$pids $!"
164         p=$(($p+1))
165 done
166 echo "done."
167
168 wait $pids
169 kill $fstrim_pid
170 wait $fstrim_pid
171
172 status=0
173
174 exit