758b23c7013ef844f999bacddb845ee4a20ddbd8
[xfstests-dev.git] / tests / btrfs / 039
1 #! /bin/bash
2 # FS QA Test No. btrfs/039
3 #
4 # Regression test for a btrfs incremental send issue related to renaming of
5 # directories. If at the time of the initial send we have a directory that is
6 # a child of a directory with a higher inode number, and then later after the
7 # initial full send we rename both the child and parent directories, but
8 # without moving any of them, a subsequent incremental send would produce a
9 # rename instruction for the child directory that pointed to an invalid path.
10 # This made the btrfs receive operation fail.
11 #
12 # This issue is fixed by the following linux kernel btrfs patch:
13 #
14 #   Btrfs: incremental send, fix invalid path after dir rename
15 #
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
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=`mktemp -d`
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44     rm -fr $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_fssum
56 _need_to_be_root
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >/dev/null 2>&1
61 _scratch_mount
62
63 mkdir -p $SCRATCH_MNT/a/b
64 mkdir $SCRATCH_MNT/d
65 mkdir $SCRATCH_MNT/a/b/c
66 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/c
67 mkdir $SCRATCH_MNT/e
68 mkdir -p $SCRATCH_MNT/a/b/f/g
69 mv $SCRATCH_MNT/e $SCRATCH_MNT/a/b/f/g
70
71 # Filesystem looks like:
72 #
73 # .                      (ino 256)
74 # |-- a                  (ino 257)
75 #     |-- b              (ino 258)
76 #         |-- c          (ino 260)
77 #         |   |-- d      (ino 259)
78 #         |
79 #         |-- f          (ino 262)
80 #             |-- g      (ino 263)
81 #                 |-- e  (ino 261)
82
83 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
84
85 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/x
86 mv $SCRATCH_MNT/a/b/x/d $SCRATCH_MNT/a/b/x/y
87 mv $SCRATCH_MNT/a/b/f $SCRATCH_MNT/a/b/w
88 mv $SCRATCH_MNT/a/b/w/g/e $SCRATCH_MNT/a/b/w/g/z
89
90 # Filesystem now looks like:
91 #
92 # .                      (ino 256)
93 # |-- a                  (ino 257)
94 #     |-- b              (ino 258)
95 #         |-- x          (ino 260)
96 #         |   |-- y      (ino 259)
97 #         |
98 #         |-- w          (ino 262)
99 #             |-- g      (ino 263)
100 #                 |-- z  (ino 261)
101
102 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
103
104 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
105 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
106         $SCRATCH_MNT/mysnap2
107
108 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
109 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
110         -f $tmp/2.snap
111
112 _scratch_unmount
113 _check_btrfs_filesystem $SCRATCH_DEV
114
115 _scratch_mkfs >/dev/null 2>&1
116 _scratch_mount
117
118 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/1.snap
119 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
120
121 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/2.snap
122 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
123
124 _scratch_unmount
125 _check_btrfs_filesystem $SCRATCH_DEV
126
127 status=0
128 exit