reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 148
1 #! /bin/bash
2 # FS QA Test No. 148
3 #
4 # Ensure that truncating the last block in a reflinked file CoWs appropriately:
5 #   - Create a file that doesn't end on a block boundary
6 #   - Create two reflink clones of the file
7 #   - Shorten one of the clones with truncate
8 #   - Lengthen the other clone with truncate
9 #   - Check that the reflinked areas are still there.
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1    # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -rf $tmp.* $testdir
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/reflink
47
48 # real QA test starts here
49 _supported_os Linux
50 _require_test_reflink
51 _require_cp_reflink
52 _require_xfs_io_command "truncate"
53
54 rm -f $seqres.full
55
56 testdir=$TEST_DIR/test-$seq
57 rm -rf $testdir
58 mkdir $testdir
59
60 echo "Create the original files"
61 blksz=65536
62 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
63 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
64
65 _cp_reflink $testdir/file1 $testdir/file2
66 _cp_reflink $testdir/file1 $testdir/file3
67
68 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
69 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
70
71 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
72 _pwrite_byte 0x62 $blksz 37 $testdir/file3.chk >> $seqres.full
73 _pwrite_byte 0x00 $((blksz + 37)) 3 $testdir/file3.chk >> $seqres.full
74 _test_remount
75
76 md5sum $testdir/file1 | _filter_test_dir
77 md5sum $testdir/file2 | _filter_test_dir
78 md5sum $testdir/file3 | _filter_test_dir
79 md5sum $testdir/file2.chk | _filter_test_dir
80 md5sum $testdir/file3.chk | _filter_test_dir
81
82 c1=$(_md5_checksum $testdir/file1)
83 c2=$(_md5_checksum $testdir/file2)
84 c3=$(_md5_checksum $testdir/file3)
85
86 test ${c1} = ${c2} || echo "file1 and file2 should match"
87 test ${c1} = ${c3} || echo "file1 and file3 should match"
88 test ${c2} = ${c3} || echo "file2 and file3 should match"
89
90 echo "truncate files"
91 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
92 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
93 _test_remount
94
95 echo "Compare files"
96 md5sum $testdir/file1 | _filter_test_dir
97 md5sum $testdir/file2 | _filter_test_dir
98 md5sum $testdir/file3 | _filter_test_dir
99 md5sum $testdir/file2.chk | _filter_test_dir
100 md5sum $testdir/file3.chk | _filter_test_dir
101
102 c1=$(_md5_checksum $testdir/file1)
103 c2=$(_md5_checksum $testdir/file2)
104 c3=$(_md5_checksum $testdir/file3)
105
106 test ${c1} != ${c2} || echo "file1 and file2 should not match"
107 test ${c1} != ${c3} || echo "file1 and file3 should not match"
108 test ${c2} != ${c3} || echo "file2 and file3 should not match"
109
110 echo "Compare against check files"
111 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
112 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
113
114 # success, all done
115 status=0
116 exit