xfs/144: Use _qsetup instead of qsetup
[xfstests-dev.git] / tests / overlay / 054
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. 054
6 #
7 # Test encode/decode overlay file handle of dir with non-indexed ancestor
8 #
9 # Overlayfs with nfs_export enabled, indexes all directories on copy up.
10 # Directory index is requires for decoding lower directory file handles
11 # in case ancestors have been renamed.
12 #
13 # When enabling nfs_export on an overlay that already has non-indexed
14 # merge dirs, the possibility of non-indexed ancestor rename requires
15 # special handling when encoding lower directory file handles.
16 #
17 # - Check encode/decode/read file handles of non-indexed merge dir
18 # - Check encode/decode/read file handles of dir with non-indexed parent
19 # - Check encode/decode/read file handles of dir with non-indexed grandparent
20 # - Check decode/read of file handles after rename of non-indexed merge dir
21 # - Check decode/read of file handles after rename of non-indexed parent
22 # - Check decode/read of file handles after rename of non-indexed grandparent
23 #
24 # This test requires and enables overlayfs NFS export support and merge
25 # dir rename support (redirect_dir).
26 # NFS export support depends on and requires overlayfs index feature.
27 #
28 # Regression test for kernel commit 2ca3c148a062 ("ovl: check lower ancestry
29 # on encode of lower dir file handle")
30 #
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         cd /
43         rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49
50 # real QA test starts here
51
52 _supported_fs overlay
53 _require_scratch
54 _require_test_program "open_by_handle"
55 # We need to require all features together, because nfs_export cannot
56 # be enabled when index is disabled
57 _require_scratch_overlay_features index nfs_export redirect_dir
58
59 # All overlay dirs are on scratch partition
60 lower=$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/upper/work dirs
88 create_dirs()
89 {
90         _scratch_mkfs
91 }
92
93 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
94 mount_dirs()
95 {
96         _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
97 }
98
99 # Unmount the overlay without unmounting base fs
100 unmount_dirs()
101 {
102         $UMOUNT_PROG $SCRATCH_MNT
103 }
104
105 # Check encode/decode/read file handles of dir with non-indexed ancestor
106 create_dirs
107 create_test_files $lower/merged -w
108 create_test_files $lower/merged/dir -w
109 create_test_files $lower/merged/dir/subdir -w
110 create_test_files $lower/merged/parent/child -w
111 # Create non-indexed merge dir
112 mkdir $upper/merged
113 mount_dirs
114 # Check encode/decode/read file handles of non-indexed merge dir
115 # This is expected to encode an upper file handle
116 test_file_handles $SCRATCH_MNT/merged -p -o $tmp.merged_file_handles
117 # Check encode/decode/read file handles of dir with non-indexed parent
118 # This is expected to copy up merged/dir and encode an upper file handle
119 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
120 test -d $upper/merged/dir || echo "merged/dir not copied up"
121 # Check encode/decode/read file handles of dir with non-indexed grandparent
122 # This is expected to encode a lower file handle
123 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
124 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
125 # This is expected to copy up parent and encode a lower file handle
126 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
127 test -d $upper/merged/parent || echo "merged/parent not copied up"
128 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
129
130 # Rename non-indexed merge dir
131 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
132 # Check open, read and readdir from stored file handles
133 # (testdir argument is the mount point and NOT the dir
134 #  we are trying to open by stored file handle)
135 test_file_handles $SCRATCH_MNT -rp -i $tmp.merged_file_handles
136 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
137 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
138 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
139 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
140 # (providing the ancestor dir argument pins the ancestor to dcache)
141 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
142 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles
143 unmount_dirs
144
145 status=0
146 exit