common: kill _supported_os
[xfstests-dev.git] / tests / overlay / 053
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 053
6 #
7 # Test encode/decode of non-samefs overlay file handles with renames
8 #
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
11 # underlying fs.
12 #
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
17 #
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.
21 #
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 here=`pwd`
27 tmp=/tmp/$$
28 status=1        # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33         cd /
34         rm -f $tmp.*
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
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46
47 _supported_fs overlay
48 _require_test
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
56
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
63
64 NUMFILES=1
65
66 # Create test dir and empty test files
67 create_test_files()
68 {
69         local dir=$1
70         local opt=$2
71
72         mkdir -p $dir
73         $here/src/open_by_handle -cp $opt $dir $NUMFILES
74 }
75
76 # Test encode/decode file handles on overlay mount
77 test_file_handles()
78 {
79         local dir=$1
80         shift
81
82         echo test_file_handles $dir $* | _filter_scratch | \
83                                 sed -e "s,$tmp\.,,g"
84         $here/src/open_by_handle $* $dir $NUMFILES
85 }
86
87 # Re-create lower/middle/upper/work dirs
88 create_dirs()
89 {
90         # Create lower dir on test partition
91         rm -rf $lower
92         mkdir $lower
93
94         # Create middle/upper/work dirs on scratch partition
95         _scratch_mkfs
96 }
97
98 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
99 # and middle and upper layer on scratch partition
100 mount_dirs()
101 {
102         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
103                                 -o "index=on,nfs_export=on,redirect_dir=on"
104 }
105
106 # Unmount the overlay without unmounting base fs and check the
107 # underlying dirs
108 unmount_dirs()
109 {
110         $UMOUNT_PROG $SCRATCH_MNT
111
112         _overlay_check_scratch_dirs $middle:$lower $upper $work \
113                                 -o "index=on,nfs_export=on,redirect_dir=on"
114 }
115
116 # Check non-stale file handles of lower/upper moved files
117 create_dirs
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
121 mount_dirs
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
138 unmount_dirs
139
140 # Check non-stale file handles of lower/upper renamed dirs
141 create_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
146 mount_dirs
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
167 unmount_dirs
168
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
175 unmount_dirs
176
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
181 # directories.
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
186 unmount_dirs
187
188 status=0
189 exit