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
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
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
64 # Create test dir and empty test files
70 $here/src/open_by_handle -cp $dir $NUMFILES
73 # Create hard links to test files
78 $here/src/open_by_handle -l $dir $NUMFILES
81 # Test encode/decode file handles on overlay mount
87 echo test_file_handles $dir $opt | _filter_scratch
88 $here/src/open_by_handle $opt $dir $NUMFILES
91 # Re-create lower/middle/upper/work dirs
94 # Create lower dir on test partition
98 # Create middle/upper/work dirs on scratch partition
102 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
103 # and middle and upper layer on scratch partition
106 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
107 -o "index=on,nfs_export=on"
110 # Unmount the overlay without unmounting base fs and check the
114 $UMOUNT_PROG $SCRATCH_MNT
116 _overlay_check_scratch_dirs $middle:$lower $upper $work \
117 -o "index=on,nfs_export=on"
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.
125 create_test_files $upper/uppertestdir
126 create_test_files $lower/lowertestdir
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
142 # Check copy up after encode/decode of lower/upper files
143 # (copy up of disconnected dentry to index dir)
145 create_test_files $upper/uppertestdir
146 create_test_files $lower/lowertestdir
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
156 # Check non-stale handles to unlinked but open lower/upper files
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
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
171 # Check stale handles of unlinked lower/upper files (nlink = 0)
173 create_test_files $upper/uppertestdir
174 create_test_files $lower/lowertestdir
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
182 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
184 create_test_files $upper/uppertestdir
185 create_test_files $lower/lowertestdir
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
197 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
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
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
215 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
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
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
233 # Check non-stale file handles of lower/upper renamed files
235 create_test_files $upper/uppertestdir
236 create_test_files $lower/lowertestdir
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