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