btrfs/106: work on non-4k page sized machines
[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         PAGE_SIZE=$(get_page_size)
62
63         # Create our test file with 16 pages worth of data in a single extent
64         # that is going to be compressed no matter which compression algorithm
65         # is used (zlib/lzo).
66         $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((16 * $PAGE_SIZE))" \
67                      $SCRATCH_MNT/foo | _filter_xfs_io_pages_modified
68
69         # Now clone the compressed extent into an adjacent file offset.
70         $CLONER_PROG -s 0 -d $((16 * $PAGE_SIZE)) -l $((16 * $PAGE_SIZE)) \
71                 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
72
73         echo "File contents before unmount:"
74         od -t x1 $SCRATCH_MNT/foo | _filter_od
75
76         # Remount the fs or clear the page cache to trigger the bug in btrfs.
77         # Because the extent has an uncompressed length that is a multiple of 16
78         # pages, all the pages belonging to the second range of the file that is
79         # mapped by the page index range [16, 31], which points to the same
80         # extent as the first file range mapped by the page index range [0, 15],
81         # had their contents full of zeroes instead of the byte 0xaa. This was a
82         # bug exclusively in the read path of compressed extents, the correct
83         # data was stored on disk, btrfs just failed to fill in the pages
84         # correctly.
85         _scratch_remount
86
87         echo "File contents after remount:"
88         # Must match the digest we got before.
89         od -t x1 $SCRATCH_MNT/foo | _filter_od
90 }
91
92 echo -e "\nTesting with zlib compression..."
93 test_clone_and_read_compressed_extent "-o compress=zlib"
94
95 _scratch_unmount
96
97 echo -e "\nTesting with lzo compression..."
98 test_clone_and_read_compressed_extent "-o compress=lzo"
99
100 status=0
101 exit