btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 034
1 #! /bin/bash
2 # FS QA Test No. btrfs/034
3 #
4 # Test for a btrfs incremental send data corruption issue due to
5 # bad detection of file holes.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 tmp=`mktemp -d`
30
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     rm -fr $tmp
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44 _supported_fs btrfs
45 _supported_os Linux
46 _require_scratch
47
48 rm -f $seqres.full
49
50 _scratch_mkfs >/dev/null 2>&1
51 _scratch_mount
52
53 # Create a file such that its file extent items span at least 3 btree leafs.
54 # This is necessary to trigger a btrfs incremental send bug where file hole
55 # detection was not correct, leading to data corruption by overriding latest
56 # data regions of a file with zeroes.
57
58 $XFS_IO_PROG -f -c "truncate 104857600" $SCRATCH_MNT/foo
59
60 for ((i = 0; i < 940; i++))
61 do
62         OFFSET=$((32768 + i * 8192))
63         LEN=$((OFFSET + 8192))
64         $XFS_IO_PROG -c "falloc -k $OFFSET $LEN" $SCRATCH_MNT/foo
65         $XFS_IO_PROG -c "pwrite -S 0xf0 $OFFSET 4096" \
66                 $SCRATCH_MNT/foo | _filter_xfs_io
67 done
68
69 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
70
71 $XFS_IO_PROG -c "truncate 3882008" $SCRATCH_MNT/foo
72
73 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
74
75 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
76 _run_btrfs_util_prog send -f $tmp/2.snap -p $SCRATCH_MNT/mysnap1 \
77         $SCRATCH_MNT/mysnap2
78
79 md5sum $SCRATCH_MNT/foo | _filter_scratch
80 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
81 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
82
83 _scratch_unmount
84 _check_btrfs_filesystem $SCRATCH_DEV
85 _scratch_mkfs >/dev/null 2>&1
86 _scratch_mount
87
88 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
89 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
90
91 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
92 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
93
94 _scratch_unmount
95 _check_btrfs_filesystem $SCRATCH_DEV
96
97 status=0
98 exit