reflink: basic tests of the reflink and dedupe ioctls
[xfstests-dev.git] / tests / generic / 119
1 #! /bin/bash
2 # FS QA Test No. 119
3 #
4 # Reflinking two sets of files together:
5 #   - Reflink identical parts of two identical files
6 #   - Reflink identical parts of two other identical files
7 #   - Reflink identical parts of all four files
8 #   - Check that we end up with identical contents
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26
27 seq=`basename "$0"`
28 seqres="$RESULT_DIR/$seq"
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1    # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -rf "$tmp".* "$TESTDIR"
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _require_test_reflink
50
51 rm -f "$seqres.full"
52
53 TESTDIR=$TEST_DIR/test-$seq
54 rm -rf $TESTDIR
55 mkdir $TESTDIR
56
57 echo "Create the original files"
58 BLKSZ=65536
59 _pwrite_byte 0x61 0 $((BLKSZ * 8)) "$TESTDIR/file1" >> "$seqres.full"
60 _pwrite_byte 0x62 0 $((BLKSZ * 8)) "$TESTDIR/file2" >> "$seqres.full"
61 _pwrite_byte 0x63 0 $((BLKSZ * 8)) "$TESTDIR/file3" >> "$seqres.full"
62 _pwrite_byte 0x64 0 $((BLKSZ * 8)) "$TESTDIR/file4" >> "$seqres.full"
63 _test_remount
64
65 md5sum "$TESTDIR/file1" | _filter_test_dir
66 md5sum "$TESTDIR/file2" | _filter_test_dir
67 md5sum "$TESTDIR/file3" | _filter_test_dir
68 md5sum "$TESTDIR/file4" | _filter_test_dir
69
70 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file2" 0 $((BLKSZ * 8)) \
71        || echo "Files 1-2 do not match (intentional)"
72
73 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $((BLKSZ * 8)) \
74        || echo "Files 1-3 do not match (intentional)"
75
76 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file4" 0 $((BLKSZ * 8)) \
77        || echo "Files 1-4 do not match (intentional)"
78
79 echo "Reflink the first four blocks together, 1-2 3-4"
80 free_before="$(stat -f -c '%a' "$TESTDIR")"
81 _reflink_range "$TESTDIR/file1" 0 "$TESTDIR/file2" 0 $((BLKSZ * 4)) >> "$seqres.full"
82 _reflink_range "$TESTDIR/file3" 0 "$TESTDIR/file4" 0 $((BLKSZ * 4)) >> "$seqres.full"
83 _test_remount
84 free_after="$(stat -f -c '%a' "$TESTDIR")"
85 echo "freesp changed by $free_before -> $free_after" >> "$seqres.full"
86
87 echo "Compare sections"
88 md5sum "$TESTDIR/file1" | _filter_test_dir
89 md5sum "$TESTDIR/file2" | _filter_test_dir
90 md5sum "$TESTDIR/file3" | _filter_test_dir
91 md5sum "$TESTDIR/file4" | _filter_test_dir
92
93 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file2" 0 $((BLKSZ * 4)) \
94        || echo "Sections of file 1-2 do not match"
95
96 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $((BLKSZ * 4)) \
97        || echo "Sections of file 1-3 do not match (intentional)"
98
99 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file4" 0 $((BLKSZ * 4)) \
100        || echo "Sections of file 1-4 do not match (intentional)"
101
102 _compare_range "$TESTDIR/file2" 0 "$TESTDIR/file3" 0 $((BLKSZ * 4)) \
103        || echo "Sections of file 2-3 do not match (intentional)"
104
105 _compare_range "$TESTDIR/file2" 0 "$TESTDIR/file4" 0 $((BLKSZ * 4)) \
106        || echo "Sections of file 2-4 do not match (intentional)"
107
108 _compare_range "$TESTDIR/file3" 0 "$TESTDIR/file4" 0 $((BLKSZ * 4)) \
109        || echo "Sections of file 3-4 do not match"
110
111 echo "Reflink the first two blocks together, 1-3 1-4"
112 free_before="$(stat -f -c '%a' $TESTDIR)"
113 _reflink_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $((BLKSZ * 2)) >> "$seqres.full"
114 _reflink_range "$TESTDIR/file1" 0 "$TESTDIR/file4" 0 $((BLKSZ * 2)) >> "$seqres.full"
115 _test_remount
116 free_after="$(stat -f -c '%a' $TESTDIR)"
117 echo "freesp changed by $free_before -> $free_after" >> "$seqres.full"
118
119 echo "Compare sections"
120 md5sum "$TESTDIR/file1" | _filter_test_dir
121 md5sum "$TESTDIR/file2" | _filter_test_dir
122 md5sum "$TESTDIR/file3" | _filter_test_dir
123 md5sum "$TESTDIR/file4" | _filter_test_dir
124
125 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file2" 0 $((BLKSZ * 2)) \
126        || echo "Sections of files 1-2 do not match"
127
128 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $((BLKSZ * 2)) \
129        || echo "Sections of files 1-3 do not match"
130
131 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file4" 0 $((BLKSZ * 2)) \
132        || echo "Sections of files 1-4 do not match"
133
134 _compare_range "$TESTDIR/file2" 0 "$TESTDIR/file3" 0 $((BLKSZ * 2)) \
135        || echo "Sections of files 2-3 do not match"
136
137 _compare_range "$TESTDIR/file2" 0 "$TESTDIR/file4" 0 $((BLKSZ * 2)) \
138        || echo "Sections of files 2-4 do not match"
139
140 _compare_range "$TESTDIR/file3" 0 "$TESTDIR/file4" 0 $((BLKSZ * 2)) \
141        || echo "Sections of files 3-4 do not match"
142
143 echo "Compare previously reflinked sections"
144 _compare_range "$TESTDIR/file1" $((BLKSZ * 2)) "$TESTDIR/file2" \
145                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
146        || echo "Sections of file 1-2 do not match"
147
148 _compare_range "$TESTDIR/file1" $((BLKSZ * 2)) "$TESTDIR/file3" \
149                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
150        || echo "Sections of file 1-3 do not match (intentional)"
151
152 _compare_range "$TESTDIR/file1" $((BLKSZ * 2)) "$TESTDIR/file4" \
153                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
154        || echo "Sections of file 1-4 do not match (intentional)"
155
156 _compare_range "$TESTDIR/file2" $((BLKSZ * 2)) "$TESTDIR/file3" \
157                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
158        || echo "Sections of file 2-3 do not match (intentional)"
159
160 _compare_range "$TESTDIR/file2" $((BLKSZ * 2)) "$TESTDIR/file4" \
161                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
162        || echo "Sections of file 2-4 do not match (intentional)"
163
164 _compare_range "$TESTDIR/file3" $((BLKSZ * 2)) "$TESTDIR/file4" \
165                 $((BLKSZ * 2)) $((BLKSZ * 2)) \
166        || echo "Sections of file 3-4 do not match"
167
168 # success, all done
169 status=0
170 exit