btrfs/139: require 2GB scratch dev
[xfstests-dev.git] / tests / btrfs / 041
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/041
6 #
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.
10 #
11 # This issue is fixed by the following btrfs-progs patch:
12 #
13 #    Btrfs-progs: fix restore of files with compressed extents
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 restore_dir=$TEST_DIR/btrfs-test-$seq
25
26 _cleanup()
27 {
28         rm -fr $tmp
29         rm -fr $restore_dir
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # real QA test starts here
37 _supported_fs btrfs
38 _supported_os Linux
39 _require_test
40 _require_scratch
41
42 rm -f $seqres.full
43 mkdir $restore_dir
44
45 test_btrfs_restore()
46 {
47         if [ -z $1 ]
48         then
49                 OPTIONS=""
50         else
51                 OPTIONS="-o compress-force=$1"
52         fi
53         _scratch_mkfs >/dev/null 2>&1
54         _scratch_mount $OPTIONS
55
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
58         # file extent items.
59         $XFS_IO_PROG -f -c "pwrite -S 0xff -b 100000 0 100000" -c "fsync" \
60                 $SCRATCH_MNT/foo | _filter_xfs_io
61
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
65
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 \
70                 | _filter_xfs_io
71         $XFS_IO_PROG -c "pwrite -S 0xd0 -b 11 33000 11" $SCRATCH_MNT/foo \
72                 | _filter_xfs_io
73         $XFS_IO_PROG -c "pwrite -S 0xbc -b 100 99000 100" $SCRATCH_MNT/foo \
74                 | _filter_xfs_io
75
76         md5sum $SCRATCH_MNT/foo | _filter_scratch
77
78         _scratch_unmount
79
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
85         # of the extent.
86         _run_btrfs_util_prog restore $SCRATCH_DEV $restore_dir
87         md5sum $restore_dir/foo | cut -d ' ' -f 1
88 }
89
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"
95 test_btrfs_restore
96
97 status=0
98 exit