generic/233,270: unlimit the max locked memory size for io_uring
[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 _require_test
34 _require_scratch
35 _require_fssum
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 touch $SCRATCH_MNT/f
47 mkdir $SCRATCH_MNT/d1
48 mkdir $SCRATCH_MNT/d259_old
49 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/d259_old/d1
50
51 # Filesystem looks like:
52 #
53 # .                                                             (ino 256)
54 # |--- f                                                        (ino 257)
55 # |
56 # |--- d259_old/                                                (ino 259)
57 #         |--- d1/                                              (ino 258)
58 #
59 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
60         $SCRATCH_MNT/mysnap1 > /dev/null
61
62 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
63         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
64
65 _scratch_unmount
66 _scratch_mkfs >>$seqres.full 2>&1
67 _scratch_mount
68 mkdir $SCRATCH_MNT/d1
69 mkdir $SCRATCH_MNT/dir258
70 mkdir $SCRATCH_MNT/dir259
71 mv $SCRATCH_MNT/d1 $SCRATCH_MNT/dir259/d1
72
73 # Filesystem now looks like:
74 #
75 # .                                                             (ino 256)
76 # |--- dir258/                                                  (ino 258)
77 # |
78 # |--- dir259/                                                  (ino 259)
79 #        |--- d1/                                               (ino 257)
80 #
81 # Notice that at this point all inodes have a generation with value 7, which is
82 # the generation value for a brand new filesystem.
83
84 # Now create the second snapshot. This makes the filesystem's current generation
85 # value to increase to the value 8, due to a transaction commit performed by the
86 # snapshot creation ioctl.
87 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
88         $SCRATCH_MNT/mysnap2 > /dev/null
89
90 # Now receive the first snapshot created in the first filesystem.
91 # Before creating any inodes, the receive command creates the first snapshot,
92 # which causes a transaction commit and therefore bumps the filesystem's current
93 # generation to the value 9. All the inodes created end up getting a generation
94 # value of 9 and the snapshot's root inode (256) gets a generation value of 8.
95 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
96 rm $send_files_dir/1.snap
97
98 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
99 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
100
101 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
102         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
103 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
104         $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
105
106 # Now recreate the filesystem by receiving both send streams and verify we get
107 # the same content that the original filesystem had.
108 _scratch_unmount
109 _scratch_mkfs >>$seqres.full 2>&1
110 _scratch_mount
111
112 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
113 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
114 # The receive of the incremental send stream used to fail because it contained
115 # a rmdir operation with an invalid path. The output of the receive command,
116 # with verbose mode (argument -vv), was the following:
117 #
118 # utimes
119 # unlink f
120 # mkdir o257-7-0
121 # mkdir o259-7-0
122 # rename o257-7-0 -> o259-7-0/d1
123 # chown o259-7-0/d1 - uid=0, gid=0
124 # chmod o259-7-0/d1 - mode=0755
125 # utimes o259-7-0/d1
126 # rmdir o258-9-0
127 # ERROR: rmdir o258-9-0 failed: No such file or directory
128 #
129 # When the kernel was computing the send stream and processing inode 258, it
130 # noticed that in both snapshots this inode is a direct child of inode 259, and
131 # that in both snapshots inode 259 as an entry with the name "d1". Because of
132 # that it decided (incorrectly) to issue an rmdir operation using the orphanized
133 # name of the inode 258 from the parent snapshot (which has a generation of 9).
134 # However that decision to send an rmdir operation due to the dentry collision
135 # was incorrect because the inodes with number 259 in both snapshots are not the
136 # same, they have different generations.
137 #
138 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
139 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
140
141 status=0
142 exit