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
37 _require_xfs_io_command "truncate"
41 testdir=$TEST_DIR/test-$seq
45 echo "Create the original files"
47 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
48 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
50 _cp_reflink $testdir/file1 $testdir/file2
51 _cp_reflink $testdir/file1 $testdir/file3
53 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
54 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
56 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
57 _pwrite_byte 0x62 $blksz 37 $testdir/file3.chk >> $seqres.full
58 _pwrite_byte 0x00 $((blksz + 37)) 3 $testdir/file3.chk >> $seqres.full
61 md5sum $testdir/file1 | _filter_test_dir
62 md5sum $testdir/file2 | _filter_test_dir
63 md5sum $testdir/file3 | _filter_test_dir
64 md5sum $testdir/file2.chk | _filter_test_dir
65 md5sum $testdir/file3.chk | _filter_test_dir
67 c1=$(_md5_checksum $testdir/file1)
68 c2=$(_md5_checksum $testdir/file2)
69 c3=$(_md5_checksum $testdir/file3)
71 test ${c1} = ${c2} || echo "file1 and file2 should match"
72 test ${c1} = ${c3} || echo "file1 and file3 should match"
73 test ${c2} = ${c3} || echo "file2 and file3 should match"
76 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
77 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
81 md5sum $testdir/file1 | _filter_test_dir
82 md5sum $testdir/file2 | _filter_test_dir
83 md5sum $testdir/file3 | _filter_test_dir
84 md5sum $testdir/file2.chk | _filter_test_dir
85 md5sum $testdir/file3.chk | _filter_test_dir
87 c1=$(_md5_checksum $testdir/file1)
88 c2=$(_md5_checksum $testdir/file2)
89 c3=$(_md5_checksum $testdir/file3)
91 test ${c1} != ${c2} || echo "file1 and file2 should not match"
92 test ${c1} != ${c3} || echo "file1 and file3 should not match"
93 test ${c2} != ${c3} || echo "file2 and file3 should not match"
95 echo "Compare against check files"
96 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
97 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"