2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
5 # FS QA Test No. btrfs/041
7 # Test that btrfs-progs' restore command is able to correctly recover files
8 # that have compressed extents, specially when the respective file extent
9 # items have a non-zero data offset field.
11 # This issue is fixed by the following btrfs-progs patch:
13 # Btrfs-progs: fix restore of files with compressed extents
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
24 restore_dir=$TEST_DIR/btrfs-test-$seq
32 # get standard environment, filters and checks
36 # real QA test starts here
50 OPTIONS="-o compress-force=$1"
52 _scratch_mkfs >/dev/null 2>&1
53 _scratch_mount $OPTIONS
55 # Create first file extent item, then fsync to make sure the next write
56 # won't end up in the same file extent item, so that we have 2 distinct
58 $XFS_IO_PROG -f -c "pwrite -S 0xff -b 100000 0 100000" -c "fsync" \
59 $SCRATCH_MNT/foo | _filter_xfs_io
61 # This creates a second file extent item.
62 $XFS_IO_PROG -c "pwrite -S 0xaa -b 100000 100000 100000" -c "fsync" \
63 $SCRATCH_MNT/foo | _filter_xfs_io
65 # Now do a few writes that will cause the first extent item to be split,
66 # with some of the new smaller file extent items getting a data offset
67 # field different from 0.
68 $XFS_IO_PROG -c "pwrite -S 0x1e -b 2 10000 2" $SCRATCH_MNT/foo \
70 $XFS_IO_PROG -c "pwrite -S 0xd0 -b 11 33000 11" $SCRATCH_MNT/foo \
72 $XFS_IO_PROG -c "pwrite -S 0xbc -b 100 99000 100" $SCRATCH_MNT/foo \
75 md5sum $SCRATCH_MNT/foo | _filter_scratch
79 rm -f $restore_dir/foo
80 # Now that the fs is unmounted, call btrfs restore to read the file
81 # from disk and save it in the test directory. It used to incorrectly
82 # read compressed file extents that have a non-zero data offset field,
83 # resulting either in decompression failure or reading a wrong section
85 _run_btrfs_util_prog restore $SCRATCH_DEV $restore_dir
86 md5sum $restore_dir/foo | cut -d ' ' -f 1
89 echo "Testing restore of file compressed with lzo"
90 test_btrfs_restore "lzo"
91 echo "Testing restore of file compressed with zlib"
92 test_btrfs_restore "zlib"
93 echo "Testing restore of file without any compression"