2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
5 # FS QA Test No. btrfs/135
7 # Test that an incremental send operation works when in both snapshots there are
8 # two directory inodes that have the same number but different generations and
9 # have an entry with the same name that corresponds to different inodes in each
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -fr $send_files_dir
27 # get standard environment, filters and checks
31 # real QA test starts here
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
40 rm -fr $send_files_dir
43 _scratch_mkfs >>$seqres.full 2>&1
48 mkdir $SCRATCH_MNT/d259_old
49 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/d259_old/d1
51 # Filesystem looks like:
56 # |--- d259_old/ (ino 259)
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
60 $SCRATCH_MNT/mysnap1 > /dev/null
62 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
63 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
66 _scratch_mkfs >>$seqres.full 2>&1
69 mkdir $SCRATCH_MNT/dir258
70 mkdir $SCRATCH_MNT/dir259
71 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/dir259/d1
73 # Filesystem now looks like:
76 # |--- dir258/ (ino 258)
78 # |--- dir259/ (ino 259)
81 # Notice that at this point all inodes have a generation with value 7, which is
82 # the generation value for a brand new filesystem.
84 # Now create the second snapshot. This makes the filesystem's current generation
85 # value to increase to the value 8, due to a transaction commit performed by the
86 # snapshot creation ioctl.
87 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
88 $SCRATCH_MNT/mysnap2 > /dev/null
90 # Now receive the first snapshot created in the first filesystem.
91 # Before creating any inodes, the receive command creates the first snapshot,
92 # which causes a transaction commit and therefore bumps the filesystem's current
93 # generation to the value 9. All the inodes created end up getting a generation
94 # value of 9 and the snapshot's root inode (256) gets a generation value of 8.
95 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
96 rm $send_files_dir/1.snap
98 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
99 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
101 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
102 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
103 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
104 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
106 # Now recreate the filesystem by receiving both send streams and verify we get
107 # the same content that the original filesystem had.
109 _scratch_mkfs >>$seqres.full 2>&1
112 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
113 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
114 # The receive of the incremental send stream used to fail because it contained
115 # a rmdir operation with an invalid path. The output of the receive command,
116 # with verbose mode (argument -vv), was the following:
122 # rename o257-7-0 -> o259-7-0/d1
123 # chown o259-7-0/d1 - uid=0, gid=0
124 # chmod o259-7-0/d1 - mode=0755
127 # ERROR: rmdir o258-9-0 failed: No such file or directory
129 # When the kernel was computing the send stream and processing inode 258, it
130 # noticed that in both snapshots this inode is a direct child of inode 259, and
131 # that in both snapshots inode 259 as an entry with the name "d1". Because of
132 # that it decided (incorrectly) to issue an rmdir operation using the orphanized
133 # name of the inode 258 from the parent snapshot (which has a generation of 9).
134 # However that decision to send an rmdir operation due to the dentry collision
135 # was incorrect because the inodes with number 259 in both snapshots are not the
136 # same, they have different generations.
138 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
139 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2