2 # FS QA Test No. btrfs/041
4 # Test that btrfs-progs' restore command is able to correctly recover files
5 # that have compressed extents, specially when the respective file extent
6 # items have a non-zero data offset field.
8 # This issue is fixed by the following btrfs-progs patch:
10 # Btrfs-progs: fix restore of files with compressed extents
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #-----------------------------------------------------------------------
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
39 restore_dir=$TEST_DIR/btrfs-test-$seq
47 # get standard environment, filters and checks
51 # real QA test starts here
66 OPTIONS="-o compress-force=$1"
68 _scratch_mkfs >/dev/null 2>&1
69 _scratch_mount $OPTIONS
71 # Create first file extent item, then fsync to make sure the next write
72 # won't end up in the same file extent item, so that we have 2 distinct
74 $XFS_IO_PROG -f -c "pwrite -S 0xff -b 100000 0 100000" -c "fsync" \
75 $SCRATCH_MNT/foo | _filter_xfs_io
77 # This creates a second file extent item.
78 $XFS_IO_PROG -c "pwrite -S 0xaa -b 100000 100000 100000" -c "fsync" \
79 $SCRATCH_MNT/foo | _filter_xfs_io
81 # Now do a few writes that will cause the first extent item to be split,
82 # with some of the new smaller file extent items getting a data offset
83 # field different from 0.
84 $XFS_IO_PROG -c "pwrite -S 0x1e -b 2 10000 2" $SCRATCH_MNT/foo \
86 $XFS_IO_PROG -c "pwrite -S 0xd0 -b 11 33000 11" $SCRATCH_MNT/foo \
88 $XFS_IO_PROG -c "pwrite -S 0xbc -b 100 99000 100" $SCRATCH_MNT/foo \
91 md5sum $SCRATCH_MNT/foo | _filter_scratch
95 rm -f $restore_dir/foo
96 # Now that the fs is unmounted, call btrfs restore to read the file
97 # from disk and save it in the test directory. It used to incorrectly
98 # read compressed file extents that have a non-zero data offset field,
99 # resulting either in decompression failure or reading a wrong section
101 _run_btrfs_util_prog restore $SCRATCH_DEV $restore_dir
102 md5sum $restore_dir/foo | cut -d ' ' -f 1
105 echo "Testing restore of file compressed with lzo"
106 test_btrfs_restore "lzo"
107 echo "Testing restore of file compressed with zlib"
108 test_btrfs_restore "zlib"
109 echo "Testing restore of file without any compression"