4 # Regression test for file read corruption when using compressed extents that
5 # are shared by multiple consecutive ranges of the same file.
7 #-----------------------------------------------------------------------
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #-----------------------------------------------------------------------
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
43 # real QA test starts here
52 test_clone_and_read_compressed_extent()
56 _scratch_mkfs >>$seqres.full 2>&1
57 _scratch_mount $mount_opts
59 BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
61 # Create a test file with a single extent that is compressed (the
62 # data we write into it is highly compressible no matter which
63 # compression algorithm is used, zlib or lzo).
64 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((1 * $BLOCK_SIZE))" \
65 -c "pwrite -S 0xbb $((1 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
66 -c "pwrite -S 0xcc $((3 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
67 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
70 # Now clone our extent into an adjacent offset.
71 $CLONER_PROG -s $((1 * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
72 -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
74 # Same as before but for this file we clone the extent into a lower
77 -c "pwrite -S 0xaa $((2 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
78 -c "pwrite -S 0xbb $((3 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
79 -c "pwrite -S 0xcc $((5 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
80 $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
82 $CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((2 * $BLOCK_SIZE)) \
83 $SCRATCH_MNT/bar $SCRATCH_MNT/bar
85 echo "File contents before unmounting filesystem:"
87 od -t x1 $SCRATCH_MNT/foo | _filter_od
89 od -t x1 $SCRATCH_MNT/bar | _filter_od
91 # Evicting the inode or clearing the page cache before reading again
92 # the file would also trigger the bug - reads were returning all bytes
93 # in the range corresponding to the second reference to the extent with
94 # a value of 0, but the correct data was persisted (it was a bug
95 # exclusively in the read path). The issue happened only if the same
96 # readpages() call targeted pages belonging to the first and second
97 # ranges that point to the same compressed extent.
100 echo "File contents after mounting filesystem again:"
101 # Must match the same contents we got before.
103 od -t x1 $SCRATCH_MNT/foo | _filter_od
105 od -t x1 $SCRATCH_MNT/bar | _filter_od
108 echo -e "\nTesting with zlib compression..."
109 test_clone_and_read_compressed_extent "-o compress=zlib"
113 echo -e "\nTesting with lzo compression..."
114 test_clone_and_read_compressed_extent "-o compress=lzo"