4 # Test decompression in the middle of large extents. Regression test for Linux
5 # kernel commit 6e78b3f7a193 ("Btrfs: fix btrfs_decompress_buf2page()").
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2017 Facebook. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
44 # remove previous $seqres.full before test
47 # real QA test starts here
52 _require_btrfs_command property
54 algos=($(_btrfs_compression_algos))
56 _scratch_mkfs >>$seqres.full 2>&1
58 # Need 1GB for the uncompressed file plus <1GB for each compressed file.
59 _require_fs_space $SCRATCH_MNT $((1024 * 1024 * (1 + ${#algos[@]})))
61 # Checksum a piece in the middle of the file. This hits the unaligned case that
62 # caused the original bug.
65 dd if="$1" bs=4K skip=555 count=100 2>>$seqres.full| md5sum | cut -d ' ' -f 1
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
73 csum="$(do_csum "${SCRATCH_MNT}/uncompressed")"
75 for algo in ${algos[@]}; do
76 echo "Testing ${algo}" >> $seqres.full
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
83 # The correct data is likely still cached. Cycle the mount to drop the
84 # cache and start fresh.
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})"
94 echo "Silence is golden"