a456a845fb19490f51e78da5571b17be085783cb
[xfstests-dev.git] / tests / btrfs / 138
1 #! /bin/bash
2 # FS QA Test 138
3 #
4 # Test decompression in the middle of large extents. Regression test for Linux
5 # kernel commit 6e78b3f7a193 ("Btrfs: fix btrfs_decompress_buf2page()").
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2017 Facebook.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # remove previous $seqres.full before test
45 rm -f $seqres.full
46
47 # real QA test starts here
48
49 _supported_fs btrfs
50 _supported_os Linux
51 _require_scratch
52 _require_btrfs_command property
53
54 algos=($(_btrfs_compression_algos))
55
56 _scratch_mkfs >>$seqres.full 2>&1
57 _scratch_mount
58 # Need 1GB for the uncompressed file plus <1GB for each compressed file.
59 _require_fs_space $SCRATCH_MNT $((1024 * 1024 * (1 + ${#algos[@]})))
60
61 # Checksum a piece in the middle of the file. This hits the unaligned case that
62 # caused the original bug.
63 do_csum()
64 {
65         dd if="$1" bs=4K skip=555 count=100 2>>$seqres.full| md5sum | cut -d ' ' -f 1
66 }
67
68 # Create a large, uncompressed (but compressible) file.
69 touch "${SCRATCH_MNT}/uncompressed"
70 $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/uncompressed" compression ""
71 _ddt of="${SCRATCH_MNT}/uncompressed" bs=1M count=1K 2>&1 | _filter_dd
72
73 csum="$(do_csum "${SCRATCH_MNT}/uncompressed")"
74
75 for algo in ${algos[@]}; do
76         echo "Testing ${algo}" >> $seqres.full
77
78         # Copy the same data, but with compression enabled.
79         touch "${SCRATCH_MNT}/${algo}"
80         $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/${algo}" compression "${algo}"
81         dd if="${SCRATCH_MNT}/uncompressed" of="${SCRATCH_MNT}/${algo}" bs=1M 2>&1 | _filter_dd
82
83         # The correct data is likely still cached. Cycle the mount to drop the
84         # cache and start fresh.
85         _scratch_cycle_mount
86
87         # Check the checksum.
88         compressed_csum="$(do_csum "${SCRATCH_MNT}/${algo}")"
89         if [ "${compressed_csum}" != "${csum}" ]; then
90                 echo "Checksum mismatch for ${algo} (expected ${csum}, got ${compressed_csum})"
91         fi
92 done
93
94 echo "Silence is golden"
95
96 status=0
97 exit