2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test encode/decode of non-samefs overlay file handles with renames
9 # This is a variant of overlay file handles with renames test for an
10 # overlayfs that is composed of multiple lower layers not on the same
13 # - Check decode/read of file handles after rename of parent
14 # - Check decode/read of file handles after rename of grandparent
15 # - Check decode/read of file handles after move to new parent
16 # - Check encode/decode/read of file handles in non-upper overlay
18 # This test requires and enables overlayfs NFS export support and merge
19 # dir rename support (redirect_dir).
20 # NFS export support depends on and requires overlayfs index feature.
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # Cleanup overlay scratch mount that is holding base test mount
36 # to prevent _check_test_fs and _test_umount from failing before
37 # _check_scratch_fs _scratch_umount
38 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
41 # get standard environment, filters and checks
45 # real QA test starts here
49 _require_test_program "open_by_handle"
50 # Use non-default scratch underlying overlay dirs, we need to check
51 # them explicity after test.
52 _require_scratch_nocheck
53 # We need to require all features together, because nfs_export cannot
54 # be enabled when index is disabled
55 _require_scratch_overlay_features index nfs_export redirect_dir
57 # Lower is on test partition
58 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
59 # Upper/work are on scratch partition
60 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
61 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
62 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
66 # Create test dir and empty test files
73 $here/src/open_by_handle -cp $opt $dir $NUMFILES
76 # Test encode/decode file handles on overlay mount
82 echo test_file_handles $dir $* | _filter_scratch | \
84 $here/src/open_by_handle $* $dir $NUMFILES
87 # Re-create lower/middle/upper/work dirs
90 # Create lower dir on test partition
94 # Create middle/upper/work dirs on scratch partition
98 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
99 # and middle and upper layer on scratch partition
102 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
103 -o "index=on,nfs_export=on,redirect_dir=on"
106 # Unmount the overlay without unmounting base fs and check the
110 $UMOUNT_PROG $SCRATCH_MNT
112 _overlay_check_scratch_dirs $middle:$lower $upper $work \
113 -o "index=on,nfs_export=on,redirect_dir=on"
116 # Check non-stale file handles of lower/upper moved files
118 create_test_files $upper/uppertestdir -w
119 create_test_files $lower/lowertestdir -w
120 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
122 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
123 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
124 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
125 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
126 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
127 # Check open and read from stored file handles
128 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
129 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
130 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
131 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
132 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
133 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
134 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
135 # Check open and read from stored file handles
136 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
137 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
140 # Check non-stale file handles of lower/upper renamed dirs
142 create_test_files $upper/uppertestdir -w
143 create_test_files $lower/lowertestdir -w
144 create_test_files $upper/uppertestdir/subdir -w
145 create_test_files $lower/lowertestdir/subdir -w
147 # Check encode/decode/read of lower/upper file handles after rename of testdir
148 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
149 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
150 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
151 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
152 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
153 # Rename pure upper dir
154 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
155 # Copy up lower dir, index and rename
156 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
157 # Check open, read and readdir from stored file handles
158 # (testdir argument is the mount point and NOT the dir
159 # we are trying to open by stored file handle)
160 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
161 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
162 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
163 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
164 # Retry decoding lower subdir file handle when indexed testdir is in dcache
165 # (providing renamed testdir argument pins the indexed testdir to dcache)
166 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
169 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
170 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
171 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
172 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
173 test_file_handles $SCRATCH_MNT/lowertestdir -rp
174 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
177 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
178 # with non-indexed redirects from top lower layer to bottom lower layer.
179 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
180 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
182 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
183 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
184 test_file_handles $SCRATCH_MNT -r
185 test_file_handles $SCRATCH_MNT/subdir -rp