31d970026c107fec3ed9279a9d712dd238edb230
[xfstests-dev.git] / tests / overlay / 050
1 #! /bin/bash
2 # FS QA Test No. 050
3 #
4 # Test encode/decode overlay file handles
5 #
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
10 #
11 # This test requires and enables overlayfs NFS export support.
12 # NFS export support depends on and requires overlayfs index feature.
13 #
14 #-----------------------------------------------------------------------
15 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
16 # Author: Amir Goldstein <amir73il@gmail.com>
17 #
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.
21 #
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.
26 #
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 #-----------------------------------------------------------------------
31 #
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44         cd /
45         rm -f $tmp.*
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53
54 _supported_fs overlay
55 _supported_os Linux
56 _require_scratch
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
61
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
66
67 NUMFILES=1
68
69 # Create test dir and empty test files
70 create_test_files()
71 {
72         local dir=$1
73
74         mkdir -p $dir
75         $here/src/open_by_handle -cp $dir $NUMFILES
76 }
77
78 # Create hard links to test files
79 link_test_files()
80 {
81         local dir=$1
82
83         $here/src/open_by_handle -l $dir $NUMFILES
84 }
85
86 # Test encode/decode file handles on overlay mount
87 test_file_handles()
88 {
89         local dir=$1
90         local opt=$2
91
92         echo test_file_handles $dir $opt | _filter_scratch
93         $here/src/open_by_handle $opt $dir $NUMFILES
94 }
95
96 # Re-create lower/upper/work dirs
97 create_dirs()
98 {
99         _scratch_mkfs
100 }
101
102 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
103 mount_dirs()
104 {
105         _scratch_mount -o "index=on,nfs_export=on"
106 }
107
108 # Unmount the overlay without unmounting base fs
109 unmount_dirs()
110 {
111         $UMOUNT_PROG $SCRATCH_MNT
112 }
113
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.
118 create_dirs
119 create_test_files $upper/uppertestdir
120 create_test_files $lower/lowertestdir
121 mount_dirs
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
134 unmount_dirs
135
136 # Check copy up after encode/decode of lower/upper files
137 # (copy up of disconnected dentry to index dir)
138 create_dirs
139 create_test_files $upper/uppertestdir
140 create_test_files $lower/lowertestdir
141 mount_dirs
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
148 unmount_dirs
149
150 # Check non-stale handles to unlinked but open lower/upper files
151 create_dirs
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
156 mount_dirs
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
163 unmount_dirs
164
165 # Check stale handles of unlinked lower/upper files (nlink = 0)
166 create_dirs
167 create_test_files $upper/uppertestdir
168 create_test_files $lower/lowertestdir
169 mount_dirs
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
174 unmount_dirs
175
176 # Check non-stale file handles of linked lower/upper files (nlink = 2,1)
177 create_dirs
178 create_test_files $upper/uppertestdir
179 create_test_files $lower/lowertestdir
180 mount_dirs
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
189 unmount_dirs
190
191 # Check non-stale file handles of linked lower/upper hardlinks (nlink = 2,1)
192 create_dirs
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
198 mount_dirs
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
207 unmount_dirs
208
209 # Check stale file handles of unlinked lower/upper hardlinks (nlink = 2,0)
210 create_dirs
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
216 mount_dirs
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
225 unmount_dirs
226
227 # Check non-stale file handles of lower/upper renamed files
228 create_dirs
229 create_test_files $upper/uppertestdir
230 create_test_files $lower/lowertestdir
231 mount_dirs
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
236 unmount_dirs
237
238 status=0
239 exit