2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 CTERA Networks. All Rights Reserved.
7 # Test encode/decode overlay file handles with renames
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
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.
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
24 status=1 # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
37 # real QA test starts here
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
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
55 # Create test dir and empty test files
62 $here/src/open_by_handle -cp $opt $dir $NUMFILES
65 # Test encode/decode file handles on overlay mount
71 echo test_file_handles $dir $* | _filter_scratch | \
73 $here/src/open_by_handle $* $dir $NUMFILES
76 # Re-create lower/middle/upper/work dirs
83 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
86 _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
89 # Unmount the overlay without unmounting base fs
92 $UMOUNT_PROG $SCRATCH_MNT
95 # Check non-stale file handles of lower/upper moved files
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
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
119 # Check non-stale file handles of lower/upper renamed 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
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
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
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
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