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.
8 #-----------------------------------------------------------------------
10 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
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.
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.
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 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
45 # real QA test starts here
54 test_clone_and_read_compressed_extent()
58 _scratch_mkfs >>$seqres.full 2>&1
59 _scratch_mount $mount_opts
61 PAGE_SIZE=$(get_page_size)
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
66 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((16 * $PAGE_SIZE))" \
67 $SCRATCH_MNT/foo | _filter_xfs_io_pages_modified
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
73 echo "File contents before unmount:"
74 od -t x1 $SCRATCH_MNT/foo | _filter_od
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
87 echo "File contents after remount:"
88 # Must match the digest we got before.
89 od -t x1 $SCRATCH_MNT/foo | _filter_od
92 echo -e "\nTesting with zlib compression..."
93 test_clone_and_read_compressed_extent "-o compress=zlib"
97 echo -e "\nTesting with lzo compression..."
98 test_clone_and_read_compressed_extent "-o compress=lzo"