xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / overlay / 051
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 051
6 #
7 # Test encode/decode overlay file handles for non-samefs.
8 #
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.
11 #
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
16 #
17 # This test requires and enables overlayfs NFS export support.
18 # NFS export support depends on and requires overlayfs index feature.
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
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
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44
45 _supported_fs overlay
46 _supported_os Linux
47 _require_test
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
55
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
62
63 NUMFILES=1
64
65 # Create test dir and empty test files
66 create_test_files()
67 {
68         local dir=$1
69
70         mkdir -p $dir
71         $here/src/open_by_handle -cp $dir $NUMFILES
72 }
73
74 # Create hard links to test files
75 link_test_files()
76 {
77         local dir=$1
78
79         $here/src/open_by_handle -l $dir $NUMFILES
80 }
81
82 # Test encode/decode file handles on overlay mount
83 test_file_handles()
84 {
85         local dir=$1
86         local opt=$2
87
88         echo test_file_handles $dir $opt | _filter_scratch
89         $here/src/open_by_handle $opt $dir $NUMFILES
90 }
91
92 # Re-create lower/middle/upper/work dirs
93 create_dirs()
94 {
95         # Create lower dir on test partition
96         rm -rf $lower
97         mkdir $lower
98
99         # Create middle/upper/work dirs on scratch partition
100         _scratch_mkfs
101 }
102
103 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
104 # and middle and upper layer on scratch partition
105 mount_dirs()
106 {
107         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
108                                 -o "index=on,nfs_export=on"
109 }
110
111 # Unmount the overlay without unmounting base fs and check the
112 # underlying dirs
113 unmount_dirs()
114 {
115         $UMOUNT_PROG $SCRATCH_MNT
116
117         _overlay_check_scratch_dirs $middle:$lower $upper $work \
118                                 -o "index=on,nfs_export=on"
119 }
120
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.
125 create_dirs
126 create_test_files $upper/uppertestdir
127 create_test_files $lower/lowertestdir
128 mount_dirs
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
141 unmount_dirs
142
143 # Check copy up after encode/decode of lower/upper files
144 # (copy up of disconnected dentry to index dir)
145 create_dirs
146 create_test_files $upper/uppertestdir
147 create_test_files $lower/lowertestdir
148 mount_dirs
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
155 unmount_dirs
156
157 # Check non-stale handles to unlinked but open lower/upper files
158 create_dirs
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
163 mount_dirs
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
170 unmount_dirs
171
172 # Check stale handles of unlinked lower/upper files (nlink = 0)
173 create_dirs
174 create_test_files $upper/uppertestdir
175 create_test_files $lower/lowertestdir
176 mount_dirs
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
181 unmount_dirs
182
183 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
184 create_dirs
185 create_test_files $upper/uppertestdir
186 create_test_files $lower/lowertestdir
187 mount_dirs
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
196 unmount_dirs
197
198 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
199 create_dirs
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
205 mount_dirs
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
214 unmount_dirs
215
216 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
217 create_dirs
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
223 mount_dirs
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
232 unmount_dirs
233
234 # Check non-stale file handles of lower/upper renamed files
235 create_dirs
236 create_test_files $upper/uppertestdir
237 create_test_files $lower/lowertestdir
238 mount_dirs
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
243 unmount_dirs
244
245 status=0
246 exit