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
51 OPTIONS="-o compress-force=$1"
53 _scratch_mkfs >/dev/null 2>&1
54 _scratch_mount $OPTIONS
56 # Create first file extent item, then fsync to make sure the next write
57 # won't end up in the same file extent item, so that we have 2 distinct
59 $XFS_IO_PROG -f -c "pwrite -S 0xff -b 100000 0 100000" -c "fsync" \
60 $SCRATCH_MNT/foo | _filter_xfs_io
62 # This creates a second file extent item.
63 $XFS_IO_PROG -c "pwrite -S 0xaa -b 100000 100000 100000" -c "fsync" \
64 $SCRATCH_MNT/foo | _filter_xfs_io
66 # Now do a few writes that will cause the first extent item to be split,
67 # with some of the new smaller file extent items getting a data offset
68 # field different from 0.
69 $XFS_IO_PROG -c "pwrite -S 0x1e -b 2 10000 2" $SCRATCH_MNT/foo \
71 $XFS_IO_PROG -c "pwrite -S 0xd0 -b 11 33000 11" $SCRATCH_MNT/foo \
73 $XFS_IO_PROG -c "pwrite -S 0xbc -b 100 99000 100" $SCRATCH_MNT/foo \
76 md5sum $SCRATCH_MNT/foo | _filter_scratch
80 rm -f $restore_dir/foo
81 # Now that the fs is unmounted, call btrfs restore to read the file
82 # from disk and save it in the test directory. It used to incorrectly
83 # read compressed file extents that have a non-zero data offset field,
84 # resulting either in decompression failure or reading a wrong section
86 _run_btrfs_util_prog restore $SCRATCH_DEV $restore_dir
87 md5sum $restore_dir/foo | cut -d ' ' -f 1
90 echo "Testing restore of file compressed with lzo"
91 test_btrfs_restore "lzo"
92 echo "Testing restore of file compressed with zlib"
93 test_btrfs_restore "zlib"
94 echo "Testing restore of file without any compression"