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
38 _require_xfs_io_command "falloc"
42 testdir=$TEST_DIR/test-$seq
46 echo "Create the original file blocks"
48 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
49 _pwrite_byte 0x62 $blksz $((blksz * 2)) $testdir/file1 >> $seqres.full
53 echo "fallocate half the file"
54 $XFS_IO_PROG -f -c "falloc $((nr_blks * blksz / 2)) $((nr_blks * blksz / 2))" $testdir/file1 >> $seqres.full
56 echo "Reflink block zero to the threes"
57 seq 1 $((nr_blks / 3)) | while read nr; do
58 _reflink_range $testdir/file1 0 $testdir/file1 $((nr * 3 * blksz)) \
59 $blksz >> $seqres.full
62 echo "Reflink block one to the fives"
63 seq 1 $((nr_blks / 5)) | while read nr; do
64 _reflink_range $testdir/file1 $blksz $testdir/file1 \
65 $((nr * 5 * blksz)) $blksz >> $seqres.full
68 echo "Dedupe block two to the sevens"
69 seq 1 $((nr_blks / 7)) | while read nr; do
70 _dedupe_range $testdir/file1 $((blksz * 2)) $testdir/file1 \
71 $((nr * 7 * blksz)) $blksz >> $seqres.full 2>&1
76 echo "Check block mappings"
77 md5sum $testdir/file1 | _filter_test_dir
79 crcZ=$(_md5_range_checksum /dev/zero 0 $blksz)
80 crc0=$(_md5_range_checksum $testdir/file1 0 $blksz)
81 crc1=$(_md5_range_checksum $testdir/file1 $blksz $blksz)
82 crc2=$(_md5_range_checksum $testdir/file1 $((blksz * 2)) $blksz)
90 crc=$(_md5_range_checksum $testdir/file1 $((lblk * blksz)) $blksz)
92 if [ $rem7 -eq 0 ]; then
93 if [ $rem5 -eq 0 ]; then
94 test $crc2 = $crc || echo "lblk $lblk doesn't match block 2"
95 elif [ $rem3 -eq 0 ]; then
96 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
97 elif [ $lblk -lt $((nr_blks / 2)) ]; then
98 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
100 elif [ $rem5 -eq 0 ]; then
101 test $crc1 = $crc || echo "lblk $lblk doesn't match block 1"
102 elif [ $rem3 -eq 0 ]; then
103 test $crc0 = $crc || echo "lblk $lblk doesn't match block 0"
104 elif [ $lblk -lt $((nr_blks / 2)) ]; then
105 test $crcZ = $crc || echo "lblk $lblk isn't zeroed"
109 seq 3 $((nr_blks - 1)) | while read lblk; do
110 err="$(check_block $lblk)"
111 test -n "$err" && echo "$lblk: $err"