btrfs/012: check free size of scratch device before copying files
[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 _require_scratch_duperemove
37 _require_command "$KILLALL_PROG" killall
38
39 _scratch_mkfs > $seqres.full 2>&1
40 _scratch_mount >> $seqres.full 2>&1
41
42 function end_test()
43 {
44         local f=1
45
46         # stop duperemove running
47         if [ -e $dupe_run ]; then
48                 rm -f $dupe_run
49                 $KILLALL_PROG -q $DUPEREMOVE_PROG > /dev/null 2>&1
50                 wait $dedup_pids
51         fi
52
53         # Make sure all fsstress get killed
54         while [ $f -ne 0 ]; do
55                 $KILLALL_PROG -q $FSSTRESS_PROG > /dev/null 2>&1
56                 sleep 1
57                 f=`ps -eLf | grep $FSSTRESS_PROG | grep -v "grep" | wc -l`
58         done
59 }
60
61 sleep_time=$((50 * TIME_FACTOR))
62
63 # Start fsstress
64 testdir="$SCRATCH_MNT/dir"
65 mkdir $testdir
66 fsstress_opts="-r -n 1000 -p $((5 * LOAD_FACTOR))"
67 $FSSTRESS_PROG $fsstress_opts -d $testdir -l 0 >> $seqres.full 2>&1 &
68 dedup_pids=""
69 dupe_run=$TEST_DIR/${seq}-running
70 # Start several dedupe processes on same directory
71 touch $dupe_run
72 for ((i = 0; i < $((2 * LOAD_FACTOR)); i++)); do
73         while [ -e $dupe_run ]; do
74                 $DUPEREMOVE_PROG -dr --dedupe-options=same $testdir \
75                         >>$seqres.full 2>&1
76         done 2>&1 | sed -e '/Terminated/d' &
77         dedup_pids="$! $dedup_pids"
78 done
79
80 # End the test after $sleep_time seconds
81 sleep $sleep_time
82 end_test
83
84 # umount and mount again, verify pagecache contents don't mutate and a fresh
85 # read from the disk also doesn't show mutations.
86 find $testdir -type f -exec md5sum {} \; > ${tmp}.md5sum
87 _scratch_cycle_mount
88 md5sum -c --quiet ${tmp}.md5sum
89
90 echo "Silence is golden"
91 status=0
92 exit