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
71 _require_test_program "open_by_handle"
72 # We need to require all features together, because nfs_export cannot
73 # be enabled when index is disabled
74 _require_scratch_overlay_features index nfs_export redirect_dir
76 # Lower is on test partition
77 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
78 # Upper/work are on scratch partition
79 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
80 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
81 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
85 # Create test dir and empty test files
92 $here/src/open_by_handle -cp $opt $dir $NUMFILES
95 # Test encode/decode file handles on overlay mount
101 echo test_file_handles $dir $* | _filter_scratch | \
103 $here/src/open_by_handle $* $dir $NUMFILES
106 # Re-create lower/middle/upper/work dirs
109 # Create lower dir on test partition
113 # Create middle/upper/work dirs on scratch partition
117 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
118 # and middle and upper layer on scratch partition
121 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
122 -o "index=on,nfs_export=on,redirect_dir=on"
125 # Unmount the overlay without unmounting base fs
128 $UMOUNT_PROG $SCRATCH_MNT
131 # Check file handles of dir with ancestor under lower redirect
133 create_test_files $lower/origin -w
134 create_test_files $lower/origin/dir -w
135 create_test_files $lower/origin/dir/subdir -w
136 create_test_files $lower/origin/parent/child -w
137 # Create lower redirected merge dir
139 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
141 # Check encode/decode/read of lower dir with parent under lower redirect
142 # This is expected to copy up merged/dir and encode an upper file handle
143 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
144 test -d $upper/merged/dir || echo "merged/dir not copied up"
145 # Check encode/decode/read of lower dir with grandparent under lower redirect
146 # This is expected to encode a lower file handle
147 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
148 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
149 # This is expected to copy up parent and encode a lower file handle
150 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
151 test -d $upper/merged/parent || echo "merged/parent not copied up"
152 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
154 # Rename lower redirected merge dir
155 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
156 # Check open, read and readdir from stored file handles
157 # (testdir argument is the mount point and NOT the dir
158 # we are trying to open by stored file handle)
159 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
160 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
161 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
162 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
163 # (providing the ancestor dir argument pins the ancestor to dcache)
164 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
165 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
166 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles