xfs: Add test for too-small device with stripe geometry
[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 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 _supported_fs btrfs
35 _require_scratch
36 _require_btrfs_command property
37
38 algos=($(_btrfs_compression_algos))
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _scratch_mount
42 # Need 1GB for the uncompressed file plus <1GB for each compressed file.
43 _require_fs_space $SCRATCH_MNT $((1024 * 1024 * (1 + ${#algos[@]})))
44
45 # Checksum a piece in the middle of the file. This hits the unaligned case that
46 # caused the original bug.
47 do_csum()
48 {
49         dd if="$1" bs=4K skip=555 count=100 2>>$seqres.full| md5sum | cut -d ' ' -f 1
50 }
51
52 # Create a large, uncompressed (but compressible) file.
53 touch "${SCRATCH_MNT}/uncompressed"
54 $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/uncompressed" compression ""
55 _ddt of="${SCRATCH_MNT}/uncompressed" bs=1M count=1K 2>&1 | _filter_dd
56
57 csum="$(do_csum "${SCRATCH_MNT}/uncompressed")"
58
59 for algo in ${algos[@]}; do
60         echo "Testing ${algo}" >> $seqres.full
61
62         # Copy the same data, but with compression enabled.
63         touch "${SCRATCH_MNT}/${algo}"
64         $BTRFS_UTIL_PROG property set "${SCRATCH_MNT}/${algo}" compression "${algo}"
65         dd if="${SCRATCH_MNT}/uncompressed" of="${SCRATCH_MNT}/${algo}" bs=1M 2>&1 | _filter_dd
66
67         # The correct data is likely still cached. Cycle the mount to drop the
68         # cache and start fresh.
69         _scratch_cycle_mount
70
71         # Check the checksum.
72         compressed_csum="$(do_csum "${SCRATCH_MNT}/${algo}")"
73         if [ "${compressed_csum}" != "${csum}" ]; then
74                 echo "Checksum mismatch for ${algo} (expected ${csum}, got ${compressed_csum})"
75         fi
76 done
77
78 echo "Silence is golden"
79
80 status=0
81 exit