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
54 _require_test_program "open_by_handle"
55 # We need to require all features together, because nfs_export cannot
56 # be enabled when index is disabled
57 _require_scratch_overlay_features index nfs_export redirect_dir
59 # All overlay dirs are on scratch partition
60 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
61 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
62 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
66 # Create test dir and empty test files
73 $here/src/open_by_handle -cp $opt $dir $NUMFILES
76 # Test encode/decode file handles on overlay mount
82 echo test_file_handles $dir $* | _filter_scratch | \
84 $here/src/open_by_handle $* $dir $NUMFILES
87 # Re-create lower/upper/work dirs
93 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
96 _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
99 # Unmount the overlay without unmounting base fs
102 $UMOUNT_PROG $SCRATCH_MNT
105 # Check encode/decode/read file handles of dir with non-indexed ancestor
107 create_test_files $lower/merged -w
108 create_test_files $lower/merged/dir -w
109 create_test_files $lower/merged/dir/subdir -w
110 create_test_files $lower/merged/parent/child -w
111 # Create non-indexed merge dir
114 # Check encode/decode/read file handles of non-indexed merge dir
115 # This is expected to encode an upper file handle
116 test_file_handles $SCRATCH_MNT/merged -p -o $tmp.merged_file_handles
117 # Check encode/decode/read file handles of dir with non-indexed parent
118 # This is expected to copy up merged/dir and encode an upper file handle
119 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
120 test -d $upper/merged/dir || echo "merged/dir not copied up"
121 # Check encode/decode/read file handles of dir with non-indexed grandparent
122 # This is expected to encode a lower file handle
123 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
124 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
125 # This is expected to copy up parent and encode a lower file handle
126 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
127 test -d $upper/merged/parent || echo "merged/parent not copied up"
128 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
130 # Rename non-indexed merge dir
131 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
132 # Check open, read and readdir from stored file handles
133 # (testdir argument is the mount point and NOT the dir
134 # we are trying to open by stored file handle)
135 test_file_handles $SCRATCH_MNT -rp -i $tmp.merged_file_handles
136 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
137 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
138 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
139 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
140 # (providing the ancestor dir argument pins the ancestor to dcache)
141 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
142 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles