reflink: test the various fallocate modes
[xfstests-dev.git] / tests / generic / 144
1 #! /bin/bash
2 # FS QA Test No. 144
3 #
4 # Ensure that fallocate steps around reflinked ranges:
5 #   - Reflink parts of two files together
6 #   - Fallocate all the other sparse space.
7 #   - Check that the reflinked areas are still there.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename "$0"`
27 seqres="$RESULT_DIR/$seq"
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -rf "$tmp".* "$TESTDIR"
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/reflink
45
46 # real QA test starts here
47 _supported_os Linux
48 _require_test_reflink
49 _require_cp_reflink
50 _require_xfs_io_command "falloc"
51 _require_xfs_io_command "truncate"
52
53 rm -f "$seqres.full"
54
55 TESTDIR="$TEST_DIR/test-$seq"
56 rm -rf "$TESTDIR"
57 mkdir "$TESTDIR"
58
59 echo "Create the original files"
60 BLKSZ=65536
61 _pwrite_byte 0x61 0 $((BLKSZ * 5 + 37)) "$TESTDIR/file1" >> "$seqres.full"
62
63 _reflink_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file2" $BLKSZ \
64                 $((BLKSZ * 4 + 37)) >> "$seqres.full"
65
66 "$XFS_IO_PROG" -f -c "truncate $((BLKSZ * 5 + 37))" "$TESTDIR/file3" >> "$seqres.full"
67 _reflink_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $BLKSZ >> "$seqres.full"
68
69 "$XFS_IO_PROG" -f -c "truncate $((BLKSZ * 5 + 37))" "$TESTDIR/file4" >> "$seqres.full"
70 _reflink_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file4" $BLKSZ $BLKSZ >> "$seqres.full"
71 _reflink_range "$TESTDIR/file1" $((BLKSZ * 3)) "$TESTDIR/file4" $((BLKSZ * 3)) \
72                 $BLKSZ >> "$seqres.full"
73
74 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file5"
75 _test_remount
76
77 echo "Compare sections"
78 md5sum "$TESTDIR/file1" | _filter_test_dir
79 md5sum "$TESTDIR/file2" | _filter_test_dir
80 md5sum "$TESTDIR/file3" | _filter_test_dir
81 md5sum "$TESTDIR/file4" | _filter_test_dir
82 md5sum "$TESTDIR/file5" | _filter_test_dir
83
84 _compare_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file2" $BLKSZ \
85                 $((BLKSZ * 4 + 37)) \
86         || echo "shared parts of files 1-2 changed"
87
88 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file3" 0 $BLKSZ \
89         || echo "shared parts of files 1-3 changed"
90
91 _compare_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file4" $BLKSZ $BLKSZ \
92         || echo "shared parts of files 1-4 changed"
93
94 _compare_range "$TESTDIR/file1" 0 "$TESTDIR/file5" 0 $((BLKSZ * 5 + 37)) \
95         || echo "shared parts of files 1-5 changed"
96
97 echo "Compare files"
98 C1="$(_md5_checksum "$TESTDIR/file1")"
99 C2="$(_md5_checksum "$TESTDIR/file2")"
100 C3="$(_md5_checksum "$TESTDIR/file3")"
101 C4="$(_md5_checksum "$TESTDIR/file4")"
102 C5="$(_md5_checksum "$TESTDIR/file5")"
103
104 test "${C1}" != "${C2}" || echo "file1 and file2 should not match"
105 test "${C1}" != "${C3}" || echo "file1 and file3 should not match"
106 test "${C1}" != "${C4}" || echo "file1 and file4 should not match"
107 test "${C1}"  = "${C5}" || echo "file1 and file5 should match"
108 test "${C2}" != "${C3}" || echo "file2 and file3 should not match"
109 test "${C2}" != "${C4}" || echo "file2 and file4 should not match"
110 test "${C2}" != "${C5}" || echo "file2 and file5 should not match"
111 test "${C3}" != "${C4}" || echo "file3 and file4 should not match"
112 test "${C3}" != "${C5}" || echo "file3 and file5 should not match"
113 test "${C4}" != "${C5}" || echo "file4 and file5 should not match"
114
115 echo "falloc everything"
116 "$XFS_IO_PROG" -f -c "falloc 0 $((BLKSZ * 5))" "$TESTDIR/file2" >> "$seqres.full"
117 "$XFS_IO_PROG" -f -c "falloc 0 $((BLKSZ * 5))" "$TESTDIR/file3" >> "$seqres.full"
118 "$XFS_IO_PROG" -f -c "falloc 0 $((BLKSZ * 5))" "$TESTDIR/file4" >> "$seqres.full"
119 _test_remount
120
121 echo "Compare files"
122 md5sum "$TESTDIR/file1" | _filter_test_dir
123 md5sum "$TESTDIR/file2" | _filter_test_dir
124 md5sum "$TESTDIR/file3" | _filter_test_dir
125 md5sum "$TESTDIR/file4" | _filter_test_dir
126 md5sum "$TESTDIR/file5" | _filter_test_dir
127
128 D1="$(_md5_checksum "$TESTDIR/file1")"
129 D2="$(_md5_checksum "$TESTDIR/file2")"
130 D3="$(_md5_checksum "$TESTDIR/file3")"
131 D4="$(_md5_checksum "$TESTDIR/file4")"
132 D5="$(_md5_checksum "$TESTDIR/file5")"
133
134 test "${C1}" = "${D1}" || echo "file1 should not change"
135 test "${C2}" = "${D2}" || echo "file2 should not change"
136 test "${C3}" = "${D3}" || echo "file3 should not change"
137 test "${C4}" = "${D4}" || echo "file4 should not change"
138 test "${C5}" = "${D5}" || echo "file2 should not change"
139
140 # success, all done
141 status=0
142 exit