2 # FS QA Test No. btrfs/134
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.
8 #-----------------------------------------------------------------------
9 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
10 # Author: Robbie Ko <robbieko@synology.com>
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.
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.
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 #-----------------------------------------------------------------------
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
38 rm -fr $send_files_dir
42 # get standard environment, filters and checks
46 # real QA test starts here
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
56 rm -fr $send_files_dir
59 _scratch_mkfs >>$seqres.full 2>&1
62 mkdir $SCRATCH_MNT/dir257
63 mkdir $SCRATCH_MNT/dir258
64 mkdir $SCRATCH_MNT/dir259
65 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/dir258/dir257
67 # Filesystem looks like:
70 # |--- dir258/ (ino 258, gen 7)
71 # | |--- dir257/ (ino 257, gen 7)
73 # |--- dir259/ (ino 259, gen 7)
75 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
76 $SCRATCH_MNT/mysnap1 > /dev/null
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.
89 touch $SCRATCH_MNT/file258
90 mkdir $SCRATCH_MNT/new_dir259
91 mv $SCRATCH_MNT/dir257 $SCRATCH_MNT/new_dir259/dir257
93 # Filesystem now looks like:
96 # |--- file258 (ino 258, gen 10)
98 # |--- new_dir259/ (ino 259, gen 10)
99 # |--- dir257/ (ino 257, gen 7)
101 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
102 $SCRATCH_MNT/mysnap2 > /dev/null
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
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
113 # Now recreate the filesystem by receiving both send streams and verify we get
114 # the same content that the original filesystem had.
116 _scratch_mkfs >>$seqres.full 2>&1
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