2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that we can reflink and dedupe blocks within the same file...
8 # - Create a file with three distinct blocks ABB
9 # - Reflink block zero to the multiple-of-three blocks
10 # - Reflink block one to the multiple-of-five blocks
11 # - Dedupe block two to the multiple-of-seven blocks
12 # - Check that we successfully avoid deduping with holes, unwritten
13 # extents, and non-matches; but actually dedupe real matches.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
27 rm -rf $tmp.* $testdir
30 # get standard environment, filters and checks
35 # real QA test starts here
39 _require_xfs_io_command "falloc"
43 testdir=$TEST_DIR/test-$seq
47 echo "Create the original file blocks"
49 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
50 _pwrite_byte 0x62 $blksz $((blksz * 2)) $testdir/file1 >> $seqres.full
54 echo "fallocate half the file"
55 $XFS_IO_PROG -f -c "falloc $((nr_blks * blksz / 2)) $((nr_blks * blksz / 2))" $testdir/file1 >> $seqres.full
57 echo "Reflink block zero to the threes"
58 seq 1 $((nr_blks / 3)) | while read nr; do
59 _reflink_range $testdir/file1 0 $testdir/file1 $((nr * 3 * blksz)) \
60 $blksz >> $seqres.full
63 echo "Reflink block one to the fives"
64 seq 1 $((nr_blks / 5)) | while read nr; do
65 _reflink_range $testdir/file1 $blksz $testdir/file1 \
66 $((nr * 5 * blksz)) $blksz >> $seqres.full
69 echo "Dedupe block two to the sevens"
70 seq 1 $((nr_blks / 7)) | while read nr; do
71 _dedupe_range $testdir/file1 $((blksz * 2)) $testdir/file1 \
72 $((nr * 7 * blksz)) $blksz >> $seqres.full 2>&1
77 echo "Check block mappings"
78 md5sum $testdir/file1 | _filter_test_dir
80 crcZ=$(_md5_range_checksum /dev/zero 0 $blksz)
81 crc0=$(_md5_range_checksum $testdir/file1 0 $blksz)
82 crc1=$(_md5_range_checksum $testdir/file1 $blksz $blksz)
83 crc2=$(_md5_range_checksum $testdir/file1 $((blksz * 2)) $blksz)
91 crc=$(_md5_range_checksum $testdir/file1 $((lblk * blksz)) $blksz)
93 if [ $rem7 -eq 0 ]; then
94 if [ $rem5 -eq 0 ]; then
95 test $crc2 = $crc || echo "lblk $lblk doesn't match block 2"
96 elif [ $rem3 -eq 0 ]; then
97 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
98 elif [ $lblk -lt $((nr_blks / 2)) ]; then
99 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
101 elif [ $rem5 -eq 0 ]; then
102 test $crc1 = $crc || echo "lblk $lblk doesn't match block 1"
103 elif [ $rem3 -eq 0 ]; then
104 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
105 elif [ $lblk -lt $((nr_blks / 2)) ]; then
106 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
110 seq 3 $((nr_blks - 1)) | while read lblk; do
111 err="$(check_block $lblk)"
112 test -n "$err" && echo "$lblk: $err"