2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
5 # FS QA Test No. btrfs/133
7 # Test that an incremental send operation does not fail when a new inode
8 # replaces an old inode that has the same number but different generation,
9 # and both are direct children of the subvolume/snapshot root.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # 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
49 # Filesystem looks like:
55 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
56 $SCRATCH_MNT/mysnap1 > /dev/null
58 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
59 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
62 _scratch_mkfs >>$seqres.full 2>&1
66 # Filesystem now looks like:
71 # Notice that at this point inode 257 has a generation with value 7, which is
72 # the generation value for a brand new filesystem.
74 # Now create the second snapshot. This makes the filesystem's current generation
75 # value to increase to the value 8, due to a transaction commit performed by the
76 # snapshot creation ioctl.
77 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
78 $SCRATCH_MNT/mysnap2 > /dev/null
80 # Now receive the first snapshot created in the first filesystem.
81 # Before creating any inodes, the receive command creates the first snapshot,
82 # which causes a transaction commit and therefore bumps the filesystem's current
83 # generation to the value 9. All the inodes created end up getting a generation
84 # value of 9 and the snapshot's root inode (256) gets a generation value of 8.
85 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
86 rm $send_files_dir/1.snap
88 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
89 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
91 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
92 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
93 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
94 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
96 # Now recreate the filesystem by receiving both send streams and verify we get
97 # the same content that the original filesystem had.
98 # The receive for the second snapshot used to fail because the send stream had
99 # an operation to rename the new inode 257 (generation 7) from its orphan name
100 # to its final name (a2) before the operation to delete (rmdir) the inode 258.
102 _scratch_mkfs >>$seqres.full 2>&1
105 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
106 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
107 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
108 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2