Rename _test_mount to _test_cycle_mount
[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_cycle_mount
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_cycle_mount
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