btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 038
1 #! /bin/bash
2 # FS QA Test No. btrfs/038
3 #
4 # Test for a btrfs incremental send issue where we end up sending a
5 # wrong section of data from a file extent if the corresponding file
6 # extent is compressed and the respective file extent item has a non
7 # zero data offset.
8 #
9 # Fixed by the following linux kernel btrfs patch:
10 #
11 #   Btrfs: use right clone root offset for compressed extents
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=`mktemp -d`
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41     rm -fr $tmp
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs btrfs
50 _supported_os Linux
51 _require_scratch
52 _require_fssum
53
54 rm -f $seqres.full
55
56 _scratch_mkfs >/dev/null 2>&1
57 _scratch_mount "-o compress-force=lzo"
58
59 $XFS_IO_PROG -f -c "truncate 118811" $SCRATCH_MNT/foo
60 $XFS_IO_PROG -c "pwrite -S 0x0d -b 39987 92267 39987" \
61         $SCRATCH_MNT/foo | _filter_xfs_io
62
63 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT \
64         $SCRATCH_MNT/mysnap1
65
66 $XFS_IO_PROG -c "pwrite -S 0x3e -b 80000 200000 80000" \
67         $SCRATCH_MNT/foo | _filter_xfs_io
68
69 # Sync to avoid btrfs merging file extent items, which would make the test
70 # succeed when it should fail.
71 _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
72
73 $XFS_IO_PROG -c "pwrite -S 0xdc -b 10000 250000 10000" \
74         $SCRATCH_MNT/foo | _filter_xfs_io
75 $XFS_IO_PROG -c "pwrite -S 0xff -b 10000 300000 10000" \
76         $SCRATCH_MNT/foo | _filter_xfs_io
77
78 # will be used for incremental send to be able to issue clone operations
79 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT \
80         $SCRATCH_MNT/clones_snap
81
82 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT \
83         $SCRATCH_MNT/mysnap2
84
85 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
86 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
87         -x $SCRATCH_MNT/mysnap2/clones_snap $SCRATCH_MNT/mysnap2
88 run_check $FSSUM_PROG -A -f -w $tmp/clones.fssum $SCRATCH_MNT/clones_snap \
89         -x $SCRATCH_MNT/clones_snap/mysnap1 -x $SCRATCH_MNT/clones_snap/mysnap2
90
91 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
92 _run_btrfs_util_prog send -f $tmp/clones.snap $SCRATCH_MNT/clones_snap
93 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 \
94         -c $SCRATCH_MNT/clones_snap -f $tmp/2.snap $SCRATCH_MNT/mysnap2
95
96 _scratch_unmount
97 _check_btrfs_filesystem $SCRATCH_DEV
98
99 _scratch_mkfs >/dev/null 2>&1
100 _scratch_mount
101
102 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
103 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
104
105 _run_btrfs_util_prog receive -f $tmp/clones.snap $SCRATCH_MNT
106 run_check $FSSUM_PROG -r $tmp/clones.fssum $SCRATCH_MNT/clones_snap 2>> $seqres.full
107
108 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
109 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
110
111 _scratch_unmount
112 _check_btrfs_filesystem $SCRATCH_DEV
113
114 status=0
115 exit