generic/561: kill duperemove after sleep_time
[xfstests-dev.git] / tests / generic / 561
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test generic/561
6 #
7 # Dedup & random I/O race test, do multi-threads fsstress and dedupe on
8 # same directory/files
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23         end_test
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs generic
36 _supported_os Linux
37 _require_scratch_duperemove
38 _require_command "$KILLALL_PROG" killall
39
40 _scratch_mkfs > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
42
43 function end_test()
44 {
45         local f=1
46
47         # stop duperemove running
48         if [ -e $dupe_run ]; then
49                 rm -f $dupe_run
50                 kill -INT $dedup_pids
51                 wait $dedup_pids
52         fi
53
54         # Make sure all fsstress get killed
55         while [ $f -ne 0 ]; do
56                 $KILLALL_PROG -q $FSSTRESS_PROG > /dev/null 2>&1
57                 sleep 1
58                 f=`ps -eLf | grep $FSSTRESS_PROG | grep -v "grep" | wc -l`
59         done
60 }
61
62 sleep_time=$((50 * TIME_FACTOR))
63
64 # Start fsstress
65 testdir="$SCRATCH_MNT/dir"
66 mkdir $testdir
67 fsstress_opts="-r -n 1000 -p $((5 * LOAD_FACTOR))"
68 $FSSTRESS_PROG $fsstress_opts -d $testdir -l 0 >> $seqres.full 2>&1 &
69 dedup_pids=""
70 dupe_run=$TEST_DIR/${seq}-running
71 # Start several dedupe processes on same directory
72 touch $dupe_run
73 for ((i = 0; i < $((2 * LOAD_FACTOR)); i++)); do
74         while [ -e $dupe_run ]; do
75                 $DUPEREMOVE_PROG -dr --dedupe-options=same $testdir \
76                         >>$seqres.full 2>&1
77         done &
78         dedup_pids="$! $dedup_pids"
79 done
80
81 # End the test after $sleep_time seconds
82 sleep $sleep_time
83 end_test
84
85 # umount and mount again, verify pagecache contents don't mutate and a fresh
86 # read from the disk also doesn't show mutations.
87 find $testdir -type f -exec md5sum {} \; > ${tmp}.md5sum
88 _scratch_cycle_mount
89 md5sum -c --quiet ${tmp}.md5sum
90
91 echo "Silence is golden"
92 status=0
93 exit