xfs: force file creation to the data device for certain layout tests
[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 _require_scratch
41 _require_test_program "open_by_handle"
42 # We need to require all features together, because nfs_export cannot
43 # be enabled when index is disabled
44 _require_scratch_overlay_features index nfs_export redirect_dir
45
46 # All overlay dirs are on scratch partition
47 lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
48 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.2
49 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
50 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
51
52 NUMFILES=1
53
54 # Create test dir and empty test files
55 create_test_files()
56 {
57         local dir=$1
58         local opt=$2
59
60         mkdir -p $dir
61         $here/src/open_by_handle -cp $opt $dir $NUMFILES
62 }
63
64 # Test encode/decode file handles on overlay mount
65 test_file_handles()
66 {
67         local dir=$1
68         shift
69
70         echo test_file_handles $dir $* | _filter_scratch | \
71                                 sed -e "s,$tmp\.,,g"
72         $here/src/open_by_handle $* $dir $NUMFILES
73 }
74
75 # Re-create lower/middle/upper/work dirs
76 create_dirs()
77 {
78         _scratch_mkfs
79         mkdir -p $middle
80 }
81
82 # Mount an overlay on $SCRATCH_MNT with all layers on scratch partition
83 mount_dirs()
84 {
85         _scratch_mount -o "index=on,nfs_export=on,redirect_dir=on"
86 }
87
88 # Unmount the overlay without unmounting base fs
89 unmount_dirs()
90 {
91         $UMOUNT_PROG $SCRATCH_MNT
92 }
93
94 # Check non-stale file handles of lower/upper moved files
95 create_dirs
96 create_test_files $upper/uppertestdir -w
97 create_test_files $lower/lowertestdir -w
98 mkdir -p $lower/lowertestdir.lo $lower/lowertestdir.up $upper/uppertestdir.lo $upper/uppertestdir.up
99 mount_dirs
100 # Check encode/decode/read of lower/upper file handles after move to new upper testdir
101 test_file_handles $SCRATCH_MNT/uppertestdir -o $tmp.upper_file_handles
102 test_file_handles $SCRATCH_MNT/lowertestdir -o $tmp.lower_file_handles
103 mv $SCRATCH_MNT/uppertestdir/* $SCRATCH_MNT/uppertestdir.up/
104 mv $SCRATCH_MNT/lowertestdir/* $SCRATCH_MNT/uppertestdir.lo/
105 # Check open and read from stored file handles
106 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
107 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
108 # Check encode/decode/read of lower/upper file handles after move to new merge testdir
109 test_file_handles $SCRATCH_MNT/uppertestdir.up -o $tmp.upper_file_handles
110 test_file_handles $SCRATCH_MNT/uppertestdir.lo -o $tmp.lower_file_handles
111 mv $SCRATCH_MNT/uppertestdir.up/* $SCRATCH_MNT/lowertestdir.up/
112 mv $SCRATCH_MNT/uppertestdir.lo/* $SCRATCH_MNT/lowertestdir.lo/
113 # Check open and read from stored file handles
114 test_file_handles $SCRATCH_MNT -r -i $tmp.upper_file_handles
115 test_file_handles $SCRATCH_MNT -r -i $tmp.lower_file_handles
116 unmount_dirs
117
118 # Check non-stale file handles of lower/upper renamed dirs
119 create_dirs
120 create_test_files $upper/uppertestdir -w
121 create_test_files $lower/lowertestdir -w
122 create_test_files $upper/uppertestdir/subdir -w
123 create_test_files $lower/lowertestdir/subdir -w
124 mount_dirs
125 # Check encode/decode/read of lower/upper file handles after rename of testdir
126 test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles
127 test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles
128 # Check encode/decode/read of lower/upper file handles after rename of testdir's parent
129 test_file_handles $SCRATCH_MNT/uppertestdir/subdir -p -o $tmp.upper_subdir_file_handles
130 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -p -o $tmp.lower_subdir_file_handles
131 # Rename pure upper dir
132 mv $SCRATCH_MNT/uppertestdir $SCRATCH_MNT/uppertestdir.new/
133 # Copy up lower dir, index and rename
134 mv $SCRATCH_MNT/lowertestdir $SCRATCH_MNT/lowertestdir.new/
135 # Check open, read and readdir from stored file handles
136 # (testdir argument is the mount point and NOT the dir
137 #  we are trying to open by stored file handle)
138 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_file_handles
139 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_file_handles
140 test_file_handles $SCRATCH_MNT -rp -i $tmp.upper_subdir_file_handles
141 test_file_handles $SCRATCH_MNT -rp -i $tmp.lower_subdir_file_handles
142 # Retry decoding lower subdir file handle when indexed testdir is in dcache
143 # (providing renamed testdir argument pins the indexed testdir to dcache)
144 test_file_handles $SCRATCH_MNT/lowertestdir.new -rp -i $tmp.lower_subdir_file_handles
145 unmount_dirs
146
147 # Check encode/decode/read of lower file handles on lower layers only r/o overlay.
148 # For non-upper overlay mount, nfs_export requires disabling redirect_dir.
149 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
150                         -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$middle:$lower
151 test_file_handles $SCRATCH_MNT/lowertestdir -rp
152 test_file_handles $SCRATCH_MNT/lowertestdir/subdir -rp
153 unmount_dirs
154
155 # Check encode/decode/read of lower file handles on lower layers only r/o overlay
156 # with non-indexed redirects from top lower layer to bottom lower layer.
157 # Overlay lookup cannot follow the redirect from $upper/lowertestdir.new to
158 # $lower/lowertestdir. Instead, we mount an overlay subtree rooted at these
159 # directories.
160 $MOUNT_PROG -t overlay $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT \
161                 -o ro,redirect_dir=nofollow,nfs_export=on,lowerdir=$upper/lowertestdir.new:$lower/lowertestdir
162 test_file_handles $SCRATCH_MNT -r
163 test_file_handles $SCRATCH_MNT/subdir -rp
164 unmount_dirs
165
166 status=0
167 exit