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
51 test_clone_and_read_compressed_extent()
55 _scratch_mkfs >>$seqres.full 2>&1
56 _scratch_mount $mount_opts
58 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
60 # Create a test file with a single extent that is compressed (the
61 # data we write into it is highly compressible no matter which
62 # compression algorithm is used, zlib or lzo).
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((1 * $BLOCK_SIZE))" \
64 -c "pwrite -S 0xbb $((1 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
65 -c "pwrite -S 0xcc $((3 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
66 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
69 # Now clone our extent into an adjacent offset.
70 $CLONER_PROG -s $((1 * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
71 -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
73 # Same as before but for this file we clone the extent into a lower
76 -c "pwrite -S 0xaa $((2 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
77 -c "pwrite -S 0xbb $((3 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
78 -c "pwrite -S 0xcc $((5 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
79 $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
81 $CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((2 * $BLOCK_SIZE)) \
82 $SCRATCH_MNT/bar $SCRATCH_MNT/bar
84 echo "File contents before unmounting filesystem:"
86 od -t x1 $SCRATCH_MNT/foo | _filter_od
88 od -t x1 $SCRATCH_MNT/bar | _filter_od
90 # Evicting the inode or clearing the page cache before reading again
91 # the file would also trigger the bug - reads were returning all bytes
92 # in the range corresponding to the second reference to the extent with
93 # a value of 0, but the correct data was persisted (it was a bug
94 # exclusively in the read path). The issue happened only if the same
95 # readpages() call targeted pages belonging to the first and second
96 # ranges that point to the same compressed extent.
99 echo "File contents after mounting filesystem again:"
100 # Must match the same contents we got before.
102 od -t x1 $SCRATCH_MNT/foo | _filter_od
104 od -t x1 $SCRATCH_MNT/bar | _filter_od
107 echo -e "\nTesting with zlib compression..."
108 test_clone_and_read_compressed_extent "-o compress=zlib"
112 echo -e "\nTesting with lzo compression..."
113 test_clone_and_read_compressed_extent "-o compress=lzo"