generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 138
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 138
6 #
7 # Test decompression in the middle of large extents. Regression test for Linux
8 # kernel commit 6e78b3f7a193 ("Btrfs: fix btrfs_decompress_buf2page()").
9 #
10 . ./common/preamble
11 _begin_fstest auto compress
12
13 # Import common functions.
14 . ./common/filter
15
16 # real QA test starts here
17
18 _supported_fs btrfs
19 _require_scratch
20 _require_btrfs_command property
21
22 algos=($(_btrfs_compression_algos))
23
24 _scratch_mkfs >>$seqres.full 2>&1
25 _scratch_mount
26 # Need 1GB for the uncompressed file plus <1GB for each compressed file.
27 _require_fs_space $SCRATCH_MNT $((1024 * 1024 * (1 + ${#algos[@]})))
28
29 # Checksum a piece in the middle of the file. This hits the unaligned case that
30 # caused the original bug.
31 do_csum()
32 {
33         dd if="$1" bs=4K skip=555 count=100 2>>$seqres.full| md5sum | cut -d ' ' -f 1
34 }
35
36 # Create a large, uncompressed (but compressible) file.
37 touch "${SCRATCH_MNT}/uncompressed"
38 $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/uncompressed" compression ""
39 _ddt of="${SCRATCH_MNT}/uncompressed" bs=1M count=1K 2>&1 | _filter_dd
40
41 csum="$(do_csum "${SCRATCH_MNT}/uncompressed")"
42
43 for algo in ${algos[@]}; do
44         echo "Testing ${algo}" >> $seqres.full
45
46         # Copy the same data, but with compression enabled.
47         touch "${SCRATCH_MNT}/${algo}"
48         $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/${algo}" compression "${algo}"
49         dd if="${SCRATCH_MNT}/uncompressed" of="${SCRATCH_MNT}/${algo}" bs=1M 2>&1 | _filter_dd
50
51         # The correct data is likely still cached. Cycle the mount to drop the
52         # cache and start fresh.
53         _scratch_cycle_mount
54
55         # Check the checksum.
56         compressed_csum="$(do_csum "${SCRATCH_MNT}/${algo}")"
57         if [ "${compressed_csum}" != "${csum}" ]; then
58                 echo "Checksum mismatch for ${algo} (expected ${csum}, got ${compressed_csum})"
59         fi
60 done
61
62 echo "Silence is golden"
63
64 status=0
65 exit