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 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
26 rm -rf $tmp.* $testdir
29 # get standard environment, filters and checks
34 # real QA test starts here
38 _require_xfs_io_command "truncate"
42 testdir=$TEST_DIR/test-$seq
46 echo "Create the original files"
48 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
49 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
51 _cp_reflink $testdir/file1 $testdir/file2
52 _cp_reflink $testdir/file1 $testdir/file3
54 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
55 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
57 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
58 _pwrite_byte 0x62 $blksz 37 $testdir/file3.chk >> $seqres.full
59 _pwrite_byte 0x00 $((blksz + 37)) 3 $testdir/file3.chk >> $seqres.full
62 md5sum $testdir/file1 | _filter_test_dir
63 md5sum $testdir/file2 | _filter_test_dir
64 md5sum $testdir/file3 | _filter_test_dir
65 md5sum $testdir/file2.chk | _filter_test_dir
66 md5sum $testdir/file3.chk | _filter_test_dir
68 c1=$(_md5_checksum $testdir/file1)
69 c2=$(_md5_checksum $testdir/file2)
70 c3=$(_md5_checksum $testdir/file3)
72 test ${c1} = ${c2} || echo "file1 and file2 should match"
73 test ${c1} = ${c3} || echo "file1 and file3 should match"
74 test ${c2} = ${c3} || echo "file2 and file3 should match"
77 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
78 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
82 md5sum $testdir/file1 | _filter_test_dir
83 md5sum $testdir/file2 | _filter_test_dir
84 md5sum $testdir/file3 | _filter_test_dir
85 md5sum $testdir/file2.chk | _filter_test_dir
86 md5sum $testdir/file3.chk | _filter_test_dir
88 c1=$(_md5_checksum $testdir/file1)
89 c2=$(_md5_checksum $testdir/file2)
90 c3=$(_md5_checksum $testdir/file3)
92 test ${c1} != ${c2} || echo "file1 and file2 should not match"
93 test ${c1} != ${c3} || echo "file1 and file3 should not match"
94 test ${c2} != ${c3} || echo "file2 and file3 should not match"
96 echo "Compare against check files"
97 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
98 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"