generic: add _require_odirect to generic/113 and generic/214
[xfstests-dev.git] / tests / generic / 147
1 #! /bin/bash
2 # FS QA Test No. 812
3 #
4 # Ensure that insert range steps around reflinked ranges:
5 #   - Create three reflink clones of a file
6 #   - Insert into 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 "finsert"
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 0x61 $blksz $blksz $testdir/file2.chk >> $seqres.full
71 _pwrite_byte 0x62 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
72 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file2.chk >> $seqres.full
73
74 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
75 _pwrite_byte 0x00 $blksz $blksz $testdir/file3.chk >> $seqres.full
76 _pwrite_byte 0x62 $((blksz * 2)) $blksz $testdir/file3.chk >> $seqres.full
77 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file3.chk >> $seqres.full
78
79 _pwrite_byte 0x61 0 $blksz $testdir/file4.chk >> $seqres.full
80 _pwrite_byte 0x62 $blksz $blksz $testdir/file4.chk >> $seqres.full
81 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file4.chk >> $seqres.full
82 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file4.chk >> $seqres.full
83 _test_remount
84
85 md5sum $testdir/file1 | _filter_test_dir
86 md5sum $testdir/file2 | _filter_test_dir
87 md5sum $testdir/file3 | _filter_test_dir
88 md5sum $testdir/file4 | _filter_test_dir
89 md5sum $testdir/file2.chk | _filter_test_dir
90 md5sum $testdir/file3.chk | _filter_test_dir
91 md5sum $testdir/file4.chk | _filter_test_dir
92
93 c1=$(_md5_checksum $testdir/file1)
94 c2=$(_md5_checksum $testdir/file2)
95 c3=$(_md5_checksum $testdir/file3)
96 c4=$(_md5_checksum $testdir/file4)
97
98 test ${c1} = ${c2} || echo "file1 and file2 should match"
99 test ${c1} = ${c3} || echo "file1 and file3 should match"
100 test ${c1} = ${c4} || echo "file1 and file4 should match"
101 test ${c2} = ${c3} || echo "file2 and file3 should match"
102 test ${c2} = ${c4} || echo "file2 and file4 should match"
103 test ${c3} = ${c4} || echo "file3 and file4 should match"
104
105 echo "finsert files"
106 $XFS_IO_PROG -f -c "finsert 0 $blksz" $testdir/file2
107 $XFS_IO_PROG -f -c "finsert $blksz $blksz" $testdir/file3
108 $XFS_IO_PROG -f -c "finsert $((blksz * 2)) $blksz" $testdir/file4
109 _test_remount
110
111 echo "Compare files"
112 md5sum $testdir/file1 | _filter_test_dir
113 md5sum $testdir/file2 | _filter_test_dir
114 md5sum $testdir/file3 | _filter_test_dir
115 md5sum $testdir/file4 | _filter_test_dir
116 md5sum $testdir/file2.chk | _filter_test_dir
117 md5sum $testdir/file3.chk | _filter_test_dir
118 md5sum $testdir/file4.chk | _filter_test_dir
119
120 c1=$(_md5_checksum $testdir/file1)
121 c2=$(_md5_checksum $testdir/file2)
122 c3=$(_md5_checksum $testdir/file3)
123 c4=$(_md5_checksum $testdir/file4)
124
125 test ${c1} != ${c2} || echo "file1 and file2 should not match"
126 test ${c1} != ${c3} || echo "file1 and file3 should not match"
127 test ${c1} != ${c4} || echo "file1 and file4 should not match"
128 test ${c2} != ${c3} || echo "file2 and file3 should not match"
129 test ${c2} != ${c4} || echo "file2 and file4 should not match"
130 test ${c3} != ${c4} || echo "file3 and file4 should not match"
131
132 echo "Compare against check files"
133 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
134 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
135 cmp -s $testdir/file4 $testdir/file4.chk || echo "file4 and file4.chk do not match"
136
137 # success, all done
138 status=0
139 exit