2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that truncating the last block in a reflinked file CoWs appropriately:
8 # - Create a file that doesn't end on a block boundary
9 # - Create two reflink clones of the file
10 # - Shorten one of the clones with truncate
11 # - Lengthen the other clone with truncate
12 # - Check that the reflinked areas are still there.
15 _begin_fstest auto quick clone
17 # Override the default cleanup function.
21 rm -rf $tmp.* $testdir
24 # Import common functions.
28 # real QA test starts here
31 _require_xfs_io_command "truncate"
33 testdir=$TEST_DIR/test-$seq
37 echo "Create the original files"
39 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
40 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
42 _cp_reflink $testdir/file1 $testdir/file2
43 _cp_reflink $testdir/file1 $testdir/file3
45 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
46 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
48 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
49 _pwrite_byte 0x62 $blksz 37 $testdir/file3.chk >> $seqres.full
50 _pwrite_byte 0x00 $((blksz + 37)) 3 $testdir/file3.chk >> $seqres.full
53 md5sum $testdir/file1 | _filter_test_dir
54 md5sum $testdir/file2 | _filter_test_dir
55 md5sum $testdir/file3 | _filter_test_dir
56 md5sum $testdir/file2.chk | _filter_test_dir
57 md5sum $testdir/file3.chk | _filter_test_dir
59 c1=$(_md5_checksum $testdir/file1)
60 c2=$(_md5_checksum $testdir/file2)
61 c3=$(_md5_checksum $testdir/file3)
63 test ${c1} = ${c2} || echo "file1 and file2 should match"
64 test ${c1} = ${c3} || echo "file1 and file3 should match"
65 test ${c2} = ${c3} || echo "file2 and file3 should match"
68 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
69 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
73 md5sum $testdir/file1 | _filter_test_dir
74 md5sum $testdir/file2 | _filter_test_dir
75 md5sum $testdir/file3 | _filter_test_dir
76 md5sum $testdir/file2.chk | _filter_test_dir
77 md5sum $testdir/file3.chk | _filter_test_dir
79 c1=$(_md5_checksum $testdir/file1)
80 c2=$(_md5_checksum $testdir/file2)
81 c3=$(_md5_checksum $testdir/file3)
83 test ${c1} != ${c2} || echo "file1 and file2 should not match"
84 test ${c1} != ${c3} || echo "file1 and file3 should not match"
85 test ${c2} != ${c3} || echo "file2 and file3 should not match"
87 echo "Compare against check files"
88 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
89 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"