f65200888c84462d1c63a06b8d718aa87e460250
[xfstests-dev.git] / tests / btrfs / 134
1 #! /bin/bash
2 # FS QA Test No. btrfs/134
3 #
4 # Test that an incremental send operation works after moving a directory into
5 # a new parent directory, deleting its previous parent directory and creating
6 # a new inode that has the same inode number as the old parent.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
10 # Author: Robbie Ko <robbieko@synology.com>
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -fr $send_files_dir
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_test
50 _require_scratch
51 _require_fssum
52
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
54
55 rm -f $seqres.full
56 rm -fr $send_files_dir
57 mkdir $send_files_dir
58
59 _scratch_mkfs >>$seqres.full 2>&1
60 _scratch_mount
61
62 mkdir $SCRATCH_MNT/dir257
63 mkdir $SCRATCH_MNT/dir258
64 mkdir $SCRATCH_MNT/dir259
65 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/dir258/dir257
66
67 # Filesystem looks like:
68 #
69 # .                                                             (ino 256, gen 3)
70 # |--- dir258/                                                  (ino 258, gen 7)
71 # |       |--- dir257/                                          (ino 257, gen 7)
72 # |
73 # |--- dir259/                                                  (ino 259, gen 7)
74 #
75 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
76     $SCRATCH_MNT/mysnap1 > /dev/null
77
78 mv $SCRATCH_MNT/dir258/dir257 $SCRATCH_MNT/dir257
79 rmdir $SCRATCH_MNT/dir258
80 rmdir $SCRATCH_MNT/dir259
81 # Remount the filesystem so that the next created inodes will have the numbers
82 # 258 and 259. This is because when a filesystem is mounted, btrfs sets the
83 # subvolume's inode counter to a value corresponding to the highest inode number
84 # in the subvolume plus 1. This inode counter is used to assign a unique number
85 # to each new inode and it's incremented by 1 after very inode creation.
86 # Note: we unmount and then mount instead of doing a mount with "-o remount"
87 # because otherwise the inode counter remains at value 260.
88 _scratch_cycle_mount
89 touch $SCRATCH_MNT/file258
90 mkdir $SCRATCH_MNT/new_dir259
91 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/new_dir259/dir257
92
93 # Filesystem now looks like:
94 #
95 # .                                                            (ino 256, gen 3)
96 # |--- file258                                                 (ino 258, gen 10)
97 # |
98 # |--- new_dir259/                                             (ino 259, gen 10)
99 #          |--- dir257/                                        (ino 257, gen 7)
100 #
101 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
102                  $SCRATCH_MNT/mysnap2 > /dev/null
103
104 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
105 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
106         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
107
108 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
109         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
110 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
111         $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
112
113 # Now recreate the filesystem by receiving both send streams and verify we get
114 # the same content that the original filesystem had.
115 _scratch_unmount
116 _scratch_mkfs >>$seqres.full 2>&1
117 _scratch_mount
118
119 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
120 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
121 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
122 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
123
124 status=0
125 exit