2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2010 (C) Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
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).
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 3
20 trap "_destroy; exit \$status" 2 15
24 # get standard environment, filters and checks
28 # real QA test starts here
31 _scratch_mkfs >/dev/null 2>&1
33 _require_batched_discard $SCRATCH_MNT
42 kill $pids $fstrim_pid 2> /dev/null
43 wait $pids $fstrim_pid 2> /dev/null
49 kill $fpid 2> /dev/null
50 wait $fpid 2> /dev/null
56 kill $mypid 2> /dev/null
62 while [ $mmlen -gt 1 ]; do
63 $FSTRIM_PROG -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
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
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)
81 step=$((RANDOM*$RANDOM+4))
82 minlen=$(((RANDOM*($RANDOM%2+1))%$mmlen))
84 if [ $((RANDOM%10)) -gt 7 ]; then
85 $FSTRIM_PROG $SCRATCH_MNT &
89 while [ $start -lt $fsize ] ; do
90 $FSTRIM_PROG -m ${minlen}k -o ${start}k -l ${step}k $SCRATCH_MNT &
93 start=$(( $start + $step ))
98 function check_sums() {
101 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/stress.$$.$p
104 diff $tmp/content.sums $tmp/stress.$$.$p
105 if [ $? -ne 0 ]; then
106 _fail "!!!Checksums has changed - Filesystem possibly corrupted!!!\n"
108 rm -f $tmp/stress.$$.$p
111 function run_process() {
116 export chpid=$! && wait $chpid &> /dev/null
119 while [ $repeat -gt 0 ]; do
121 # Remove old directories.
122 rm -rf $SCRATCH_MNT/$p
123 export chpid=$! && wait $chpid &> /dev/null
125 # Copy content -> partition.
126 mkdir $SCRATCH_MNT/$p
127 cp -axT $content/ $SCRATCH_MNT/$p/
128 export chpid=$! && wait $chpid &> /dev/null
131 repeat=$(( $repeat - 1 ))
142 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/content.sums
145 echo -n "Running the test: "
150 while [ $p -le $nproc ]; do