common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 135
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 Synology Inc. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/135
6 #
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
10 # snapshot.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -fr $send_files_dir
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32 _supported_fs btrfs
33 _supported_os Linux
34 _require_test
35 _require_scratch
36 _require_fssum
37
38 send_files_dir=$TEST_DIR/btrfs-test-$seq
39
40 rm -f $seqres.full
41 rm -fr $send_files_dir
42 mkdir $send_files_dir
43
44 _scratch_mkfs >>$seqres.full 2>&1
45 _scratch_mount
46
47 touch $SCRATCH_MNT/f
48 mkdir $SCRATCH_MNT/d1
49 mkdir $SCRATCH_MNT/d259_old
50 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/d259_old/d1
51
52 # Filesystem looks like:
53 #
54 # .                                                             (ino 256)
55 # |--- f                                                        (ino 257)
56 # |
57 # |--- d259_old/                                                (ino 259)
58 #         |--- d1/                                              (ino 258)
59 #
60 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
61         $SCRATCH_MNT/mysnap1 > /dev/null
62
63 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
64         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
65
66 _scratch_unmount
67 _scratch_mkfs >>$seqres.full 2>&1
68 _scratch_mount
69 mkdir $SCRATCH_MNT/d1
70 mkdir $SCRATCH_MNT/dir258
71 mkdir $SCRATCH_MNT/dir259
72 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/dir259/d1
73
74 # Filesystem now looks like:
75 #
76 # .                                                             (ino 256)
77 # |--- dir258/                                                  (ino 258)
78 # |
79 # |--- dir259/                                                  (ino 259)
80 #        |--- d1/                                               (ino 257)
81 #
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.
84
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
90
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
98
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
101
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
106
107 # Now recreate the filesystem by receiving both send streams and verify we get
108 # the same content that the original filesystem had.
109 _scratch_unmount
110 _scratch_mkfs >>$seqres.full 2>&1
111 _scratch_mount
112
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:
118 #
119 # utimes
120 # unlink f
121 # mkdir o257-7-0
122 # mkdir o259-7-0
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
126 # utimes o259-7-0/d1
127 # rmdir o258-9-0
128 # ERROR: rmdir o258-9-0 failed: No such file or directory
129 #
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.
138 #
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
141
142 status=0
143 exit