2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test encode/decode overlay file handles
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
14 # This test requires and enables overlayfs NFS export support.
15 # NFS export support depends on and requires overlayfs index feature.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
36 # real QA test starts here
41 _require_test_program "open_by_handle"
42 # We need to require both features together, because nfs_export cannot
43 # be enabled when index is disabled
44 _require_scratch_overlay_features index nfs_export
46 # All overlay dirs are on scratch partition
47 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
48 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
49 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
53 # Create test dir and empty test files
59 $here/src/open_by_handle -cp $dir $NUMFILES
62 # Create hard links to test files
67 $here/src/open_by_handle -l $dir $NUMFILES
70 # Test encode/decode file handles on overlay mount
76 echo test_file_handles $dir $opt | _filter_scratch
77 $here/src/open_by_handle $opt $dir $NUMFILES
80 # Re-create lower/upper/work dirs
86 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
89 _scratch_mount -o "index=on,nfs_export=on"
92 # Unmount the overlay without unmounting base fs
95 $UMOUNT_PROG $SCRATCH_MNT
98 # Check non-stale file handles of lower/upper files and verify
99 # that handle encoded before copy up is decoded to upper after
100 # copy up. Verify reading data from file open by file handle
101 # and verify access_at() with dirfd open by file handle.
103 create_test_files $upper/uppertestdir
104 create_test_files $lower/lowertestdir
106 # Check encode/decode of upper regular file handles
107 test_file_handles $SCRATCH_MNT/uppertestdir
108 # Check encode/decode of upper dir file handle
109 test_file_handles $SCRATCH_MNT/uppertestdir -p
110 # Check encode/write/decode/read/write of upper file handles
111 test_file_handles $SCRATCH_MNT/uppertestdir -wrap
112 # Check encode/decode of lower regular file handles before copy up
113 test_file_handles $SCRATCH_MNT/lowertestdir
114 # Check encode/decode of lower dir file handles before copy up
115 test_file_handles $SCRATCH_MNT/lowertestdir -p
116 # Check encode/write/decode/read/write of lower file handles across copy up
117 test_file_handles $SCRATCH_MNT/lowertestdir -wrap
120 # Check copy up after encode/decode of lower/upper files
121 # (copy up of disconnected dentry to index dir)
123 create_test_files $upper/uppertestdir
124 create_test_files $lower/lowertestdir
126 # Check encode/decode/write/read of upper regular file handles
127 test_file_handles $SCRATCH_MNT/uppertestdir -a
128 test_file_handles $SCRATCH_MNT/uppertestdir -r
129 # Check encode/decode/write/read of lower regular file handles
130 test_file_handles $SCRATCH_MNT/lowertestdir -a
131 test_file_handles $SCRATCH_MNT/lowertestdir -r
134 # Check non-stale handles to unlinked but open lower/upper files
136 create_test_files $upper/uppertestdir
137 create_test_files $upper/uppertestdir.rw
138 create_test_files $lower/lowertestdir
139 create_test_files $lower/lowertestdir.rw
141 test_file_handles $SCRATCH_MNT/uppertestdir -dk
142 # Check encode/write/unlink/decode/read of upper regular file handles
143 test_file_handles $SCRATCH_MNT/uppertestdir.rw -rwdk
144 test_file_handles $SCRATCH_MNT/lowertestdir -dk
145 # Check encode/write/unlink/decode/read of lower file handles across copy up
146 test_file_handles $SCRATCH_MNT/lowertestdir.rw -rwdk
149 # Check stale handles of unlinked lower/upper files (nlink = 0)
151 create_test_files $upper/uppertestdir
152 create_test_files $lower/lowertestdir
154 # Check decode of upper file handles after unlink/rmdir (nlink == 0)
155 test_file_handles $SCRATCH_MNT/uppertestdir -dp
156 # Check decode of lower file handles after unlink/rmdir (nlink == 0)
157 test_file_handles $SCRATCH_MNT/lowertestdir -dp
160 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
162 create_test_files $upper/uppertestdir
163 create_test_files $lower/lowertestdir
165 # Check decode/read of upper file handles after link (nlink == 2)
166 test_file_handles $SCRATCH_MNT/uppertestdir -wlr
167 # Check decode/read of upper file handles after link + unlink (nlink == 1)
168 test_file_handles $SCRATCH_MNT/uppertestdir -ur
169 # Check decode/read of lower file handles after copy up + link (nlink == 2)
170 test_file_handles $SCRATCH_MNT/lowertestdir -wlr
171 # Check decode/read of lower file handles after copy up + link + unlink (nlink == 1)
172 test_file_handles $SCRATCH_MNT/lowertestdir -ur
175 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
177 create_test_files $upper/uppertestdir
178 create_test_files $lower/lowertestdir
179 # Create lower/upper hardlinks
180 link_test_files $lower/lowertestdir
181 link_test_files $upper/uppertestdir
183 # Check encode/decode of upper hardlink file handles (nlink == 2)
184 test_file_handles $SCRATCH_MNT/uppertestdir
185 # Check decode/read of upper hardlink file handles after unlink (nlink == 1)
186 test_file_handles $SCRATCH_MNT/uppertestdir -wur
187 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
188 test_file_handles $SCRATCH_MNT/lowertestdir
189 # Check decode/read of lower hardlink file handles after copy up + unlink (nlink == 1)
190 test_file_handles $SCRATCH_MNT/lowertestdir -wur
193 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
195 create_test_files $upper/uppertestdir
196 create_test_files $lower/lowertestdir
197 # Create lower/upper hardlinks
198 link_test_files $lower/lowertestdir
199 link_test_files $upper/uppertestdir
201 # Check encode/decode of upper hardlink file handles (nlink == 2)
202 test_file_handles $SCRATCH_MNT/uppertestdir
203 # Check decode of upper hardlink file handles after 2*unlink (nlink == 0)
204 test_file_handles $SCRATCH_MNT/uppertestdir -d
205 # Check encode/decode of lower hardlink file handles before copy up (nlink == 2)
206 test_file_handles $SCRATCH_MNT/lowertestdir
207 # Check decode of lower hardlink file handles after copy up + 2*unlink (nlink == 0)
208 test_file_handles $SCRATCH_MNT/lowertestdir -d
211 # Check non-stale file handles of lower/upper renamed files
213 create_test_files $upper/uppertestdir
214 create_test_files $lower/lowertestdir
216 # Check decode/read of upper file handles after rename in same upper parent
217 test_file_handles $SCRATCH_MNT/uppertestdir -wmr
218 # Check decode/read of lower file handles after copy up + rename in same merge parent
219 test_file_handles $SCRATCH_MNT/lowertestdir -wmr