c4c7be2a9c723456b67ea0340764b843cd81e29d
[xfstests-dev.git] / tests / btrfs / 144
1 #! /bin/bash
2 # FS QA Test No. btrfs/144
3 #
4 # Test that an incremental send operation works correctly when an inode A is
5 # renamed, a new hard link added to it and some other inode B is renamed to
6 # the old name of inode A.
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 touch $SCRATCH_MNT/f1
64 touch $SCRATCH_MNT/f2
65 touch $SCRATCH_MNT/f3
66
67 # Filesystem looks like:
68 #
69 # .                                                             (ino 256)
70 # |
71 # |--- f1                                                       (ino 257)
72 # |--- f2                                                       (ino 258)
73 # |--- f3                                                       (ino 259)
74 #
75 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
76         $SCRATCH_MNT/mysnap1 > /dev/null
77
78 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
79         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
80
81 mv $SCRATCH_MNT/f3 $SCRATCH_MNT/f4
82 ln $SCRATCH_MNT/f2 $SCRATCH_MNT/f5
83 mv $SCRATCH_MNT/f2 $SCRATCH_MNT/f3
84 mv $SCRATCH_MNT/f1 $SCRATCH_MNT/f2
85
86 # Filesystem now looks like:
87 #
88 # .                                                             (ino 256)
89 # |
90 # |--- f2                                                       (ino 257)
91 # |--- f3                                                       (ino 258)
92 # |--- f4                                                       (ino 259)
93 # |--- f5                                                       (ino 258)
94 #
95
96 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
97                  $SCRATCH_MNT/mysnap2 > /dev/null
98
99 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
100                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
101
102 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
103 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
104         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
105
106 # Now recreate the filesystem by receiving both send streams and verify we get
107 # the same content that the original filesystem had.
108 _scratch_unmount
109 _scratch_mkfs >>$seqres.full 2>&1
110 _scratch_mount
111
112 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
113 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
114 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
115 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
116
117 status=0
118 exit