Rename _test_mount to _test_cycle_mount
[xfstests-dev.git] / tests / generic / 146
1 #! /bin/bash
2 # FS QA Test No. 146
3 #
4 # Ensure that punch-hole steps around reflinked ranges:
5 #   - Create three reflink clones of a file
6 #   - Punch 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 "fpunch"
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_cycle_mount
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 "fpunch files"
103 $XFS_IO_PROG -f -c "fpunch 0 $blksz" $testdir/file2
104 $XFS_IO_PROG -f -c "fpunch $blksz $blksz" $testdir/file3
105 $XFS_IO_PROG -f -c "fpunch $((blksz * 2)) $blksz" $testdir/file4
106 _test_cycle_mount
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