fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / overlay / 054
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 054
6 #
7 # Test encode/decode overlay file handle of dir with non-indexed ancestor
8 #
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.
12 #
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.
16 #
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
23 #
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.
27 #
28 # Regression test for kernel commit 2ca3c148a062 ("ovl: check lower ancestry
29 # on encode of lower dir file handle")
30 #
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         cd /
43         rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49
50 # real QA test starts here
51
52 _supported_fs overlay
53 _supported_os Linux
54 _require_scratch
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
59
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
64
65 NUMFILES=1
66
67 # Create test dir and empty test files
68 create_test_files()
69 {
70         local dir=$1
71         local opt=$2
72
73         mkdir -p $dir
74         $here/src/open_by_handle -cp $opt $dir $NUMFILES
75 }
76
77 # Test encode/decode file handles on overlay mount
78 test_file_handles()
79 {
80         local dir=$1
81         shift
82
83         echo test_file_handles $dir $* | _filter_scratch | \
84                                 sed -e "s,$tmp\.,,g"
85         $here/src/open_by_handle $* $dir $NUMFILES
86 }
87
88 # Re-create lower/upper/work dirs
89 create_dirs()
90 {
91         _scratch_mkfs
92 }
93
94 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
95 mount_dirs()
96 {
97         _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
98 }
99
100 # Unmount the overlay without unmounting base fs
101 unmount_dirs()
102 {
103         $UMOUNT_PROG $SCRATCH_MNT
104 }
105
106 # Check encode/decode/read file handles of dir with non-indexed ancestor
107 create_dirs
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
113 mkdir $upper/merged
114 mount_dirs
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"
130
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
144 unmount_dirs
145
146 status=0
147 exit