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 _begin_fstest auto quick copyup redirect exportfs nonsamefs
25 # Override the default cleanup function.
30 # Cleanup overlay scratch mount that is holding base test mount
31 # to prevent _check_test_fs and _test_umount from failing before
32 # _check_scratch_fs _scratch_umount
33 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
36 # Import common functions.
39 # real QA test starts here
43 _require_test_program "open_by_handle"
44 # Use non-default scratch underlying overlay dirs, we need to check
45 # them explicity after test.
46 _require_scratch_nocheck
47 # We need to require all features together, because nfs_export cannot
48 # be enabled when index is disabled
49 _require_scratch_overlay_features index nfs_export redirect_dir
51 # Lower is on test partition
52 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
53 # Upper/work are on scratch partition
54 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
55 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
56 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
60 # Create test dir and empty test files
67 $here/src/open_by_handle -cp $opt $dir $NUMFILES
70 # Test encode/decode file handles on overlay mount
76 echo test_file_handles $dir $* | _filter_scratch | \
78 $here/src/open_by_handle $* $dir $NUMFILES
81 # Re-create lower/middle/upper/work dirs
84 # Create lower dir on test partition
88 # Create middle/upper/work dirs on scratch partition
92 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
93 # and middle and upper layer on scratch partition
96 _overlay_scratch_mount_dirs $middle:$lower $upper $work \
97 -o "index=on,nfs_export=on,redirect_dir=on"
100 # Unmount the overlay without unmounting base fs and check the
104 $UMOUNT_PROG $SCRATCH_MNT
106 _overlay_check_scratch_dirs $middle:$lower $upper $work \
107 -o "index=on,nfs_export=on,redirect_dir=on"
110 # Check non-stale file handles of lower/upper moved files
112 create_test_files $upper/uppertestdir -w
113 create_test_files $lower/lowertestdir -w
114 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
116 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
117 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
118 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
119 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
120 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
121 # Check open and read from stored file handles
122 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
123 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
124 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
125 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
126 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
127 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
128 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
129 # Check open and read from stored file handles
130 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
131 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
134 # Check non-stale file handles of lower/upper renamed dirs
136 create_test_files $upper/uppertestdir -w
137 create_test_files $lower/lowertestdir -w
138 create_test_files $upper/uppertestdir/subdir -w
139 create_test_files $lower/lowertestdir/subdir -w
141 # Check encode/decode/read of lower/upper file handles after rename of testdir
142 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
143 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
144 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
145 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
146 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
147 # Rename pure upper dir
148 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
149 # Copy up lower dir, index and rename
150 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
151 # Check open, read and readdir from stored file handles
152 # (testdir argument is the mount point and NOT the dir
153 # we are trying to open by stored file handle)
154 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
155 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
156 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
157 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
158 # Retry decoding lower subdir file handle when indexed testdir is in dcache
159 # (providing renamed testdir argument pins the indexed testdir to dcache)
160 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
163 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
164 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
165 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
166 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
167 test_file_handles $SCRATCH_MNT/lowertestdir -rp
168 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
171 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
172 # with non-indexed redirects from top lower layer to bottom lower layer.
173 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
174 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
176 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
177 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
178 test_file_handles $SCRATCH_MNT -r
179 test_file_handles $SCRATCH_MNT/subdir -rp