btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 086
1 #! /bin/bash
2 # FS QA Test No. btrfs/086
3 #
4 # Test cloning a file range with a length of zero into a destination offset
5 # greater than zero.
6 #
7 # This made btrfs create an extent state record with a start offset greater than
8 # the end offset, resulting in chaos such as an infinite loop when evicting an
9 # inode.
10 #
11 # This issue was fixed by the following linux kernel patch:
12 #
13 #   Btrfs: fix inode eviction infinite loop after cloning into it
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
17 # Author: Filipe Manana <fdmanana@suse.com>
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32 #
33
34 seq=`basename $0`
35 seqres=$RESULT_DIR/$seq
36 echo "QA output created by $seq"
37
38 tmp=/tmp/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44         rm -f $tmp.*
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # real QA test starts here
52 _supported_fs btrfs
53 _supported_os Linux
54 _require_scratch
55 _require_cloner
56
57 rm -f $seqres.full
58
59 _scratch_mkfs >>$seqres.full 2>&1
60 _scratch_mount
61
62 touch $SCRATCH_MNT/foo
63 touch $SCRATCH_MNT/bar
64
65 # Now attempt to clone foo into bar. Because we pass a length of zero, the
66 # clone ioctl will adjust the length to match the size of the file foo (minus
67 # the source offset which is zero) - because the adjusted length value is
68 # zero, it made btrfs create an extent state record for file bar with a start
69 # offset (64k) greater then its end offset (64k - 1), which is something never
70 # supposed to happen and for example it made inode eviction enter an infinite
71 # loop that dumped a warning trace on each iteration.
72 $CLONER_PROG -s 0 -d 65536 -l 0 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
73 echo "bar file size after clone operation: $(stat -c %s $SCRATCH_MNT/bar)"
74
75 status=0
76 exit