btrfs: test read corruption of compressed extents differently
[xfstests-dev.git] / tests / btrfs / 106
1 #! /bin/bash
2 # FSQA Test No. 106
3 #
4 # Regression test for file read corruption when using compressed extents
5 # that represent file ranges with a length that is a multiple of 16 pages
6 # and that are shared by multiple consecutive ranges of the same file.
7 #
8 #-----------------------------------------------------------------------
9 #
10 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46 _need_to_be_root
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_scratch
50 _require_cloner
51
52 rm -f $seqres.full
53
54 test_clone_and_read_compressed_extent()
55 {
56         local mount_opts=$1
57
58         _scratch_mkfs >>$seqres.full 2>&1
59         _scratch_mount $mount_opts
60
61         # Create our test file with a single extent of 64Kb that is going to be
62         # compressed no matter which compression algorithm is used (zlib/lzo).
63         $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 64K" \
64                 $SCRATCH_MNT/foo | _filter_xfs_io
65
66         # Now clone the compressed extent into an adjacent file offset.
67         $CLONER_PROG -s 0 -d $((64 * 1024)) -l $((64 * 1024)) \
68                 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
69
70         echo "File digest before unmount:"
71         md5sum $SCRATCH_MNT/foo | _filter_scratch
72
73         # Remount the fs or clear the page cache to trigger the bug in btrfs.
74         # Because the extent has an uncompressed length that is a multiple of
75         # 16 pages, all the pages belonging to the second range of the file
76         # (64K to 128K), which points to the same extent as the first range
77         # (0K to 64K), had their contents full of zeroes instead of the byte
78         # 0xaa. This was a bug exclusively in the read path of compressed
79         # extents, the correct data was stored on disk, btrfs just failed to
80         # fill in the pages correctly.
81         _scratch_remount
82
83         echo "File digest after remount:"
84         # Must match the digest we got before.
85         md5sum $SCRATCH_MNT/foo | _filter_scratch
86 }
87
88 echo -e "\nTesting with zlib compression..."
89 test_clone_and_read_compressed_extent "-o compress=zlib"
90
91 _scratch_unmount
92
93 echo -e "\nTesting with lzo compression..."
94 test_clone_and_read_compressed_extent "-o compress=lzo"
95
96 status=0
97 exit