reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 122
1 #! /bin/bash
2 # FS QA Test No. 122
3 #
4 # Ensuring that we cannot dedupe non-matching parts of files:
5 #   - Fail to dedupe non-identical parts of two different files
6 #   - Check that nothing changes in either file
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1    # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     cd /
37     rm -rf $tmp.* $testdir
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/reflink
44
45 # real QA test starts here
46 _supported_os Linux
47 _require_test_dedupe
48
49 rm -f $seqres.full
50
51 testdir=$TEST_DIR/test-$seq
52 rm -rf $testdir
53 mkdir $testdir
54
55 echo "Create the original files"
56 blksz=65536
57 _pwrite_byte 0x61 $((blksz * 2)) $((blksz * 6)) $testdir/file1 >> $seqres.full
58 _pwrite_byte 0x62 $((blksz * 2)) $((blksz * 6)) $testdir/file2 >> $seqres.full
59 _test_remount
60
61 md5sum $testdir/file1 | _filter_test_dir
62 md5sum $testdir/file2 | _filter_test_dir
63
64 _compare_range $testdir/file1 0 $testdir/file2 0 "$((blksz * 8))" \
65        || echo "Files 1-2 do not match (intentional)"
66
67 echo "(Fail to) dedupe the middle blocks together"
68 free_before=$(stat -f -c '%a' $testdir)
69 _dedupe_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
70                 $((blksz * 4)) $((blksz * 2)) >> $seqres.full
71 _test_remount
72 free_after=$(stat -f -c '%a' $testdir)
73 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
74
75 echo "Compare sections"
76 md5sum $testdir/file1 | _filter_test_dir
77 md5sum $testdir/file2 | _filter_test_dir
78
79 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) \
80        || echo "Start sections do not match (intentional)"
81
82 _compare_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
83                 $((blksz * 4)) $((blksz * 2)) \
84        || echo "Middle sections do not match (intentional)"
85
86 _compare_range $testdir/file1 $((blksz * 6)) $testdir/file2 \
87                 $((blksz * 6)) $((blksz * 2)) \
88        || echo "End sections do not match (intentional)"
89
90 # success, all done
91 status=0
92 exit