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.
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
40 rm -rf $tmp.* $testdir
43 # get standard environment, filters and checks
48 # real QA test starts here
52 _require_xfs_io_command "truncate"
56 testdir=$TEST_DIR/test-$seq
60 echo "Create the original files"
62 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
63 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
65 _cp_reflink $testdir/file1 $testdir/file2
66 _cp_reflink $testdir/file1 $testdir/file3
68 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
69 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
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
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
82 c1=$(_md5_checksum $testdir/file1)
83 c2=$(_md5_checksum $testdir/file2)
84 c3=$(_md5_checksum $testdir/file3)
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"
91 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
92 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
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
102 c1=$(_md5_checksum $testdir/file1)
103 c2=$(_md5_checksum $testdir/file2)
104 c3=$(_md5_checksum $testdir/file3)
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"
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"