reflink: test the various fallocate modes
[xfstests-dev.git] / tests / generic / 149
1 #! /bin/bash
2 # FS QA Test No. 813
3 #
4 # Ensure that zero-range steps around reflinked ranges:
5 #   - Create three reflink clones of a file
6 #   - Zero-range the start, middle, and end of the reflink range of each
7 #     of the three files, respectively
8 #   - Check that the reflinked areas are still there.
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 _require_cp_reflink
51 _require_xfs_io_command "fzero"
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 "$TESTDIR/file1" >> "$seqres.full"
62 _pwrite_byte 0x62 $BLKSZ $BLKSZ "$TESTDIR/file1" >> "$seqres.full"
63 _pwrite_byte 0x63 $((BLKSZ * 2)) $BLKSZ "$TESTDIR/file1" >> "$seqres.full"
64
65 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file2"
66 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file3"
67 _cp_reflink "$TESTDIR/file1" "$TESTDIR/file4"
68
69 _pwrite_byte 0x00 0 $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
70 _pwrite_byte 0x62 $BLKSZ $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
71 _pwrite_byte 0x63 $((BLKSZ * 2)) $BLKSZ "$TESTDIR/file2.chk" >> "$seqres.full"
72
73 _pwrite_byte 0x61 0 $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
74 _pwrite_byte 0x00 $BLKSZ $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
75 _pwrite_byte 0x63 $((BLKSZ * 2)) $BLKSZ "$TESTDIR/file3.chk" >> "$seqres.full"
76
77 _pwrite_byte 0x61 0 $BLKSZ "$TESTDIR/file4.chk" >> "$seqres.full"
78 _pwrite_byte 0x62 $BLKSZ $BLKSZ "$TESTDIR/file4.chk" >> "$seqres.full"
79 _pwrite_byte 0x00 $((BLKSZ * 2)) $BLKSZ "$TESTDIR/file4.chk" >> "$seqres.full"
80 _test_remount
81
82 md5sum "$TESTDIR/file1" | _filter_test_dir
83 md5sum "$TESTDIR/file2" | _filter_test_dir
84 md5sum "$TESTDIR/file3" | _filter_test_dir
85 md5sum "$TESTDIR/file4" | _filter_test_dir
86 md5sum "$TESTDIR/file2.chk" | _filter_test_dir
87 md5sum "$TESTDIR/file3.chk" | _filter_test_dir
88 md5sum "$TESTDIR/file4.chk" | _filter_test_dir
89
90 C1="$(_md5_checksum "$TESTDIR/file1")"
91 C2="$(_md5_checksum "$TESTDIR/file2")"
92 C3="$(_md5_checksum "$TESTDIR/file3")"
93 C4="$(_md5_checksum "$TESTDIR/file4")"
94
95 test "${C1}" = "${C2}" || echo "file1 and file2 should match"
96 test "${C1}" = "${C3}" || echo "file1 and file3 should match"
97 test "${C1}" = "${C4}" || echo "file1 and file4 should match"
98 test "${C2}" = "${C3}" || echo "file2 and file3 should match"
99 test "${C2}" = "${C4}" || echo "file2 and file4 should match"
100 test "${C3}" = "${C4}" || echo "file3 and file4 should match"
101
102 echo "fzero files"
103 "$XFS_IO_PROG" -f -c "fzero 0 $BLKSZ" "$TESTDIR/file2"
104 "$XFS_IO_PROG" -f -c "fzero $BLKSZ $BLKSZ" "$TESTDIR/file3"
105 "$XFS_IO_PROG" -f -c "fzero $((BLKSZ * 2)) $BLKSZ" "$TESTDIR/file4"
106 _test_remount
107
108 echo "Compare files"
109 md5sum "$TESTDIR/file1" | _filter_test_dir
110 md5sum "$TESTDIR/file2" | _filter_test_dir
111 md5sum "$TESTDIR/file3" | _filter_test_dir
112 md5sum "$TESTDIR/file4" | _filter_test_dir
113 md5sum "$TESTDIR/file2.chk" | _filter_test_dir
114 md5sum "$TESTDIR/file3.chk" | _filter_test_dir
115 md5sum "$TESTDIR/file4.chk" | _filter_test_dir
116
117 C1="$(_md5_checksum "$TESTDIR/file1")"
118 C2="$(_md5_checksum "$TESTDIR/file2")"
119 C3="$(_md5_checksum "$TESTDIR/file3")"
120 C4="$(_md5_checksum "$TESTDIR/file4")"
121
122 test "${C1}" != "${C2}" || echo "file1 and file2 should not match"
123 test "${C1}" != "${C3}" || echo "file1 and file3 should not match"
124 test "${C1}" != "${C4}" || echo "file1 and file4 should not match"
125 test "${C2}" != "${C3}" || echo "file2 and file3 should not match"
126 test "${C2}" != "${C4}" || echo "file2 and file4 should not match"
127 test "${C3}" != "${C4}" || echo "file3 and file4 should not match"
128
129 echo "Compare against check files"
130 cmp -s "$TESTDIR/file2" "$TESTDIR/file2.chk" || echo "file2 and file2.chk do not match"
131 cmp -s "$TESTDIR/file3" "$TESTDIR/file3.chk" || echo "file3 and file3.chk do not match"
132 cmp -s "$TESTDIR/file4" "$TESTDIR/file4.chk" || echo "file4 and file4.chk do not match"
133
134 # success, all done
135 status=0
136 exit