2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test encode/decode overlay file handle of dir with non-indexed ancestor
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 already has non-indexed
14 # merge dirs, the possibility of non-indexed ancestor rename requires
15 # special handling when encoding lower directory file handles.
17 # - Check encode/decode/read file handles of non-indexed merge dir
18 # - Check encode/decode/read file handles of dir with non-indexed parent
19 # - Check encode/decode/read file handles of dir with non-indexed grandparent
20 # - Check decode/read of file handles after rename of non-indexed merge dir
21 # - Check decode/read of file handles after rename of non-indexed parent
22 # - Check decode/read of file handles after rename of non-indexed grandparent
24 # This test requires and enables overlayfs NFS export support and merge
25 # dir rename support (redirect_dir).
26 # NFS export support depends on and requires overlayfs index feature.
28 # Regression test for kernel commit 2ca3c148a062 ("ovl: check lower ancestry
29 # on encode of lower dir file handle")
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
50 # real QA test starts here
55 _require_test_program "open_by_handle"
56 # We need to require all features together, because nfs_export cannot
57 # be enabled when index is disabled
58 _require_scratch_overlay_features index nfs_export redirect_dir
60 # All overlay dirs are on scratch partition
61 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
62 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
63 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
67 # Create test dir and empty test files
74 $here/src/open_by_handle -cp $opt $dir $NUMFILES
77 # Test encode/decode file handles on overlay mount
83 echo test_file_handles $dir $* | _filter_scratch | \
85 $here/src/open_by_handle $* $dir $NUMFILES
88 # Re-create lower/upper/work dirs
94 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
97 _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
100 # Unmount the overlay without unmounting base fs
103 $UMOUNT_PROG $SCRATCH_MNT
106 # Check encode/decode/read file handles of dir with non-indexed ancestor
108 create_test_files $lower/merged -w
109 create_test_files $lower/merged/dir -w
110 create_test_files $lower/merged/dir/subdir -w
111 create_test_files $lower/merged/parent/child -w
112 # Create non-indexed merge dir
115 # Check encode/decode/read file handles of non-indexed merge dir
116 # This is expected to encode an upper file handle
117 test_file_handles $SCRATCH_MNT/merged -p -o $tmp.merged_file_handles
118 # Check encode/decode/read file handles of dir with non-indexed parent
119 # This is expected to copy up merged/dir and encode an upper file handle
120 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
121 test -d $upper/merged/dir || echo "merged/dir not copied up"
122 # Check encode/decode/read file handles of dir with non-indexed grandparent
123 # This is expected to encode a lower file handle
124 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
125 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
126 # This is expected to copy up parent and encode a lower file handle
127 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
128 test -d $upper/merged/parent || echo "merged/parent not copied up"
129 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
131 # Rename non-indexed merge dir
132 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
133 # Check open, read and readdir from stored file handles
134 # (testdir argument is the mount point and NOT the dir
135 # we are trying to open by stored file handle)
136 test_file_handles $SCRATCH_MNT -rp -i $tmp.merged_file_handles
137 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
138 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
139 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
140 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
141 # (providing the ancestor dir argument pins the ancestor to dcache)
142 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
143 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles