4 # Test overlay file handle of dir with ancestor under lower redirect
6 # Overlayfs with nfs_export enabled, indexes all directories on copy up.
7 # Directory index is requires for decoding lower directory file handles
8 # in case ancestors have been renamed.
10 # When enabling nfs_export on an overlay that has merge dirs with lower
11 # layer redirects, the possibility of ancestor rename requires special
12 # handling when encoding lower directory file handles from layer > 1.
14 # - Check decode of lower dir with parent under lower redirect
15 # - Check decode of lower dir with grandparent under lower redirect
16 # - Check decode of lower dir after rename of lower redirected parent
17 # - Check decode of lower dir after rename of lower redirected grandparent
19 # This test requires and enables overlayfs NFS export support and merge
20 # dir rename support (redirect_dir).
21 # NFS export support depends on and requires overlayfs index feature.
23 #-----------------------------------------------------------------------
24 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
25 # Author: Amir Goldstein <amir73il@gmail.com>
27 # This program is free software; you can redistribute it and/or
28 # modify it under the terms of the GNU General Public License as
29 # published by the Free Software Foundation.
31 # This program is distributed in the hope that it would be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 # GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License
37 # along with this program; if not, write the Free Software Foundation,
38 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 #-----------------------------------------------------------------------
43 seqres=$RESULT_DIR/$seq
44 echo "QA output created by $seq"
48 status=1 # failure is the default!
49 trap "_cleanup; exit \$status" 0 1 2 3 15
55 # Cleanup overlay scratch mount that is holding base test mount
56 # to prevent _check_test_fs and _test_umount from failing before
57 # _check_scratch_fs _scratch_umount
58 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
61 # get standard environment, filters and checks
65 # real QA test starts here
70 _require_test_program "open_by_handle"
71 # Use non-default scratch underlying overlay dirs, we need to check
72 # them explicity after test.
73 _require_scratch_nocheck
74 # We need to require all features together, because nfs_export cannot
75 # be enabled when index is disabled
76 _require_scratch_overlay_features index nfs_export redirect_dir
78 # Lower is on test partition
79 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
80 # Upper/work are on scratch partition
81 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
82 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
83 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
87 # Create test dir and empty test files
94 $here/src/open_by_handle -cp $opt $dir $NUMFILES
97 # Test encode/decode file handles on overlay mount
103 echo test_file_handles $dir $* | _filter_scratch | \
105 $here/src/open_by_handle $* $dir $NUMFILES
108 # Re-create lower/middle/upper/work dirs
111 # Create lower dir on test partition
115 # Create middle/upper/work dirs on scratch partition
119 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
120 # and middle and upper layer on scratch partition
123 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
124 -o "index=on,nfs_export=on,redirect_dir=on"
127 # Unmount the overlay without unmounting base fs and check the
131 $UMOUNT_PROG $SCRATCH_MNT
133 _overlay_check_scratch_dirs $middle:$lower $upper $work \
134 -o "index=on,nfs_export=on,redirect_dir=on"
137 # Check file handles of dir with ancestor under lower redirect
139 create_test_files $lower/origin -w
140 create_test_files $lower/origin/dir -w
141 create_test_files $lower/origin/dir/subdir -w
142 create_test_files $lower/origin/parent/child -w
143 # Create lower redirected merge dir
145 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
147 # Check encode/decode/read of lower dir with parent under lower redirect
148 # This is expected to copy up merged/dir and encode an upper file handle
149 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
150 test -d $upper/merged/dir || echo "merged/dir not copied up"
151 # Check encode/decode/read of lower dir with grandparent under lower redirect
152 # This is expected to encode a lower file handle
153 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
154 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
155 # This is expected to copy up parent and encode a lower file handle
156 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
157 test -d $upper/merged/parent || echo "merged/parent not copied up"
158 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
160 # Rename lower redirected merge dir
161 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
162 # Check open, read and readdir from stored file handles
163 # (testdir argument is the mount point and NOT the dir
164 # we are trying to open by stored file handle)
165 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
166 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
167 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
168 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
169 # (providing the ancestor dir argument pins the ancestor to dcache)
170 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
171 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
172 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles