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
67 _require_test_program "open_by_handle"
68 # We need to require all features together, because nfs_export cannot
69 # be enabled when index is disabled
70 _require_scratch_overlay_features index nfs_export redirect_dir
72 # Lower is on test partition
73 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
74 # Upper/work are on scratch partition
75 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
76 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
77 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
81 # Create test dir and empty test files
88 $here/src/open_by_handle -cp $opt $dir $NUMFILES
91 # Test encode/decode file handles on overlay mount
97 echo test_file_handles $dir $* | _filter_scratch | \
99 $here/src/open_by_handle $* $dir $NUMFILES
102 # Re-create lower/middle/upper/work dirs
105 # Create lower dir on test partition
109 # Create middle/upper/work dirs on scratch partition
113 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
114 # and middle and upper layer on scratch partition
117 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
118 -o "index=on,nfs_export=on,redirect_dir=on"
121 # Unmount the overlay without unmounting base fs
124 $UMOUNT_PROG $SCRATCH_MNT
127 # Check non-stale file handles of lower/upper moved files
129 create_test_files $upper/uppertestdir -w
130 create_test_files $lower/lowertestdir -w
131 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
133 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
134 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
135 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
136 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
137 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
138 # Check open and read from stored file handles
139 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
140 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
141 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
142 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
143 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
144 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
145 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
146 # Check open and read from stored file handles
147 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
148 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
151 # Check non-stale file handles of lower/upper renamed dirs
153 create_test_files $upper/uppertestdir -w
154 create_test_files $lower/lowertestdir -w
155 create_test_files $upper/uppertestdir/subdir -w
156 create_test_files $lower/lowertestdir/subdir -w
158 # Check encode/decode/read of lower/upper file handles after rename of testdir
159 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
160 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
161 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
162 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
163 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
164 # Rename pure upper dir
165 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
166 # Copy up lower dir, index and rename
167 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
168 # Check open, read and readdir from stored file handles
169 # (testdir argument is the mount point and NOT the dir
170 # we are trying to open by stored file handle)
171 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
172 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
173 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
174 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
175 # Retry decoding lower subdir file handle when indexed testdir is in dcache
176 # (providing renamed testdir argument pins the indexed testdir to dcache)
177 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
180 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
181 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
182 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
183 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
184 test_file_handles $SCRATCH_MNT/lowertestdir -rp
185 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
188 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
189 # with non-indexed redirects from top lower layer to bottom lower layer.
190 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
191 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
193 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
194 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
195 test_file_handles $SCRATCH_MNT -r
196 test_file_handles $SCRATCH_MNT/subdir -rp