generic/402: Drop useless fail message
[xfstests-dev.git] / tests / generic / 137
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 137
6 #
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.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1    # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26     cd /
27     rm -rf $tmp.* $testdir
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/reflink
34
35 # real QA test starts here
36 _require_test_reflink
37 _require_test_dedupe
38 _require_xfs_io_command "falloc"
39
40 rm -f $seqres.full
41
42 testdir=$TEST_DIR/test-$seq
43 rm -rf $testdir
44 mkdir $testdir
45
46 echo "Create the original file blocks"
47 blksz=65536
48 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
49 _pwrite_byte 0x62 $blksz $((blksz * 2)) $testdir/file1 >> $seqres.full
50
51 nr_blks=1024
52
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
55
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
60 done
61
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
66 done
67
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
72 done
73
74 _test_cycle_mount
75
76 echo "Check block mappings"
77 md5sum $testdir/file1 | _filter_test_dir
78
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)
83
84 check_block() {
85         lblk=$1
86         rem7=$((lblk % 7))
87         rem5=$((lblk % 5))
88         rem3=$((lblk % 3))
89
90         crc=$(_md5_range_checksum $testdir/file1 $((lblk * blksz)) $blksz)
91
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"
99                 fi
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"
106         fi
107 }
108
109 seq 3 $((nr_blks - 1)) | while read lblk; do
110         err="$(check_block $lblk)"
111         test -n "$err" && echo "$lblk: $err"
112 done
113
114 # success, all done
115 status=0
116 exit