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
56 _require_test_program "open_by_handle"
57 # Use non-default scratch underlying overlay dirs, we need to check
58 # them explicity after test.
59 _require_scratch_nocheck
60 # We need to require all features together, because nfs_export cannot
61 # be enabled when index is disabled
62 _require_scratch_overlay_features index nfs_export redirect_dir
64 # Lower is on test partition
65 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
66 # Upper/work are on scratch partition
67 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
68 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
69 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
73 # Create test dir and empty test files
80 $here/src/open_by_handle -cp $opt $dir $NUMFILES
83 # Test encode/decode file handles on overlay mount
89 echo test_file_handles $dir $* | _filter_scratch | \
91 $here/src/open_by_handle $* $dir $NUMFILES
94 # Re-create lower/middle/upper/work dirs
97 # Create lower dir on test partition
101 # Create middle/upper/work dirs on scratch partition
105 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
106 # and middle and upper layer on scratch partition
109 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
110 -o "index=on,nfs_export=on,redirect_dir=on"
113 # Unmount the overlay without unmounting base fs and check the
117 $UMOUNT_PROG $SCRATCH_MNT
119 _overlay_check_scratch_dirs $middle:$lower $upper $work \
120 -o "index=on,nfs_export=on,redirect_dir=on"
123 # Check file handles of dir with ancestor under lower redirect
125 create_test_files $lower/origin -w
126 create_test_files $lower/origin/dir -w
127 create_test_files $lower/origin/dir/subdir -w
128 create_test_files $lower/origin/parent/child -w
129 # Create lower redirected merge dir
131 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
133 # Check encode/decode/read of lower dir with parent under lower redirect
134 # This is expected to copy up merged/dir and encode an upper file handle
135 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
136 test -d $upper/merged/dir || echo "merged/dir not copied up"
137 # Check encode/decode/read of lower dir with grandparent under lower redirect
138 # This is expected to encode a lower file handle
139 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
140 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
141 # This is expected to copy up parent and encode a lower file handle
142 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
143 test -d $upper/merged/parent || echo "merged/parent not copied up"
144 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
146 # Rename lower redirected merge dir
147 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
148 # Check open, read and readdir from stored file handles
149 # (testdir argument is the mount point and NOT the dir
150 # we are trying to open by stored file handle)
151 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
152 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
153 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
154 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
155 # (providing the ancestor dir argument pins the ancestor to dcache)
156 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
157 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
158 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles