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
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
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
52 # Create test dir and empty test files
58 $here/src/open_by_handle -cp $dir $NUMFILES
61 # Create hard links to test files
66 $here/src/open_by_handle -l $dir $NUMFILES
69 # Test encode/decode file handles on overlay mount
75 echo test_file_handles $dir $opt | _filter_scratch
76 $here/src/open_by_handle $opt $dir $NUMFILES
79 # Re-create lower/upper/work dirs
85 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
88 _scratch_mount -o "index=on,nfs_export=on"
91 # Unmount the overlay without unmounting base fs
94 $UMOUNT_PROG $SCRATCH_MNT
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.
102 create_test_files $upper/uppertestdir
103 create_test_files $lower/lowertestdir
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
119 # Check copy up after encode/decode of lower/upper files
120 # (copy up of disconnected dentry to index dir)
122 create_test_files $upper/uppertestdir
123 create_test_files $lower/lowertestdir
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
133 # Check non-stale handles to unlinked but open lower/upper files
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
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
148 # Check stale handles of unlinked lower/upper files (nlink = 0)
150 create_test_files $upper/uppertestdir
151 create_test_files $lower/lowertestdir
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
159 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
161 create_test_files $upper/uppertestdir
162 create_test_files $lower/lowertestdir
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
174 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
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
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
192 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
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
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
210 # Check non-stale file handles of lower/upper renamed files
212 create_test_files $upper/uppertestdir
213 create_test_files $lower/lowertestdir
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