generic/554: hide permision warning on exfat
[xfstests-dev.git] / tests / generic / 251
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2010 (C) Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
4 #
5 # FS QA Test No. 251
6 #
7 # This test was created in order to verify filesystem FITRIM implementation.
8 # By many concurrent copy and remove operations and checking that files
9 # does not change after copied into SCRATCH_MNT test if FITRIM implementation
10 # corrupts the filesystem (data/metadata).
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=`mktemp -d`
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 3
20 trap "_destroy; exit \$status" 2 15
21 chpid=0
22 mypid=$$
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs generic
30 _require_scratch
31 _scratch_mkfs >/dev/null 2>&1
32 _scratch_mount
33 _require_batched_discard $SCRATCH_MNT
34
35 _cleanup()
36 {
37         rm -rf $tmp
38 }
39
40 _destroy()
41 {
42         kill $pids $fstrim_pid 2> /dev/null
43         wait $pids $fstrim_pid 2> /dev/null
44         rm -rf $tmp
45 }
46
47 _destroy_fstrim()
48 {
49         kill $fpid 2> /dev/null
50         wait $fpid 2> /dev/null
51 }
52
53 _fail()
54 {
55         echo "$1"
56         kill $mypid 2> /dev/null
57 }
58
59 _guess_max_minlen()
60 {
61         mmlen=100000
62         while [ $mmlen -gt 1 ]; do
63                 $FSTRIM_PROG -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
64                 mmlen=$(($mmlen/2))
65         done
66         echo $mmlen
67 }
68
69 ##
70 # Background FSTRIM loop. We are trimming the device in the loop and for
71 # test coverage, we are doing whole device trim followed by several smaller
72 # trims.
73 ##
74 fstrim_loop()
75 {
76         trap "_destroy_fstrim; exit \$status" 2 15
77         fsize=$($DF_PROG | grep $SCRATCH_MNT | grep $SCRATCH_DEV  | awk '{print $3}')
78         mmlen=$(_guess_max_minlen)
79
80         while true ; do
81                 step=$((RANDOM*$RANDOM+4))
82                 minlen=$(((RANDOM*($RANDOM%2+1))%$mmlen))
83                 start=$RANDOM
84                 if [ $((RANDOM%10)) -gt 7 ]; then
85                         $FSTRIM_PROG $SCRATCH_MNT &
86                         fpid=$!
87                         wait $fpid
88                 fi
89                 while [ $start -lt $fsize ] ; do
90                         $FSTRIM_PROG -m ${minlen}k -o ${start}k -l ${step}k $SCRATCH_MNT &
91                         fpid=$!
92                         wait $fpid
93                         start=$(( $start + $step ))
94                 done
95         done
96 }
97
98 function check_sums() {
99         (
100         cd $SCRATCH_MNT/$p
101         find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/stress.$$.$p
102         )
103
104         diff $tmp/content.sums $tmp/stress.$$.$p
105         if [ $? -ne 0 ]; then
106                 _fail "!!!Checksums has changed - Filesystem possibly corrupted!!!\n"
107         fi
108         rm -f $tmp/stress.$$.$p
109 }
110
111 function run_process() {
112         local p=$1
113         repeat=10
114
115         sleep $((5*$p))s &
116         export chpid=$! && wait $chpid &> /dev/null
117         chpid=0
118
119         while [ $repeat -gt 0 ]; do
120
121                 # Remove old directories.
122                 rm -rf $SCRATCH_MNT/$p
123                 export chpid=$! && wait $chpid &> /dev/null
124
125                 # Copy content -> partition.
126                 mkdir $SCRATCH_MNT/$p
127                 cp -axT $content/ $SCRATCH_MNT/$p/
128                 export chpid=$! && wait $chpid &> /dev/null
129
130                 check_sums
131                 repeat=$(( $repeat - 1 ))
132         done
133 }
134
135 nproc=20
136 content=$here
137
138 mkdir -p $tmp
139
140 (
141 cd $content
142 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/content.sums
143 )
144
145 echo -n "Running the test: "
146 pids=""
147 fstrim_loop &
148 fstrim_pid=$!
149 p=1
150 while [ $p -le $nproc ]; do
151         run_process $p &
152         pids="$pids $!"
153         p=$(($p+1))
154 done
155 echo "done."
156
157 wait $pids
158 kill $fstrim_pid
159 wait $fstrim_pid
160
161 status=0
162
163 exit