2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Regression test for file read corruption when using compressed extents
8 # that represent file ranges with a length that is a multiple of 16 pages
9 # and that are shared by multiple consecutive ranges of the same file.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # real QA test starts here
35 test_clone_and_read_compressed_extent()
39 _scratch_mkfs >>$seqres.full 2>&1
40 _scratch_mount $mount_opts
42 PAGE_SIZE=$(get_page_size)
44 # Create our test file with 16 pages worth of data in a single extent
45 # that is going to be compressed no matter which compression algorithm
47 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((16 * $PAGE_SIZE))" \
48 $SCRATCH_MNT/foo | _filter_xfs_io_pages_modified
50 # Now clone the compressed extent into an adjacent file offset.
51 $CLONER_PROG -s 0 -d $((16 * $PAGE_SIZE)) -l $((16 * $PAGE_SIZE)) \
52 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
54 echo "File contents before unmount:"
55 od -t x1 $SCRATCH_MNT/foo | _filter_od
57 # Remount the fs or clear the page cache to trigger the bug in btrfs.
58 # Because the extent has an uncompressed length that is a multiple of 16
59 # pages, all the pages belonging to the second range of the file that is
60 # mapped by the page index range [16, 31], which points to the same
61 # extent as the first file range mapped by the page index range [0, 15],
62 # had their contents full of zeroes instead of the byte 0xaa. This was a
63 # bug exclusively in the read path of compressed extents, the correct
64 # data was stored on disk, btrfs just failed to fill in the pages
68 echo "File contents after remount:"
69 # Must match the digest we got before.
70 od -t x1 $SCRATCH_MNT/foo | _filter_od
73 echo -e "\nTesting with zlib compression..."
74 test_clone_and_read_compressed_extent "-o compress=zlib"
78 echo -e "\nTesting with lzo compression..."
79 test_clone_and_read_compressed_extent "-o compress=lzo"