4 # Ensure that we can reflink and dedupe blocks within the same file...
5 # - Create a file with three distinct blocks ABB
6 # - Reflink block zero to the multiple-of-three blocks
7 # - Reflink block one to the multiple-of-five blocks
8 # - Dedupe block two to the multiple-of-seven blocks
9 # - Check that we successfully avoid deduping with holes, unwritten
10 # extents, and non-matches; but actually dedupe real matches.
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #-----------------------------------------------------------------------
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
41 rm -rf $tmp.* $testdir
44 # get standard environment, filters and checks
49 # real QA test starts here
53 _require_xfs_io_command "falloc"
57 testdir=$TEST_DIR/test-$seq
61 echo "Create the original file blocks"
63 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
64 _pwrite_byte 0x62 $blksz $((blksz * 2)) $testdir/file1 >> $seqres.full
68 echo "fallocate half the file"
69 $XFS_IO_PROG -f -c "falloc $((nr_blks * blksz / 2)) $((nr_blks * blksz / 2))" $testdir/file1 >> $seqres.full
71 echo "Reflink block zero to the threes"
72 seq 1 $((nr_blks / 3)) | while read nr; do
73 _reflink_range $testdir/file1 0 $testdir/file1 $((nr * 3 * blksz)) \
74 $blksz >> $seqres.full
77 echo "Reflink block one to the fives"
78 seq 1 $((nr_blks / 5)) | while read nr; do
79 _reflink_range $testdir/file1 $blksz $testdir/file1 \
80 $((nr * 5 * blksz)) $blksz >> $seqres.full
83 echo "Dedupe block two to the sevens"
84 seq 1 $((nr_blks / 7)) | while read nr; do
85 _dedupe_range $testdir/file1 $((blksz * 2)) $testdir/file1 \
86 $((nr * 7 * blksz)) $blksz >> $seqres.full 2>&1
91 echo "Check block mappings"
92 md5sum $testdir/file1 | _filter_test_dir
94 crcZ=$(_md5_range_checksum /dev/zero 0 $blksz)
95 crc0=$(_md5_range_checksum $testdir/file1 0 $blksz)
96 crc1=$(_md5_range_checksum $testdir/file1 $blksz $blksz)
97 crc2=$(_md5_range_checksum $testdir/file1 $((blksz * 2)) $blksz)
105 crc=$(_md5_range_checksum $testdir/file1 $((lblk * blksz)) $blksz)
107 if [ $rem7 -eq 0 ]; then
108 if [ $rem5 -eq 0 ]; then
109 test $crc2 = $crc || echo "lblk $lblk doesn't match block 2"
110 elif [ $rem3 -eq 0 ]; then
111 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
112 elif [ $lblk -lt $((nr_blks / 2)) ]; then
113 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
115 elif [ $rem5 -eq 0 ]; then
116 test $crc1 = $crc || echo "lblk $lblk doesn't match block 1"
117 elif [ $rem3 -eq 0 ]; then
118 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
119 elif [ $lblk -lt $((nr_blks / 2)) ]; then
120 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
124 seq 3 $((nr_blks - 1)) | while read lblk; do
125 err="$(check_block $lblk)"
126 test -n "$err" && echo "$lblk: $err"