overlay/029: fix test failure with nfs_export feature enabled
[xfstests-dev.git] / tests / overlay / 050
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. 050
6 #
7 # Test encode/decode overlay file handles
8 #
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
13 #
14 # This test requires and enables overlayfs NFS export support.
15 # NFS export support depends on and requires overlayfs index feature.
16 #
17 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # real QA test starts here
37
38 _supported_fs overlay
39 _supported_os Linux
40 _require_scratch
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
45
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
50
51 NUMFILES=1
52
53 # Create test dir and empty test files
54 create_test_files()
55 {
56         local dir=$1
57
58         mkdir -p $dir
59         $here/src/open_by_handle -cp $dir $NUMFILES
60 }
61
62 # Create hard links to test files
63 link_test_files()
64 {
65         local dir=$1
66
67         $here/src/open_by_handle -l $dir $NUMFILES
68 }
69
70 # Test encode/decode file handles on overlay mount
71 test_file_handles()
72 {
73         local dir=$1
74         local opt=$2
75
76         echo test_file_handles $dir $opt | _filter_scratch
77         $here/src/open_by_handle $opt $dir $NUMFILES
78 }
79
80 # Re-create lower/upper/work dirs
81 create_dirs()
82 {
83         _scratch_mkfs
84 }
85
86 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
87 mount_dirs()
88 {
89         _scratch_mount -o "index=on,nfs_export=on"
90 }
91
92 # Unmount the overlay without unmounting base fs
93 unmount_dirs()
94 {
95         $UMOUNT_PROG $SCRATCH_MNT
96 }
97
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.
102 create_dirs
103 create_test_files $upper/uppertestdir
104 create_test_files $lower/lowertestdir
105 mount_dirs
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
118 unmount_dirs
119
120 # Check copy up after encode/decode of lower/upper files
121 # (copy up of disconnected dentry to index dir)
122 create_dirs
123 create_test_files $upper/uppertestdir
124 create_test_files $lower/lowertestdir
125 mount_dirs
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
132 unmount_dirs
133
134 # Check non-stale handles to unlinked but open lower/upper files
135 create_dirs
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
140 mount_dirs
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
147 unmount_dirs
148
149 # Check stale handles of unlinked lower/upper files (nlink = 0)
150 create_dirs
151 create_test_files $upper/uppertestdir
152 create_test_files $lower/lowertestdir
153 mount_dirs
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
158 unmount_dirs
159
160 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
161 create_dirs
162 create_test_files $upper/uppertestdir
163 create_test_files $lower/lowertestdir
164 mount_dirs
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
173 unmount_dirs
174
175 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
176 create_dirs
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
182 mount_dirs
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
191 unmount_dirs
192
193 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
194 create_dirs
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
200 mount_dirs
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
209 unmount_dirs
210
211 # Check non-stale file handles of lower/upper renamed files
212 create_dirs
213 create_test_files $upper/uppertestdir
214 create_test_files $lower/lowertestdir
215 mount_dirs
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
220 unmount_dirs
221
222 status=0
223 exit