933d30981ad0ee4690846afdf90f5099dd4c8edb
[xfstests-dev.git] / tests / shared / 009
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 009
6 #
7 # Iterate dedupe integrity test. Copy an original data0 several
8 # times (d0 -> d1, d1 -> d2, ... dn-1 -> dn), dedupe dataN everytime
9 # before copy. At last, verify dataN same with data0.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
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
36 # duperemove only supports btrfs and xfs (with reflink feature).
37 # Add other filesystems if it supports more later.
38 _supported_fs xfs btrfs
39 _supported_os Linux
40 _require_scratch_dedupe
41 _require_command "$DUPEREMOVE_PROG" duperemove
42
43 _scratch_mkfs > $seqres.full 2>&1
44 _scratch_mount >> $seqres.full 2>&1
45
46 function iterate_dedup_verify()
47 {
48         local src=$srcdir
49         local dest=$dupdir/1
50
51         for ((index = 1; index <= times; index++)); do
52                 cp -a $src $dest
53                 find $dest -type f -exec md5sum {} \; \
54                         > $md5file$index
55                 # Make some noise
56                 $FSSTRESS_PROG $fsstress_opts -d $noisedir \
57                                -n 200 -p $((5 * LOAD_FACTOR)) >/dev/null 2>&1
58                 # Too many output, so only save error output
59                 $DUPEREMOVE_PROG -dr --dedupe-options=same $dupdir \
60                         >/dev/null 2>$seqres.full
61                 md5sum -c --quiet $md5file$index
62                 src=$dest
63                 dest=$dupdir/$((index + 1))
64         done
65 }
66
67 srcdir=$SCRATCH_MNT/src
68 dupdir=$SCRATCH_MNT/dup
69 noisedir=$dupdir/noise
70 mkdir $srcdir $dupdir
71 mkdir $dupdir/noise
72
73 md5file=${tmp}.md5sum
74
75 fsstress_opts="-w -r"
76 # Create some files to be original data
77 $FSSTRESS_PROG $fsstress_opts -d $srcdir \
78                -n 500 -p $((5 * LOAD_FACTOR)) >/dev/null 2>&1
79
80 # Calculate how many test cycles will be run
81 src_size=`du -ks $srcdir | awk '{print $1}'`
82 free_size=`df -kP $SCRATCH_MNT | grep -v Filesystem | awk '{print $4}'`
83 times=$((free_size / src_size))
84 if [ $times -gt $((4 * TIME_FACTOR)) ]; then
85         times=$((4 * TIME_FACTOR))
86 fi
87
88 echo "= Do dedup and verify ="
89 iterate_dedup_verify
90
91 # Use the last checksum file to verify the original data
92 sed -e s#dup/$times#src#g $md5file$times > $md5file
93 echo "= Backwords verify ="
94 md5sum -c --quiet $md5file
95
96 # read from the disk also doesn't show mutations.
97 _scratch_cycle_mount
98 echo "= Verify after cycle mount ="
99 for ((index = 1; index <= times; index++)); do
100         md5sum -c --quiet $md5file$index
101 done
102
103 status=0
104 exit