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 _begin_fstest auto quick send
16 # Override the default cleanup function.
20 rm -fr $send_files_dir
24 # Import common functions.
27 # real QA test starts here
33 send_files_dir=$TEST_DIR/btrfs-test-$seq
35 rm -fr $send_files_dir
38 _scratch_mkfs >>$seqres.full 2>&1
43 mkdir $SCRATCH_MNT/testdir
44 # We want "a" to have a lower inode number than its parent directory, so it
45 # was created before the directory and then moved into it.
46 mv $SCRATCH_MNT/a $SCRATCH_MNT/testdir/a
48 # Filesystem looks like:
51 # |----- testdir/ (ino 259)
52 # | |----- a (ino 257)
56 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
57 $SCRATCH_MNT/mysnap1 > /dev/null
59 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
60 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
62 # Now rename 259 to "testdir_2", then change the name of 257 to "testdir" and
63 # make it a direct descendant of the root inode (256). Also create a new link
64 # for inode 257 with the old name of inode 258. By swapping the names and
65 # location of several inodes and create a nasty dependency chain of rename and
67 mv $SCRATCH_MNT/testdir/a $SCRATCH_MNT/a2
68 touch $SCRATCH_MNT/testdir/a
69 mv $SCRATCH_MNT/b $SCRATCH_MNT/b2
70 ln $SCRATCH_MNT/a2 $SCRATCH_MNT/b
71 mv $SCRATCH_MNT/testdir $SCRATCH_MNT/testdir_2
72 mv $SCRATCH_MNT/a2 $SCRATCH_MNT/testdir
74 # Filesystem now looks like:
77 # |----- testdir_2/ (ino 259)
78 # | |----- a (ino 260)
80 # |----- testdir (ino 257)
85 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
86 $SCRATCH_MNT/mysnap2 > /dev/null
87 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
88 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
90 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
91 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
92 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
94 # Now recreate the filesystem by receiving both send streams and verify we get
95 # the same content that the original filesystem had.
97 _scratch_mkfs >>$seqres.full 2>&1
100 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
102 # The receive operation below used to fail because when attemping to create the
103 # hard link named "b" for inode 257, the link operation contained a target path
104 # of "o259-6-0/a", which caused the receiver process to fail because inode 259
105 # was not yet orphanized (renamed to "o259-6-0"), it still had the name "testdir"
106 # when the link operation was issued.
107 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
109 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
110 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2