2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/221
7 # Test that an incremental send operation emits the correct path for link and
8 # rename operation after swapping the names and locations of several inodes in
9 # a way that creates a nasty dependency of rename and link operations. Notably
10 # one file has its name and location swapped with a directory for which it used
11 # to have a directory entry in it.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
24 rm -fr $send_files_dir
28 # get standard environment, filters and checks
32 # 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/testdir
50 # We want "a" to have a lower inode number than its parent directory, so it
51 # was created before the directory and then moved into it.
52 mv $SCRATCH_MNT/a $SCRATCH_MNT/testdir/a
54 # Filesystem looks like:
57 # |----- testdir/ (ino 259)
58 # | |----- a (ino 257)
62 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
63 $SCRATCH_MNT/mysnap1 > /dev/null
65 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
66 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
68 # Now rename 259 to "testdir_2", then change the name of 257 to "testdir" and
69 # make it a direct descendant of the root inode (256). Also create a new link
70 # for inode 257 with the old name of inode 258. By swapping the names and
71 # location of several inodes and create a nasty dependency chain of rename and
73 mv $SCRATCH_MNT/testdir/a $SCRATCH_MNT/a2
74 touch $SCRATCH_MNT/testdir/a
75 mv $SCRATCH_MNT/b $SCRATCH_MNT/b2
76 ln $SCRATCH_MNT/a2 $SCRATCH_MNT/b
77 mv $SCRATCH_MNT/testdir $SCRATCH_MNT/testdir_2
78 mv $SCRATCH_MNT/a2 $SCRATCH_MNT/testdir
80 # Filesystem now looks like:
83 # |----- testdir_2/ (ino 259)
84 # | |----- a (ino 260)
86 # |----- testdir (ino 257)
91 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
92 $SCRATCH_MNT/mysnap2 > /dev/null
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 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
97 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
98 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
100 # Now recreate the filesystem by receiving both send streams and verify we get
101 # the same content that the original filesystem had.
103 _scratch_mkfs >>$seqres.full 2>&1
106 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
108 # The receive operation below used to fail because when attemping to create the
109 # hard link named "b" for inode 257, the link operation contained a target path
110 # of "o259-6-0/a", which caused the receiver process to fail because inode 259
111 # was not yet orphanized (renamed to "o259-6-0"), it still had the name "testdir"
112 # when the link operation was issued.
113 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
115 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
116 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2