btrfs: test send for files with multiple hard links renamed
[xfstests-dev.git] / tests / btrfs / 155
1 #! /bin/bash
2 # FS QA Test No. btrfs/155
3 #
4 # Test that an incremental send operation works if a file that has multiple
5 # hard links has some of its hard links renamed in the send snapshot, with one
6 # of them getting the same path that some other inode had in the send snapshot.
7 #
8 #-----------------------------------------------------------------------
9 #
10 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -fr $send_files_dir
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # real QA test starts here
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_test
51 _require_scratch
52 _require_fssum
53
54 send_files_dir=$TEST_DIR/btrfs-test-$seq
55
56 rm -f $seqres.full
57 rm -fr $send_files_dir
58 mkdir $send_files_dir
59
60 _scratch_mkfs >>$seqres.full 2>&1
61 _scratch_mount
62
63 mkdir $SCRATCH_MNT/a
64 touch $SCRATCH_MNT/a/f1
65 mkdir -p $SCRATCH_MNT/a/b/c
66 ln $SCRATCH_MNT/a/f1 $SCRATCH_MNT/a/b/c/f1l1
67 touch $SCRATCH_MNT/a/b/f2
68 mkdir $SCRATCH_MNT/d
69 mv $SCRATCH_MNT/a/b/c/f1l1 $SCRATCH_MNT/d/f1l1_2
70 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/a/f2l1
71 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/d/f2l2
72 mv $SCRATCH_MNT/a/f1 $SCRATCH_MNT/d/f1_2
73
74 # Filesystem looks like:
75 #
76 # .                                                      (ino 256)
77 # |---- a/                                               (ino 257)
78 # |     |---- b/                                         (ino 259)
79 # |     |     |---- c/                                   (ino 260)
80 # |     |     |---- f2                                   (ino 261)
81 # |     |
82 # |     |---- f2l1                                       (ino 261)
83 # |
84 # |---- d/                                               (ino 262)
85 #       |---- f1l1_2                                     (ino 258)
86 #       |---- f2l2                                       (ino 261)
87 #       |---- f1_2                                       (ino 258)
88 #
89 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
90         $SCRATCH_MNT/mysnap1 > /dev/null
91
92 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
93         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
94
95 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/d2
96 mv $SCRATCH_MNT/a/f2l1 $SCRATCH_MNT/d
97 mkdir $SCRATCH_MNT/a/f2l1
98 ln $SCRATCH_MNT/a/b/d2/f1_2 $SCRATCH_MNT/a/b/f1l2
99 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/a/f2l1/b2
100 mv $SCRATCH_MNT/a/f2l1/b2/d2 $SCRATCH_MNT/a/f2l1/b2/c/d3
101 mv $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2 $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2_2
102
103 # Filesystem now looks like:
104 #
105 # .                                                      (ino 256)
106 # |---- a/                                               (ino 257)
107 # |     |---- f2l1/                                      (ino 263)
108 # |             |---- b2/                                (ino 259)
109 # |                   |---- c/                           (ino 260)
110 # |                   |     |---- d3                     (ino 262)
111 # |                   |           |---- f1l1_2           (ino 258)
112 # |                   |           |---- f2l2_2           (ino 261)
113 # |                   |           |---- f1_2             (ino 258)
114 # |                   |
115 # |                   |---- f2                           (ino 261)
116 # |                   |---- f1l2                         (ino 258)
117 # |
118 # |---- d                                                (ino 261)
119 #
120
121 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
122                  $SCRATCH_MNT/mysnap2 > /dev/null
123 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
124                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
125
126 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
127 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
128         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
129
130 # Now recreate the filesystem by receiving both send streams and verify we get
131 # the same content that the original filesystem had.
132 _scratch_unmount
133 _scratch_mkfs >>$seqres.full 2>&1
134 _scratch_mount
135
136 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
137 # The incremental send operation below used to issue an unlink operation for the
138 # path "d/f2l1" after it orphanized inode 262 (renamed it to o262-7-0) and after
139 # it created the link named "d" for inode 261, which made the receiver fail on
140 # the unlink operation with error code ENOTDIR. That unlink operation should
141 # have had the path "o262-7-0/f2l2" instead.
142 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
143 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
144 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
145
146 status=0
147 exit