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
32 _scratch_mkfs >/dev/null 2>&1
34 _require_batched_discard $SCRATCH_MNT
43 kill $pids $fstrim_pid 2> /dev/null
44 wait $pids $fstrim_pid 2> /dev/null
50 kill $fpid 2> /dev/null
51 wait $fpid 2> /dev/null
57 kill $mypid 2> /dev/null
63 while [ $mmlen -gt 1 ]; do
64 $FSTRIM_PROG -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
71 # Background FSTRIM loop. We are trimming the device in the loop and for
72 # test coverage, we are doing whole device trim followed by several smaller
77 trap "_destroy_fstrim; exit \$status" 2 15
78 fsize=$($DF_PROG | grep $SCRATCH_MNT | grep $SCRATCH_DEV | awk '{print $3}')
79 mmlen=$(_guess_max_minlen)
82 step=$((RANDOM*$RANDOM+4))
83 minlen=$(((RANDOM*($RANDOM%2+1))%$mmlen))
85 if [ $((RANDOM%10)) -gt 7 ]; then
86 $FSTRIM_PROG $SCRATCH_MNT &
90 while [ $start -lt $fsize ] ; do
91 $FSTRIM_PROG -m ${minlen}k -o ${start}k -l ${step}k $SCRATCH_MNT &
94 start=$(( $start + $step ))
99 function check_sums() {
102 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/stress.$$.$p
105 diff $tmp/content.sums $tmp/stress.$$.$p
106 if [ $? -ne 0 ]; then
107 _fail "!!!Checksums has changed - Filesystem possibly corrupted!!!\n"
109 rm -f $tmp/stress.$$.$p
112 function run_process() {
117 export chpid=$! && wait $chpid &> /dev/null
120 while [ $repeat -gt 0 ]; do
122 # Remove old directories.
123 rm -rf $SCRATCH_MNT/$p
124 export chpid=$! && wait $chpid &> /dev/null
126 # Copy content -> partition.
127 mkdir $SCRATCH_MNT/$p
128 cp -axT $content/ $SCRATCH_MNT/$p/
129 export chpid=$! && wait $chpid &> /dev/null
132 repeat=$(( $repeat - 1 ))
143 find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/content.sums
146 echo -n "Running the test: "
151 while [ $p -le $nproc ]; do