overlay: test overlay file handles of lower dir with non-indexed ancestor
[xfstests-dev.git] / tests / overlay / 054
1 #! /bin/bash
2 # FS QA Test No. 054
3 #
4 # Test encode/decode overlay file handle of dir with non-indexed ancestor
5 #
6 # Overlayfs with nfs_export enabled, indexes all directories on copy up.
7 # Directory index is requires for decoding lower directory file handles
8 # in case ancestors have been renamed.
9 #
10 # When enabling nfs_export on an overlay that already has non-indexed
11 # merge dirs, the possibility of non-indexed ancestor rename requires
12 # special handling when encoding lower directory file handles.
13 #
14 # - Check encode/decode/read file handles of non-indexed merge dir
15 # - Check encode/decode/read file handles of dir with non-indexed parent
16 # - Check encode/decode/read file handles of dir with non-indexed grandparent
17 # - Check decode/read of file handles after rename of non-indexed merge dir
18 # - Check decode/read of file handles after rename of non-indexed parent
19 # - Check decode/read of file handles after rename of non-indexed grandparent
20 #
21 # This test requires and enables overlayfs NFS export support and merge
22 # dir rename support (redirect_dir).
23 # NFS export support depends on and requires overlayfs index feature.
24 #
25 #-----------------------------------------------------------------------
26 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
27 # Author: Amir Goldstein <amir73il@gmail.com>
28 #
29 # This program is free software; you can redistribute it and/or
30 # modify it under the terms of the GNU General Public License as
31 # published by the Free Software Foundation.
32 #
33 # This program is distributed in the hope that it would be useful,
34 # but WITHOUT ANY WARRANTY; without even the implied warranty of
35 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36 # GNU General Public License for more details.
37 #
38 # You should have received a copy of the GNU General Public License
39 # along with this program; if not, write the Free Software Foundation,
40 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
41 #-----------------------------------------------------------------------
42 #
43
44 seq=`basename $0`
45 seqres=$RESULT_DIR/$seq
46 echo "QA output created by $seq"
47
48 here=`pwd`
49 tmp=/tmp/$$
50 status=1        # failure is the default!
51 trap "_cleanup; exit \$status" 0 1 2 3 15
52
53 _cleanup()
54 {
55         cd /
56         rm -f $tmp.*
57 }
58
59 # get standard environment, filters and checks
60 . ./common/rc
61 . ./common/filter
62
63 # real QA test starts here
64
65 _supported_fs overlay
66 _supported_os Linux
67 _require_scratch
68 _require_test_program "open_by_handle"
69 # We need to require all features together, because nfs_export cannot
70 # be enabled when index is disabled
71 _require_scratch_overlay_features index nfs_export redirect_dir
72
73 # All overlay dirs are on scratch partition
74 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
75 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
76 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
77
78 NUMFILES=1
79
80 # Create test dir and empty test files
81 create_test_files()
82 {
83         local dir=$1
84         local opt=$2
85
86         mkdir -p $dir
87         $here/src/open_by_handle -cp $opt $dir $NUMFILES
88 }
89
90 # Test encode/decode file handles on overlay mount
91 test_file_handles()
92 {
93         local dir=$1
94         shift
95
96         echo test_file_handles $dir $* | _filter_scratch | \
97                                 sed -e "s,$tmp\.,,g"
98         $here/src/open_by_handle $* $dir $NUMFILES
99 }
100
101 # Re-create lower/upper/work dirs
102 create_dirs()
103 {
104         _scratch_mkfs
105 }
106
107 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
108 mount_dirs()
109 {
110         _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
111 }
112
113 # Unmount the overlay without unmounting base fs
114 unmount_dirs()
115 {
116         $UMOUNT_PROG $SCRATCH_MNT
117 }
118
119 # Check encode/decode/read file handles of dir with non-indexed ancestor
120 create_dirs
121 create_test_files $lower/merged -w
122 create_test_files $lower/merged/dir -w
123 create_test_files $lower/merged/dir/subdir -w
124 create_test_files $lower/merged/parent/child -w
125 # Create non-indexed merge dir
126 mkdir $upper/merged
127 mount_dirs
128 # Check encode/decode/read file handles of non-indexed merge dir
129 # This is expected to encode an upper file handle
130 test_file_handles $SCRATCH_MNT/merged -p -o $tmp.merged_file_handles
131 # Check encode/decode/read file handles of dir with non-indexed parent
132 # This is expected to copy up merged/dir and encode an upper file handle
133 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
134 test -d $upper/merged/dir || echo "merged/dir not copied up"
135 # Check encode/decode/read file handles of dir with non-indexed grandparent
136 # This is expected to encode a lower file handle
137 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
138 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
139 # This is expected to copy up parent and encode a lower file handle
140 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
141 test -d $upper/merged/parent || echo "merged/parent not copied up"
142 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
143
144 # Rename non-indexed merge dir
145 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
146 # Check open, read and readdir from stored file handles
147 # (testdir argument is the mount point and NOT the dir
148 #  we are trying to open by stored file handle)
149 test_file_handles $SCRATCH_MNT -rp -i $tmp.merged_file_handles
150 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
151 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
152 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
153 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
154 # (providing the ancestor dir argument pins the ancestor to dcache)
155 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
156 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles
157 unmount_dirs
158
159 status=0
160 exit