misc: move exit status into trap handler
[xfstests-dev.git] / tests / btrfs / 077
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/077
6 #
7 # Regression test for a btrfs incremental send issue.
8 # If between two snapshots we rename an existing directory named X to Y and
9 # make it a child (direct or not) of a new inode named X, we were delaying
10 # the move/rename of the former directory unnecessarily, which would result
11 # in attempting to rename the new directory from its orphan name to name X
12 # prematurely. This made btrfs receive fail with an error message like the
13 # following:
14 #
15 #   rename o261-7-0 -> merlin/RC/OSD failed
16 #
17 # This issue was a regression in the 3.16 kernel and got fixed by the following
18 # linux kernel btrfs patch:
19 #
20 #   Btrfs: send, don't delay dir move if there's a new parent inode
21 #
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 tmp=`mktemp -d`
27 status=1        # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 _cleanup()
31 {
32     rm -fr $send_files_dir
33     rm -fr $tmp
34 }
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/filter
39
40 # real QA test starts here
41 _supported_fs btrfs
42 _require_scratch
43 _require_fssum
44
45 send_files_dir=$TEST_DIR/btrfs-test-$seq
46
47 rm -f $seqres.full
48 rm -fr $send_files_dir
49 mkdir $send_files_dir
50
51 _scratch_mkfs >>$seqres.full 2>&1
52 _scratch_mount
53
54 mkdir -p $SCRATCH_MNT/merlin/RC/OSD/Source
55 mkdir -p $SCRATCH_MNT/fdm/RCz/OSDz/Sourcez
56 mkdir -p $SCRATCH_MNT/Z/Z2
57
58 # Filesystem looks like:
59 #
60 # .                                                 (ino 256)
61 # |---- merlin/                                     (ino 257)
62 # |        |---- RC/                                (ino 258)
63 # |              |----- OSD/                        (ino 259)
64 # |                      |---- Source/              (ino 260)
65 # |
66 # |---- fdm/                                        (ino 261)
67 # |       |---- RCz/                                (ino 262)
68 # |             |----- OSDz/                        (ino 263)
69 # |                     |---- Sourcez/              (ino 264)
70 # |
71 # |---- Z/                                          (ino 265)
72 #       |---- Z2/                                   (ino 266)
73 #
74 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
75
76 mkdir $SCRATCH_MNT/OSD
77 mv $SCRATCH_MNT/merlin/RC/OSD $SCRATCH_MNT/OSD/OSD-Plane_788
78 mv $SCRATCH_MNT/OSD $SCRATCH_MNT/merlin/RC
79
80 mkdir $SCRATCH_MNT/OSDz
81 mv $SCRATCH_MNT/Z/Z2 $SCRATCH_MNT/OSDz/xz2
82 mv $SCRATCH_MNT/Z $SCRATCH_MNT/OSDz/xz2/xz
83 mv $SCRATCH_MNT/fdm/RCz/OSDz $SCRATCH_MNT/OSDz/xz2/xz/OSD-Plane_788z
84 mv $SCRATCH_MNT/OSDz $SCRATCH_MNT/fdm/RCz
85
86 # Filesystem now looks like:
87 #
88 #
89 # .                                                                  (ino 256)
90 # |---- merlin/                                                      (ino 257)
91 # |       |---- RC/                                                  (ino 258)
92 # |             |----- OSD/                                     (ino 267) (new)
93 # |                     |---- OSD-Plane_788/                         (ino 259)
94 # |                                    |---- Source/                 (ino 260)
95 # |
96 # |---- fdm/                                                         (ino 261)
97 #         |---- RCz/                                                 (ino 262)
98 #                |----- OSDz/                                   (ino 268) (new)
99 #                        |--- xz2/                                   (ino 266)
100 #                              |---- xz/                             (ino 265)
101 #                                    |---- OSD-Plane_788z/           (ino 263)
102 #                                                    |---- Sourcez/  (ino 264)
103 #
104
105 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
106
107 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
108 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
109         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
110
111 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
112 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
113         $SCRATCH_MNT/mysnap2
114
115 _check_scratch_fs
116
117 _scratch_unmount
118 _scratch_mkfs >>$seqres.full 2>&1
119 _scratch_mount
120
121 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
122 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
123
124 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
125 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
126
127 echo "Silence is golden"
128
129 status=0
130 exit