2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test overlay file handle of dir with ancestor under lower redirect
9 # Overlayfs with nfs_export enabled, indexes all directories on copy up.
10 # Directory index is requires for decoding lower directory file handles
11 # in case ancestors have been renamed.
13 # When enabling nfs_export on an overlay that has merge dirs with lower
14 # layer redirects, the possibility of ancestor rename requires special
15 # handling when encoding lower directory file handles from layer > 1.
17 # - Check decode of lower dir with parent under lower redirect
18 # - Check decode of lower dir with grandparent under lower redirect
19 # - Check decode of lower dir after rename of lower redirected parent
20 # - Check decode of lower dir after rename of lower redirected grandparent
22 # This test requires and enables overlayfs NFS export support and merge
23 # dir rename support (redirect_dir).
24 # NFS export support depends on and requires overlayfs index feature.
26 # Regression test for kernel commit 2ca3c148a062 ("ovl: check lower ancestry
27 # on encode of lower dir file handle")
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # Cleanup overlay scratch mount that is holding base test mount
43 # to prevent _check_test_fs and _test_umount from failing before
44 # _check_scratch_fs _scratch_umount
45 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
48 # get standard environment, filters and checks
52 # real QA test starts here
57 _require_test_program "open_by_handle"
58 # Use non-default scratch underlying overlay dirs, we need to check
59 # them explicity after test.
60 _require_scratch_nocheck
61 # We need to require all features together, because nfs_export cannot
62 # be enabled when index is disabled
63 _require_scratch_overlay_features index nfs_export redirect_dir
65 # Lower is on test partition
66 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
67 # Upper/work are on scratch partition
68 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
69 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
70 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
74 # Create test dir and empty test files
81 $here/src/open_by_handle -cp $opt $dir $NUMFILES
84 # Test encode/decode file handles on overlay mount
90 echo test_file_handles $dir $* | _filter_scratch | \
92 $here/src/open_by_handle $* $dir $NUMFILES
95 # Re-create lower/middle/upper/work dirs
98 # Create lower dir on test partition
102 # Create middle/upper/work dirs on scratch partition
106 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
107 # and middle and upper layer on scratch partition
110 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
111 -o "index=on,nfs_export=on,redirect_dir=on"
114 # Unmount the overlay without unmounting base fs and check the
118 $UMOUNT_PROG $SCRATCH_MNT
120 _overlay_check_scratch_dirs $middle:$lower $upper $work \
121 -o "index=on,nfs_export=on,redirect_dir=on"
124 # Check file handles of dir with ancestor under lower redirect
126 create_test_files $lower/origin -w
127 create_test_files $lower/origin/dir -w
128 create_test_files $lower/origin/dir/subdir -w
129 create_test_files $lower/origin/parent/child -w
130 # Create lower redirected merge dir
132 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
134 # Check encode/decode/read of lower dir with parent under lower redirect
135 # This is expected to copy up merged/dir and encode an upper file handle
136 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
137 test -d $upper/merged/dir || echo "merged/dir not copied up"
138 # Check encode/decode/read of lower dir with grandparent under lower redirect
139 # This is expected to encode a lower file handle
140 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
141 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
142 # This is expected to copy up parent and encode a lower file handle
143 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
144 test -d $upper/merged/parent || echo "merged/parent not copied up"
145 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
147 # Rename lower redirected merge dir
148 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
149 # Check open, read and readdir from stored file handles
150 # (testdir argument is the mount point and NOT the dir
151 # we are trying to open by stored file handle)
152 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
153 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
154 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
155 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
156 # (providing the ancestor dir argument pins the ancestor to dcache)
157 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
158 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
159 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles