overlay/029: fix test failure with nfs_export feature enabled
[xfstests-dev.git] / tests / overlay / 052
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. 052
6 #
7 # Test encode/decode overlay file handles with renames
8 #
9 # - Check decode/read of file handles after rename of parent
10 # - Check decode/read of file handles after rename of grandparent
11 # - Check decode/read of file handles after move to new parent
12 # - Check encode/decode/read of file handles in non-upper overlay
13 #
14 # This test requires and enables overlayfs NFS export support and merge
15 # dir rename support (redirect_dir).
16 # NFS export support depends on and requires overlayfs index feature.
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 tmp=/tmp/$$
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
29         cd /
30         rm -f $tmp.*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 # real QA test starts here
38
39 _supported_fs overlay
40 _supported_os Linux
41 _require_scratch
42 _require_test_program "open_by_handle"
43 # We need to require all features together, because nfs_export cannot
44 # be enabled when index is disabled
45 _require_scratch_overlay_features index nfs_export redirect_dir
46
47 # All overlay dirs are on scratch partition
48 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
49 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.2
50 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
51 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
52
53 NUMFILES=1
54
55 # Create test dir and empty test files
56 create_test_files()
57 {
58         local dir=$1
59         local opt=$2
60
61         mkdir -p $dir
62         $here/src/open_by_handle -cp $opt $dir $NUMFILES
63 }
64
65 # Test encode/decode file handles on overlay mount
66 test_file_handles()
67 {
68         local dir=$1
69         shift
70
71         echo test_file_handles $dir $* | _filter_scratch | \
72                                 sed -e "s,$tmp\.,,g"
73         $here/src/open_by_handle $* $dir $NUMFILES
74 }
75
76 # Re-create lower/middle/upper/work dirs
77 create_dirs()
78 {
79         _scratch_mkfs
80         mkdir -p $middle
81 }
82
83 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
84 mount_dirs()
85 {
86         _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
87 }
88
89 # Unmount the overlay without unmounting base fs
90 unmount_dirs()
91 {
92         $UMOUNT_PROG $SCRATCH_MNT
93 }
94
95 # Check non-stale file handles of lower/upper moved files
96 create_dirs
97 create_test_files $upper/uppertestdir -w
98 create_test_files $lower/lowertestdir -w
99 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
100 mount_dirs
101 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
102 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
103 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
104 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
105 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
106 # Check open and read from stored file handles
107 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
108 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
109 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
110 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
111 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
112 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
113 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
114 # Check open and read from stored file handles
115 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
116 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
117 unmount_dirs
118
119 # Check non-stale file handles of lower/upper renamed dirs
120 create_dirs
121 create_test_files $upper/uppertestdir -w
122 create_test_files $lower/lowertestdir -w
123 create_test_files $upper/uppertestdir/subdir -w
124 create_test_files $lower/lowertestdir/subdir -w
125 mount_dirs
126 # Check encode/decode/read of lower/upper file handles after rename of testdir
127 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
128 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
129 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
130 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
131 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
132 # Rename pure upper dir
133 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
134 # Copy up lower dir, index and rename
135 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
136 # Check open, read and readdir from stored file handles
137 # (testdir argument is the mount point and NOT the dir
138 #  we are trying to open by stored file handle)
139 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
140 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
141 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
142 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
143 # Retry decoding lower subdir file handle when indexed testdir is in dcache
144 # (providing renamed testdir argument pins the indexed testdir to dcache)
145 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
146 unmount_dirs
147
148 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
149 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
150 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
151                         -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
152 test_file_handles $SCRATCH_MNT/lowertestdir -rp
153 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
154 unmount_dirs
155
156 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
157 # with non-indexed redirects from top lower layer to bottom lower layer.
158 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
159 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
160 # directories.
161 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
162                 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
163 test_file_handles $SCRATCH_MNT -r
164 test_file_handles $SCRATCH_MNT/subdir -rp
165 unmount_dirs
166
167 status=0
168 exit