btrfs: test incremental send after renaming and linking file
[xfstests-dev.git] / tests / btrfs / 077
1 #! /bin/bash
2 # FS QA Test No. btrfs/077
3 #
4 # Regression test for a btrfs incremental send issue.
5 # If between two snapshots we rename an existing directory named X to Y and
6 # make it a child (direct or not) of a new inode named X, we were delaying
7 # the move/rename of the former directory unnecessarily, which would result
8 # in attempting to rename the new directory from its orphan name to name X
9 # prematurely. This made btrfs receive fail with an error message like the
10 # following:
11 #
12 #   rename o261-7-0 -> merlin/RC/OSD failed
13 #
14 # This issue was a regression in the 3.16 kernel and got fixed by the following
15 # linux kernel btrfs patch:
16 #
17 #   Btrfs: send, don't delay dir move if there's a new parent inode
18 #
19 #-----------------------------------------------------------------------
20 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
21 # Author: Filipe Manana <fdmanana@suse.com>
22 #
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License as
25 # published by the Free Software Foundation.
26 #
27 # This program is distributed in the hope that it would be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 # GNU General Public License for more details.
31 #
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write the Free Software Foundation,
34 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
35 #-----------------------------------------------------------------------
36 #
37
38 seq=`basename $0`
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
41
42 tmp=`mktemp -d`
43 status=1        # failure is the default!
44 trap "_cleanup; exit \$status" 0 1 2 3 15
45
46 _cleanup()
47 {
48     rm -fr $send_files_dir
49     rm -fr $tmp
50 }
51
52 # get standard environment, filters and checks
53 . ./common/rc
54 . ./common/filter
55
56 # real QA test starts here
57 _supported_fs btrfs
58 _supported_os Linux
59 _require_scratch
60 _require_fssum
61
62 send_files_dir=$TEST_DIR/btrfs-test-$seq
63
64 rm -f $seqres.full
65 rm -fr $send_files_dir
66 mkdir $send_files_dir
67
68 _scratch_mkfs >>$seqres.full 2>&1
69 _scratch_mount
70
71 mkdir -p $SCRATCH_MNT/merlin/RC/OSD/Source
72 mkdir -p $SCRATCH_MNT/fdm/RCz/OSDz/Sourcez
73 mkdir -p $SCRATCH_MNT/Z/Z2
74
75 # Filesystem looks like:
76 #
77 # .                                                 (ino 256)
78 # |---- merlin/                                     (ino 257)
79 # |        |---- RC/                                (ino 258)
80 # |              |----- OSD/                        (ino 259)
81 # |                      |---- Source/              (ino 260)
82 # |
83 # |---- fdm/                                        (ino 261)
84 # |       |---- RCz/                                (ino 262)
85 # |             |----- OSDz/                        (ino 263)
86 # |                     |---- Sourcez/              (ino 264)
87 # |
88 # |---- Z/                                          (ino 265)
89 #       |---- Z2/                                   (ino 266)
90 #
91 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
92
93 mkdir $SCRATCH_MNT/OSD
94 mv $SCRATCH_MNT/merlin/RC/OSD $SCRATCH_MNT/OSD/OSD-Plane_788
95 mv $SCRATCH_MNT/OSD $SCRATCH_MNT/merlin/RC
96
97 mkdir $SCRATCH_MNT/OSDz
98 mv $SCRATCH_MNT/Z/Z2 $SCRATCH_MNT/OSDz/xz2
99 mv $SCRATCH_MNT/Z $SCRATCH_MNT/OSDz/xz2/xz
100 mv $SCRATCH_MNT/fdm/RCz/OSDz $SCRATCH_MNT/OSDz/xz2/xz/OSD-Plane_788z
101 mv $SCRATCH_MNT/OSDz $SCRATCH_MNT/fdm/RCz
102
103 # Filesystem now looks like:
104 #
105 #
106 # .                                                                  (ino 256)
107 # |---- merlin/                                                      (ino 257)
108 # |       |---- RC/                                                  (ino 258)
109 # |             |----- OSD/                                     (ino 267) (new)
110 # |                     |---- OSD-Plane_788/                         (ino 259)
111 # |                                    |---- Source/                 (ino 260)
112 # |
113 # |---- fdm/                                                         (ino 261)
114 #         |---- RCz/                                                 (ino 262)
115 #                |----- OSDz/                                   (ino 268) (new)
116 #                        |--- xz2/                                   (ino 266)
117 #                              |---- xz/                             (ino 265)
118 #                                    |---- OSD-Plane_788z/           (ino 263)
119 #                                                    |---- Sourcez/  (ino 264)
120 #
121
122 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
123
124 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
125 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
126         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
127
128 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
129 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
130         $SCRATCH_MNT/mysnap2
131
132 _check_scratch_fs
133
134 _scratch_unmount
135 _scratch_mkfs >>$seqres.full 2>&1
136 _scratch_mount
137
138 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
139 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
140
141 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
142 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
143
144 echo "Silence is golden"
145
146 status=0
147 exit