2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/155
7 # Test that an incremental send operation works if a file that has multiple
8 # hard links has some of its hard links renamed in the send snapshot, with one
9 # of them getting the same path that some other inode had in the send snapshot.
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
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
46 touch $SCRATCH_MNT/a/f1
47 mkdir -p $SCRATCH_MNT/a/b/c
48 ln $SCRATCH_MNT/a/f1 $SCRATCH_MNT/a/b/c/f1l1
49 touch $SCRATCH_MNT/a/b/f2
51 mv $SCRATCH_MNT/a/b/c/f1l1 $SCRATCH_MNT/d/f1l1_2
52 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/a/f2l1
53 ln $SCRATCH_MNT/a/b/f2 $SCRATCH_MNT/d/f2l2
54 mv $SCRATCH_MNT/a/f1 $SCRATCH_MNT/d/f1_2
56 # Filesystem looks like:
60 # | |---- b/ (ino 259)
61 # | | |---- c/ (ino 260)
62 # | | |---- f2 (ino 261)
64 # | |---- f2l1 (ino 261)
67 # |---- f1l1_2 (ino 258)
68 # |---- f2l2 (ino 261)
69 # |---- f1_2 (ino 258)
71 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
72 $SCRATCH_MNT/mysnap1 > /dev/null
74 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
75 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
77 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/d2
78 mv $SCRATCH_MNT/a/f2l1 $SCRATCH_MNT/d
79 mkdir $SCRATCH_MNT/a/f2l1
80 ln $SCRATCH_MNT/a/b/d2/f1_2 $SCRATCH_MNT/a/b/f1l2
81 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/a/f2l1/b2
82 mv $SCRATCH_MNT/a/f2l1/b2/d2 $SCRATCH_MNT/a/f2l1/b2/c/d3
83 mv $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2 $SCRATCH_MNT/a/f2l1/b2/c/d3/f2l2_2
85 # Filesystem now looks like:
89 # | |---- f2l1/ (ino 263)
90 # | |---- b2/ (ino 259)
91 # | |---- c/ (ino 260)
92 # | | |---- d3 (ino 262)
93 # | | |---- f1l1_2 (ino 258)
94 # | | |---- f2l2_2 (ino 261)
95 # | | |---- f1_2 (ino 258)
97 # | |---- f2 (ino 261)
98 # | |---- f1l2 (ino 258)
103 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
104 $SCRATCH_MNT/mysnap2 > /dev/null
105 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
106 $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
108 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
109 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
110 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
112 # Now recreate the filesystem by receiving both send streams and verify we get
113 # the same content that the original filesystem had.
115 _scratch_mkfs >>$seqres.full 2>&1
118 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
119 # The incremental send operation below used to issue an unlink operation for the
120 # path "d/f2l1" after it orphanized inode 262 (renamed it to o262-7-0) and after
121 # it created the link named "d" for inode 261, which made the receiver fail on
122 # the unlink operation with error code ENOTDIR. That unlink operation should
123 # have had the path "o262-7-0/f2l2" instead.
124 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
125 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
126 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2