4 # Test encode/decode overlay file handles
6 # - Check encode/write/decode/read content of lower/upper file handles
7 # - Check encode/decode/write/read content of lower/upper file handles
8 # - Check decode/read of unlinked lower/upper files and directories
9 # - Check decode/read of lower file handles after copy up, link and unlink
11 # This test requires and enables overlayfs NFS export support.
12 # NFS export support depends on and requires overlayfs index feature.
14 #-----------------------------------------------------------------------
15 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
16 # Author: Amir Goldstein <amir73il@gmail.com>
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-----------------------------------------------------------------------
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
39 status=1 # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
48 # get standard environment, filters and checks
52 # real QA test starts here
57 _require_test_program "open_by_handle"
58 # We need to require both features together, because nfs_export cannot
59 # be enabled when index is disabled
60 _require_scratch_overlay_features index nfs_export
62 # All overlay dirs are on scratch partition
63 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
64 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
65 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
69 # Create test dir and empty test files
75 $here/src/open_by_handle -cp $dir $NUMFILES
78 # Create hard links to test files
83 $here/src/open_by_handle -l $dir $NUMFILES
86 # Test encode/decode file handles on overlay mount
92 echo test_file_handles $dir $opt | _filter_scratch
93 $here/src/open_by_handle $opt $dir $NUMFILES
96 # Re-create lower/upper/work dirs
102 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
105 _scratch_mount -o "index=on,nfs_export=on"
108 # Unmount the overlay without unmounting base fs
111 $UMOUNT_PROG $SCRATCH_MNT
114 # Check non-stale file handles of lower/upper files and verify
115 # that handle encoded before copy up is decoded to upper after
116 # copy up. Verify reading data from file open by file handle
117 # and verify access_at() with dirfd open by file handle.
119 create_test_files $upper/uppertestdir
120 create_test_files $lower/lowertestdir
122 # Check encode/decode of upper regular file handles
123 test_file_handles $SCRATCH_MNT/uppertestdir
124 # Check encode/decode of upper dir file handle
125 test_file_handles $SCRATCH_MNT/uppertestdir -p
126 # Check encode/write/decode/read/write of upper file handles
127 test_file_handles $SCRATCH_MNT/uppertestdir -wrap
128 # Check encode/decode of lower regular file handles before copy up
129 test_file_handles $SCRATCH_MNT/lowertestdir
130 # Check encode/decode of lower dir file handles before copy up
131 test_file_handles $SCRATCH_MNT/lowertestdir -p
132 # Check encode/write/decode/read/write of lower file handles across copy up
133 test_file_handles $SCRATCH_MNT/lowertestdir -wrap
136 # Check copy up after encode/decode of lower/upper files
137 # (copy up of disconnected dentry to index dir)
139 create_test_files $upper/uppertestdir
140 create_test_files $lower/lowertestdir
142 # Check encode/decode/write/read of upper regular file handles
143 test_file_handles $SCRATCH_MNT/uppertestdir -a
144 test_file_handles $SCRATCH_MNT/uppertestdir -r
145 # Check encode/decode/write/read of lower regular file handles
146 test_file_handles $SCRATCH_MNT/lowertestdir -a
147 test_file_handles $SCRATCH_MNT/lowertestdir -r
150 # Check non-stale handles to unlinked but open lower/upper files
152 create_test_files $upper/uppertestdir
153 create_test_files $upper/uppertestdir.rw
154 create_test_files $lower/lowertestdir
155 create_test_files $lower/lowertestdir.rw
157 test_file_handles $SCRATCH_MNT/uppertestdir -dk
158 # Check encode/write/unlink/decode/read of upper regular file handles
159 test_file_handles $SCRATCH_MNT/uppertestdir.rw -rwdk
160 test_file_handles $SCRATCH_MNT/lowertestdir -dk
161 # Check encode/write/unlink/decode/read of lower file handles across copy up
162 test_file_handles $SCRATCH_MNT/lowertestdir.rw -rwdk
165 # Check stale handles of unlinked lower/upper files (nlink = 0)
167 create_test_files $upper/uppertestdir
168 create_test_files $lower/lowertestdir
170 # Check decode of upper file handles after unlink/rmdir (nlink == 0)
171 test_file_handles $SCRATCH_MNT/uppertestdir -dp
172 # Check decode of lower file handles after unlink/rmdir (nlink == 0)
173 test_file_handles $SCRATCH_MNT/lowertestdir -dp
176 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
178 create_test_files $upper/uppertestdir
179 create_test_files $lower/lowertestdir
181 # Check decode/read of upper file handles after link (nlink == 2)
182 test_file_handles $SCRATCH_MNT/uppertestdir -wlr
183 # Check decode/read of upper file handles after link + unlink (nlink == 1)
184 test_file_handles $SCRATCH_MNT/uppertestdir -ur
185 # Check decode/read of lower file handles after copy up + link (nlink == 2)
186 test_file_handles $SCRATCH_MNT/lowertestdir -wlr
187 # Check decode/read of lower file handles after copy up + link + unlink (nlink == 1)
188 test_file_handles $SCRATCH_MNT/lowertestdir -ur
191 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
193 create_test_files $upper/uppertestdir
194 create_test_files $lower/lowertestdir
195 # Create lower/upper hardlinks
196 link_test_files $lower/lowertestdir
197 link_test_files $upper/uppertestdir
199 # Check encode/decode of upper hardlink file handles (nlink == 2)
200 test_file_handles $SCRATCH_MNT/uppertestdir
201 # Check decode/read of upper hardlink file handles after unlink (nlink == 1)
202 test_file_handles $SCRATCH_MNT/uppertestdir -wur
203 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
204 test_file_handles $SCRATCH_MNT/lowertestdir
205 # Check decode/read of lower hardlink file handles after copy up + unlink (nlink == 1)
206 test_file_handles $SCRATCH_MNT/lowertestdir -wur
209 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
211 create_test_files $upper/uppertestdir
212 create_test_files $lower/lowertestdir
213 # Create lower/upper hardlinks
214 link_test_files $lower/lowertestdir
215 link_test_files $upper/uppertestdir
217 # Check encode/decode of upper hardlink file handles (nlink == 2)
218 test_file_handles $SCRATCH_MNT/uppertestdir
219 # Check decode of upper hardlink file handles after 2*unlink (nlink == 0)
220 test_file_handles $SCRATCH_MNT/uppertestdir -d
221 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
222 test_file_handles $SCRATCH_MNT/lowertestdir
223 # Check decode of lower hardlink file handles after copy up + 2*unlink (nlink == 0)
224 test_file_handles $SCRATCH_MNT/lowertestdir -d
227 # Check non-stale file handles of lower/upper renamed files
229 create_test_files $upper/uppertestdir
230 create_test_files $lower/lowertestdir
232 # Check decode/read of upper file handles after rename in same upper parent
233 test_file_handles $SCRATCH_MNT/uppertestdir -wmr
234 # Check decode/read of lower file handles after copy up + rename in same merge parent
235 test_file_handles $SCRATCH_MNT/lowertestdir -wmr