2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test encode/decode overlay file handles for non-samefs.
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.
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
17 # This test requires and enables overlayfs NFS export support.
18 # NFS export support depends on and requires overlayfs index feature.
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
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
39 # get standard environment, filters and checks
43 # real QA test starts here
48 _require_test_program "open_by_handle"
49 # Use non-default scratch underlying overlay dirs, we need to check
50 # them explicity after test.
51 _require_scratch_nocheck
52 # We need to require both features together, because nfs_export cannot
53 # be enabled when index is disabled
54 _require_scratch_overlay_features index nfs_export
56 # Lower is on test partition
57 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
58 # Upper/work are on scratch partition
59 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
60 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
61 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
65 # Create test dir and empty test files
71 $here/src/open_by_handle -cp $dir $NUMFILES
74 # Create hard links to test files
79 $here/src/open_by_handle -l $dir $NUMFILES
82 # Test encode/decode file handles on overlay mount
88 echo test_file_handles $dir $opt | _filter_scratch
89 $here/src/open_by_handle $opt $dir $NUMFILES
92 # Re-create lower/middle/upper/work dirs
95 # Create lower dir on test partition
99 # Create middle/upper/work dirs on scratch partition
103 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
104 # and middle and upper layer on scratch partition
107 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
108 -o "index=on,nfs_export=on"
111 # Unmount the overlay without unmounting base fs and check the
115 $UMOUNT_PROG $SCRATCH_MNT
117 _overlay_check_scratch_dirs $middle:$lower $upper $work \
118 -o "index=on,nfs_export=on"
121 # Check non-stale file handles of lower/upper files and verify
122 # that handle encoded before copy up is decoded to upper after
123 # copy up. Verify reading data from file open by file handle
124 # and verify access_at() with dirfd open by file handle.
126 create_test_files $upper/uppertestdir
127 create_test_files $lower/lowertestdir
129 # Check encode/decode of upper regular file handles
130 test_file_handles $SCRATCH_MNT/uppertestdir
131 # Check encode/decode of upper dir file handle
132 test_file_handles $SCRATCH_MNT/uppertestdir -p
133 # Check encode/write/decode/read/write of upper file handles
134 test_file_handles $SCRATCH_MNT/uppertestdir -wrap
135 # Check encode/decode of lower regular file handles before copy up
136 test_file_handles $SCRATCH_MNT/lowertestdir
137 # Check encode/decode of lower dir file handles before copy up
138 test_file_handles $SCRATCH_MNT/lowertestdir -p
139 # Check encode/write/decode/read/write of lower file handles across copy up
140 test_file_handles $SCRATCH_MNT/lowertestdir -wrap
143 # Check copy up after encode/decode of lower/upper files
144 # (copy up of disconnected dentry to index dir)
146 create_test_files $upper/uppertestdir
147 create_test_files $lower/lowertestdir
149 # Check encode/decode/write/read of upper regular file handles
150 test_file_handles $SCRATCH_MNT/uppertestdir -a
151 test_file_handles $SCRATCH_MNT/uppertestdir -r
152 # Check encode/decode/write/read of lower regular file handles
153 test_file_handles $SCRATCH_MNT/lowertestdir -a
154 test_file_handles $SCRATCH_MNT/lowertestdir -r
157 # Check non-stale handles to unlinked but open lower/upper files
159 create_test_files $upper/uppertestdir
160 create_test_files $upper/uppertestdir.rw
161 create_test_files $lower/lowertestdir
162 create_test_files $lower/lowertestdir.rw
164 test_file_handles $SCRATCH_MNT/uppertestdir -dk
165 # Check encode/write/unlink/decode/read of upper regular file handles
166 test_file_handles $SCRATCH_MNT/uppertestdir.rw -rwdk
167 test_file_handles $SCRATCH_MNT/lowertestdir -dk
168 # Check encode/write/unlink/decode/read of lower file handles across copy up
169 test_file_handles $SCRATCH_MNT/lowertestdir.rw -rwdk
172 # Check stale handles of unlinked lower/upper files (nlink = 0)
174 create_test_files $upper/uppertestdir
175 create_test_files $lower/lowertestdir
177 # Check decode of upper file handles after unlink/rmdir (nlink == 0)
178 test_file_handles $SCRATCH_MNT/uppertestdir -dp
179 # Check decode of lower file handles after unlink/rmdir (nlink == 0)
180 test_file_handles $SCRATCH_MNT/lowertestdir -dp
183 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
185 create_test_files $upper/uppertestdir
186 create_test_files $lower/lowertestdir
188 # Check decode/read of upper file handles after link (nlink == 2)
189 test_file_handles $SCRATCH_MNT/uppertestdir -wlr
190 # Check decode/read of upper file handles after link + unlink (nlink == 1)
191 test_file_handles $SCRATCH_MNT/uppertestdir -ur
192 # Check decode/read of lower file handles after copy up + link (nlink == 2)
193 test_file_handles $SCRATCH_MNT/lowertestdir -wlr
194 # Check decode/read of lower file handles after copy up + link + unlink (nlink == 1)
195 test_file_handles $SCRATCH_MNT/lowertestdir -ur
198 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
200 create_test_files $upper/uppertestdir
201 create_test_files $lower/lowertestdir
202 # Create lower/upper hardlinks
203 link_test_files $lower/lowertestdir
204 link_test_files $upper/uppertestdir
206 # Check encode/decode of upper hardlink file handles (nlink == 2)
207 test_file_handles $SCRATCH_MNT/uppertestdir
208 # Check decode/read of upper hardlink file handles after unlink (nlink == 1)
209 test_file_handles $SCRATCH_MNT/uppertestdir -wur
210 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
211 test_file_handles $SCRATCH_MNT/lowertestdir
212 # Check decode/read of lower hardlink file handles after copy up + unlink (nlink == 1)
213 test_file_handles $SCRATCH_MNT/lowertestdir -wur
216 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
218 create_test_files $upper/uppertestdir
219 create_test_files $lower/lowertestdir
220 # Create lower/upper hardlinks
221 link_test_files $lower/lowertestdir
222 link_test_files $upper/uppertestdir
224 # Check encode/decode of upper hardlink file handles (nlink == 2)
225 test_file_handles $SCRATCH_MNT/uppertestdir
226 # Check decode of upper hardlink file handles after 2*unlink (nlink == 0)
227 test_file_handles $SCRATCH_MNT/uppertestdir -d
228 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
229 test_file_handles $SCRATCH_MNT/lowertestdir
230 # Check decode of lower hardlink file handles after copy up + 2*unlink (nlink == 0)
231 test_file_handles $SCRATCH_MNT/lowertestdir -d
234 # Check non-stale file handles of lower/upper renamed files
236 create_test_files $upper/uppertestdir
237 create_test_files $lower/lowertestdir
239 # Check decode/read of upper file handles after rename in same upper parent
240 test_file_handles $SCRATCH_MNT/uppertestdir -wmr
241 # Check decode/read of lower file handles after copy up + rename in same merge parent
242 test_file_handles $SCRATCH_MNT/lowertestdir -wmr