misc: move exit status into trap handler
[xfstests-dev.git] / tests / btrfs / 086
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/086
6 #
7 # Test cloning a file range with a length of zero into a destination offset
8 # greater than zero.
9 #
10 # This made btrfs create an extent state record with a start offset greater than
11 # the end offset, resulting in chaos such as an infinite loop when evicting an
12 # inode.
13 #
14 # This issue was fixed by the following linux kernel patch:
15 #
16 #   Btrfs: fix inode eviction infinite loop after cloning into it
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # real QA test starts here
36 _supported_fs btrfs
37 _require_scratch
38 _require_cloner
39
40 rm -f $seqres.full
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount
44
45 touch $SCRATCH_MNT/foo
46 touch $SCRATCH_MNT/bar
47
48 # Now attempt to clone foo into bar. Because we pass a length of zero, the
49 # clone ioctl will adjust the length to match the size of the file foo (minus
50 # the source offset which is zero) - because the adjusted length value is
51 # zero, it made btrfs create an extent state record for file bar with a start
52 # offset (64k) greater then its end offset (64k - 1), which is something never
53 # supposed to happen and for example it made inode eviction enter an infinite
54 # loop that dumped a warning trace on each iteration.
55 $CLONER_PROG -s 0 -d 65536 -l 0 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
56 echo "bar file size after clone operation: `_get_filesize $SCRATCH_MNT/bar`"
57
58 status=0
59 exit