xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / overlay / 051
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 051
6 #
7 # Test encode/decode overlay file handles for non-samefs.
8 #
9 # This is a variant of overlay file handles test for an overlayfs that is
10 # composed of multiple lower layers not on the same underlying fs.
11 #
12 # - Check encode/write/decode/read content of lower/upper file handles
13 # - Check encode/decode/write/read content of lower/upper file handles
14 # - Check decode/read of unlinked lower/upper files and directories
15 # - Check decode/read of lower file handles after copy up, link and unlink
16 #
17 # This test requires and enables overlayfs NFS export support.
18 # NFS export support depends on and requires overlayfs index feature.
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33         # Cleanup overlay scratch mount that is holding base test mount
34         # to prevent _check_test_fs and _test_umount from failing before
35         # _check_scratch_fs _scratch_umount
36         $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44
45 _supported_fs overlay
46 _require_test
47 _require_test_program "open_by_handle"
48 # Use non-default scratch underlying overlay dirs, we need to check
49 # them explicity after test.
50 _require_scratch_nocheck
51 # We need to require both features together, because nfs_export cannot
52 # be enabled when index is disabled
53 _require_scratch_overlay_features index nfs_export
54
55 # Lower is on test partition
56 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
57 # Upper/work are on scratch partition
58 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
59 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
60 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
61
62 NUMFILES=1
63
64 # Create test dir and empty test files
65 create_test_files()
66 {
67         local dir=$1
68
69         mkdir -p $dir
70         $here/src/open_by_handle -cp $dir $NUMFILES
71 }
72
73 # Create hard links to test files
74 link_test_files()
75 {
76         local dir=$1
77
78         $here/src/open_by_handle -l $dir $NUMFILES
79 }
80
81 # Test encode/decode file handles on overlay mount
82 test_file_handles()
83 {
84         local dir=$1
85         local opt=$2
86
87         echo test_file_handles $dir $opt | _filter_scratch
88         $here/src/open_by_handle $opt $dir $NUMFILES
89 }
90
91 # Re-create lower/middle/upper/work dirs
92 create_dirs()
93 {
94         # Create lower dir on test partition
95         rm -rf $lower
96         mkdir $lower
97
98         # Create middle/upper/work dirs on scratch partition
99         _scratch_mkfs
100 }
101
102 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
103 # and middle and upper layer on scratch partition
104 mount_dirs()
105 {
106         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
107                                 -o "index=on,nfs_export=on"
108 }
109
110 # Unmount the overlay without unmounting base fs and check the
111 # underlying dirs
112 unmount_dirs()
113 {
114         $UMOUNT_PROG $SCRATCH_MNT
115
116         _overlay_check_scratch_dirs $middle:$lower $upper $work \
117                                 -o "index=on,nfs_export=on"
118 }
119
120 # Check non-stale file handles of lower/upper files and verify
121 # that handle encoded before copy up is decoded to upper after
122 # copy up. Verify reading data from file open by file handle
123 # and verify access_at() with dirfd open by file handle.
124 create_dirs
125 create_test_files $upper/uppertestdir
126 create_test_files $lower/lowertestdir
127 mount_dirs
128 # Check encode/decode of upper regular file handles
129 test_file_handles $SCRATCH_MNT/uppertestdir
130 # Check encode/decode of upper dir file handle
131 test_file_handles $SCRATCH_MNT/uppertestdir -p
132 # Check encode/write/decode/read/write of upper file handles
133 test_file_handles $SCRATCH_MNT/uppertestdir -wrap
134 # Check encode/decode of lower regular file handles before copy up
135 test_file_handles $SCRATCH_MNT/lowertestdir
136 # Check encode/decode of lower dir file handles before copy up
137 test_file_handles $SCRATCH_MNT/lowertestdir -p
138 # Check encode/write/decode/read/write of lower file handles across copy up
139 test_file_handles $SCRATCH_MNT/lowertestdir -wrap
140 unmount_dirs
141
142 # Check copy up after encode/decode of lower/upper files
143 # (copy up of disconnected dentry to index dir)
144 create_dirs
145 create_test_files $upper/uppertestdir
146 create_test_files $lower/lowertestdir
147 mount_dirs
148 # Check encode/decode/write/read of upper regular file handles
149 test_file_handles $SCRATCH_MNT/uppertestdir -a
150 test_file_handles $SCRATCH_MNT/uppertestdir -r
151 # Check encode/decode/write/read of lower regular file handles
152 test_file_handles $SCRATCH_MNT/lowertestdir -a
153 test_file_handles $SCRATCH_MNT/lowertestdir -r
154 unmount_dirs
155
156 # Check non-stale handles to unlinked but open lower/upper files
157 create_dirs
158 create_test_files $upper/uppertestdir
159 create_test_files $upper/uppertestdir.rw
160 create_test_files $lower/lowertestdir
161 create_test_files $lower/lowertestdir.rw
162 mount_dirs
163 test_file_handles $SCRATCH_MNT/uppertestdir -dk
164 # Check encode/write/unlink/decode/read of upper regular file handles
165 test_file_handles $SCRATCH_MNT/uppertestdir.rw -rwdk
166 test_file_handles $SCRATCH_MNT/lowertestdir -dk
167 # Check encode/write/unlink/decode/read of lower file handles across copy up
168 test_file_handles $SCRATCH_MNT/lowertestdir.rw -rwdk
169 unmount_dirs
170
171 # Check stale handles of unlinked lower/upper files (nlink = 0)
172 create_dirs
173 create_test_files $upper/uppertestdir
174 create_test_files $lower/lowertestdir
175 mount_dirs
176 # Check decode of upper file handles after unlink/rmdir (nlink == 0)
177 test_file_handles $SCRATCH_MNT/uppertestdir -dp
178 # Check decode of lower file handles after unlink/rmdir (nlink == 0)
179 test_file_handles $SCRATCH_MNT/lowertestdir -dp
180 unmount_dirs
181
182 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
183 create_dirs
184 create_test_files $upper/uppertestdir
185 create_test_files $lower/lowertestdir
186 mount_dirs
187 # Check decode/read of upper file handles after link (nlink == 2)
188 test_file_handles $SCRATCH_MNT/uppertestdir -wlr
189 # Check decode/read of upper file handles after link + unlink (nlink == 1)
190 test_file_handles $SCRATCH_MNT/uppertestdir -ur
191 # Check decode/read of lower file handles after copy up + link (nlink == 2)
192 test_file_handles $SCRATCH_MNT/lowertestdir -wlr
193 # Check decode/read of lower file handles after copy up + link + unlink (nlink == 1)
194 test_file_handles $SCRATCH_MNT/lowertestdir -ur
195 unmount_dirs
196
197 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
198 create_dirs
199 create_test_files $upper/uppertestdir
200 create_test_files $lower/lowertestdir
201 # Create lower/upper hardlinks
202 link_test_files $lower/lowertestdir
203 link_test_files $upper/uppertestdir
204 mount_dirs
205 # Check encode/decode of upper hardlink file handles (nlink == 2)
206 test_file_handles $SCRATCH_MNT/uppertestdir
207 # Check decode/read of upper hardlink file handles after unlink (nlink == 1)
208 test_file_handles $SCRATCH_MNT/uppertestdir -wur
209 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
210 test_file_handles $SCRATCH_MNT/lowertestdir
211 # Check decode/read of lower hardlink file handles after copy up + unlink (nlink == 1)
212 test_file_handles $SCRATCH_MNT/lowertestdir -wur
213 unmount_dirs
214
215 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
216 create_dirs
217 create_test_files $upper/uppertestdir
218 create_test_files $lower/lowertestdir
219 # Create lower/upper hardlinks
220 link_test_files $lower/lowertestdir
221 link_test_files $upper/uppertestdir
222 mount_dirs
223 # Check encode/decode of upper hardlink file handles (nlink == 2)
224 test_file_handles $SCRATCH_MNT/uppertestdir
225 # Check decode of upper hardlink file handles after 2*unlink (nlink == 0)
226 test_file_handles $SCRATCH_MNT/uppertestdir -d
227 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
228 test_file_handles $SCRATCH_MNT/lowertestdir
229 # Check decode of lower hardlink file handles after copy up + 2*unlink (nlink == 0)
230 test_file_handles $SCRATCH_MNT/lowertestdir -d
231 unmount_dirs
232
233 # Check non-stale file handles of lower/upper renamed files
234 create_dirs
235 create_test_files $upper/uppertestdir
236 create_test_files $lower/lowertestdir
237 mount_dirs
238 # Check decode/read of upper file handles after rename in same upper parent
239 test_file_handles $SCRATCH_MNT/uppertestdir -wmr
240 # Check decode/read of lower file handles after copy up + rename in same merge parent
241 test_file_handles $SCRATCH_MNT/lowertestdir -wmr
242 unmount_dirs
243
244 status=0
245 exit