4 # Test encode/decode of non-samefs overlay file handles with renames
6 # This is a variant of overlay file handles with renames test for an
7 # overlayfs that is composed of multiple lower layers not on the same
10 # - Check decode/read of file handles after rename of parent
11 # - Check decode/read of file handles after rename of grandparent
12 # - Check decode/read of file handles after move to new parent
13 # - Check encode/decode/read of file handles in non-upper overlay
15 # This test requires and enables overlayfs NFS export support and merge
16 # dir rename support (redirect_dir).
17 # NFS export support depends on and requires overlayfs index feature.
19 #-----------------------------------------------------------------------
20 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
21 # Author: Amir Goldstein <amir73il@gmail.com>
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License as
25 # published by the Free Software Foundation.
27 # This program is distributed in the hope that it would be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write the Free Software Foundation,
34 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #-----------------------------------------------------------------------
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
44 status=1 # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # Cleanup overlay scratch mount that is holding base test mount
52 # to prevent _check_test_fs and _test_umount from failing before
53 # _check_scratch_fs _scratch_umount
54 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
57 # get standard environment, filters and checks
61 # real QA test starts here
66 _require_test_program "open_by_handle"
67 # Use non-default scratch underlying overlay dirs, we need to check
68 # them explicity after test.
69 _require_scratch_nocheck
70 # We need to require all features together, because nfs_export cannot
71 # be enabled when index is disabled
72 _require_scratch_overlay_features index nfs_export redirect_dir
74 # Lower is on test partition
75 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
76 # Upper/work are on scratch partition
77 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
78 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
79 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
83 # Create test dir and empty test files
90 $here/src/open_by_handle -cp $opt $dir $NUMFILES
93 # Test encode/decode file handles on overlay mount
99 echo test_file_handles $dir $* | _filter_scratch | \
101 $here/src/open_by_handle $* $dir $NUMFILES
104 # Re-create lower/middle/upper/work dirs
107 # Create lower dir on test partition
111 # Create middle/upper/work dirs on scratch partition
115 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
116 # and middle and upper layer on scratch partition
119 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
120 -o "index=on,nfs_export=on,redirect_dir=on"
123 # Unmount the overlay without unmounting base fs and check the
127 $UMOUNT_PROG $SCRATCH_MNT
129 _overlay_check_scratch_dirs $middle:$lower $upper $work \
130 -o "index=on,nfs_export=on,redirect_dir=on"
133 # Check non-stale file handles of lower/upper moved files
135 create_test_files $upper/uppertestdir -w
136 create_test_files $lower/lowertestdir -w
137 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
139 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
140 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
141 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
142 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
143 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
144 # Check open and read from stored file handles
145 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
146 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
147 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
148 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
149 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
150 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
151 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
152 # Check open and read from stored file handles
153 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
154 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
157 # Check non-stale file handles of lower/upper renamed dirs
159 create_test_files $upper/uppertestdir -w
160 create_test_files $lower/lowertestdir -w
161 create_test_files $upper/uppertestdir/subdir -w
162 create_test_files $lower/lowertestdir/subdir -w
164 # Check encode/decode/read of lower/upper file handles after rename of testdir
165 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
166 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
167 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
168 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
169 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
170 # Rename pure upper dir
171 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
172 # Copy up lower dir, index and rename
173 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
174 # Check open, read and readdir from stored file handles
175 # (testdir argument is the mount point and NOT the dir
176 # we are trying to open by stored file handle)
177 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
178 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
179 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
180 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
181 # Retry decoding lower subdir file handle when indexed testdir is in dcache
182 # (providing renamed testdir argument pins the indexed testdir to dcache)
183 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
186 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
187 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
188 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
189 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
190 test_file_handles $SCRATCH_MNT/lowertestdir -rp
191 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
194 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
195 # with non-indexed redirects from top lower layer to bottom lower layer.
196 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
197 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
199 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
200 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
201 test_file_handles $SCRATCH_MNT -r
202 test_file_handles $SCRATCH_MNT/subdir -rp