overlay: correct scratch dirs check
[xfstests-dev.git] / tests / overlay / 053
1 #! /bin/bash
2 # FS QA Test No. 053
3 #
4 # Test encode/decode of non-samefs overlay file handles with renames
5 #
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
8 # underlying fs.
9 #
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
14 #
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.
18 #
19 #-----------------------------------------------------------------------
20 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
21 # Author: Amir Goldstein <amir73il@gmail.com>
22 #
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.
26 #
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.
31 #
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 #-----------------------------------------------------------------------
36 #
37
38 seq=`basename $0`
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
41
42 here=`pwd`
43 tmp=/tmp/$$
44 status=1        # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 _cleanup()
48 {
49         cd /
50         rm -f $tmp.*
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
55 }
56
57 # get standard environment, filters and checks
58 . ./common/rc
59 . ./common/filter
60
61 # real QA test starts here
62
63 _supported_fs overlay
64 _supported_os Linux
65 _require_test
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
73
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
80
81 NUMFILES=1
82
83 # Create test dir and empty test files
84 create_test_files()
85 {
86         local dir=$1
87         local opt=$2
88
89         mkdir -p $dir
90         $here/src/open_by_handle -cp $opt $dir $NUMFILES
91 }
92
93 # Test encode/decode file handles on overlay mount
94 test_file_handles()
95 {
96         local dir=$1
97         shift
98
99         echo test_file_handles $dir $* | _filter_scratch | \
100                                 sed -e "s,$tmp\.,,g"
101         $here/src/open_by_handle $* $dir $NUMFILES
102 }
103
104 # Re-create lower/middle/upper/work dirs
105 create_dirs()
106 {
107         # Create lower dir on test partition
108         rm -rf $lower
109         mkdir $lower
110
111         # Create middle/upper/work dirs on scratch partition
112         _scratch_mkfs
113 }
114
115 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
116 # and middle and upper layer on scratch partition
117 mount_dirs()
118 {
119         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
120                                 -o "index=on,nfs_export=on,redirect_dir=on"
121 }
122
123 # Unmount the overlay without unmounting base fs and check the
124 # underlying dirs
125 unmount_dirs()
126 {
127         $UMOUNT_PROG $SCRATCH_MNT
128
129         _overlay_check_scratch_dirs $middle:$lower $upper $work \
130                                 -o "index=on,nfs_export=on,redirect_dir=on"
131 }
132
133 # Check non-stale file handles of lower/upper moved files
134 create_dirs
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
138 mount_dirs
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
155 unmount_dirs
156
157 # Check non-stale file handles of lower/upper renamed dirs
158 create_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
163 mount_dirs
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
184 unmount_dirs
185
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
192 unmount_dirs
193
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
198 # directories.
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
203 unmount_dirs
204
205 status=0
206 exit