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
38 send_files_dir=$TEST_DIR/btrfs-test-$seq
41 rm -fr $send_files_dir
44 _scratch_mkfs >>$seqres.full 2>&1
49 mkdir $SCRATCH_MNT/d259_old
50 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/d259_old/d1
52 # Filesystem looks like:
57 # |--- d259_old/ (ino 259)
60 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
61 $SCRATCH_MNT/mysnap1 > /dev/null
63 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
64 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
67 _scratch_mkfs >>$seqres.full 2>&1
70 mkdir $SCRATCH_MNT/dir258
71 mkdir $SCRATCH_MNT/dir259
72 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/dir259/d1
74 # Filesystem now looks like:
77 # |--- dir258/ (ino 258)
79 # |--- dir259/ (ino 259)
82 # Notice that at this point all inodes have a generation with value 7, which is
83 # the generation value for a brand new filesystem.
85 # Now create the second snapshot. This makes the filesystem's current generation
86 # value to increase to the value 8, due to a transaction commit performed by the
87 # snapshot creation ioctl.
88 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
89 $SCRATCH_MNT/mysnap2 > /dev/null
91 # Now receive the first snapshot created in the first filesystem.
92 # Before creating any inodes, the receive command creates the first snapshot,
93 # which causes a transaction commit and therefore bumps the filesystem's current
94 # generation to the value 9. All the inodes created end up getting a generation
95 # value of 9 and the snapshot's root inode (256) gets a generation value of 8.
96 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
97 rm $send_files_dir/1.snap
99 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
100 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
102 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
103 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
104 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
105 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
107 # Now recreate the filesystem by receiving both send streams and verify we get
108 # the same content that the original filesystem had.
110 _scratch_mkfs >>$seqres.full 2>&1
113 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
114 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
115 # The receive of the incremental send stream used to fail because it contained
116 # a rmdir operation with an invalid path. The output of the receive command,
117 # with verbose mode (argument -vv), was the following:
123 # rename o257-7-0 -> o259-7-0/d1
124 # chown o259-7-0/d1 - uid=0, gid=0
125 # chmod o259-7-0/d1 - mode=0755
128 # ERROR: rmdir o258-9-0 failed: No such file or directory
130 # When the kernel was computing the send stream and processing inode 258, it
131 # noticed that in both snapshots this inode is a direct child of inode 259, and
132 # that in both snapshots inode 259 as an entry with the name "d1". Because of
133 # that it decided (incorrectly) to issue an rmdir operation using the orphanized
134 # name of the inode 258 from the parent snapshot (which has a generation of 9).
135 # However that decision to send an rmdir operation due to the dentry collision
136 # was incorrect because the inodes with number 259 in both snapshots are not the
137 # same, they have different generations.
139 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
140 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2