btrfs: test incremental send after renaming and linking file
[xfstests-dev.git] / tests / btrfs / 084
1 #! /bin/bash
2 # FS QA Test No. btrfs/084
3 #
4 # Test for incremental send where the difference between the parent and send
5 # snapshots is that for a subtree with the same path in both snapshots (p1/p2),
6 # the root directories were swapped.
7 #
8 # This issue was fixed by the following linux kernel btrfs patch:
9 #
10 #   Btrfs: incremental send, clear name from cache after orphanization
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         rm -fr $send_files_dir
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # real QA test starts here
50 _supported_fs btrfs
51 _supported_os Linux
52 _require_scratch
53 _require_fssum
54
55 send_files_dir=$TEST_DIR/btrfs-test-$seq
56
57 rm -f $seqres.full
58 rm -fr $send_files_dir
59 mkdir $send_files_dir
60
61 _scratch_mkfs >>$seqres.full 2>&1
62 _scratch_mount
63
64 mkdir -p $SCRATCH_MNT/data/n1/n2/p1/p2
65 mkdir $SCRATCH_MNT/data/n4
66 mkdir -p $SCRATCH_MNT/data/p1/p2
67
68 # Filesystem looks like:
69 #
70 # .                                       (ino 256)
71 # |---- data                              (ino 257)
72 #         |---- n1/                       (ino 258)
73 #         |     |---- n2/                 (ino 259)
74 #         |           |---- p1/           (ino 260)
75 #         |                 |---- p2/     (ino 261)
76 #         |
77 #         |---- n4/                       (ino 262)
78 #         |---- p1/                       (ino 263)
79 #               |---- p2/                 (ino 264)
80 #
81 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
82
83 # Now move directories around such that for the subtrees with the path "p1/p2"
84 # we end up swapping the parents, that is, inode 263 becomes the parent of
85 # inode 261 and inode 260 becomes the parent of inode 264. This makes the send
86 # stream orphanize the inodes 263 and 264, and we want to verify the respective
87 # rename operations don't fail, that they don't use incorrect paths.
88 mv $SCRATCH_MNT/data/p1/p2 $SCRATCH_MNT/data
89 mv $SCRATCH_MNT/data/n1/n2/p1/p2 $SCRATCH_MNT/data/p1
90 mv $SCRATCH_MNT/data/p2 $SCRATCH_MNT/data/n1/n2/p1
91 mv $SCRATCH_MNT/data/n1/n2 $SCRATCH_MNT/data/p1
92 mv $SCRATCH_MNT/data/p1 $SCRATCH_MNT/data/n4
93 mv $SCRATCH_MNT/data/n4/p1/n2/p1 $SCRATCH_MNT/data
94
95 # Filesystem now looks like:
96 #
97 # .                                       (ino 256)
98 # |---- data                              (ino 257)
99 #         |---- n1/                       (ino 258)
100 #         |---- n4/                       (ino 262)
101 #         |     |---- p1/                 (ino 263)
102 #         |           |---- n2/           (ino 259)
103 #         |           |---- p2/           (ino 261)
104 #         |
105 #         |---- p1/                       (ino 260)
106 #               |---- p2/                 (ino 264)
107 #
108 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
109
110 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
111 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
112         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
113
114 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
115 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
116         $SCRATCH_MNT/mysnap2
117
118 # Now recreate the filesystem by receiving both send streams and verify we get
119 # the same content that the original filesystem had.
120 _scratch_unmount
121 _scratch_mkfs >>$seqres.full 2>&1
122 _scratch_mount
123
124 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
125 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
126 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
127 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
128
129 echo "Silence is golden"
130 status=0
131 exit