common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / overlay / 055
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. 055
6 #
7 # Test overlay file handle of dir with ancestor under lower redirect
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 has merge dirs with lower
14 # layer redirects, the possibility of ancestor rename requires special
15 # handling when encoding lower directory file handles from layer > 1.
16 #
17 # - Check decode of lower dir with parent under lower redirect
18 # - Check decode of lower dir with grandparent under lower redirect
19 # - Check decode of lower dir after rename of lower redirected parent
20 # - Check decode of lower dir after rename of lower redirected grandparent
21 #
22 # This test requires and enables overlayfs NFS export support and merge
23 # dir rename support (redirect_dir).
24 # NFS export support depends on and requires overlayfs index feature.
25 #
26 # Regression test for kernel commit 2ca3c148a062 ("ovl: check lower ancestry
27 # on encode of lower dir file handle")
28 #
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         cd /
41         rm -f $tmp.*
42         # Cleanup overlay scratch mount that is holding base test mount
43         # to prevent _check_test_fs and _test_umount from failing before
44         # _check_scratch_fs _scratch_umount
45         $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53
54 _supported_fs overlay
55 _require_test
56 _require_test_program "open_by_handle"
57 # Use non-default scratch underlying overlay dirs, we need to check
58 # them explicity after test.
59 _require_scratch_nocheck
60 # We need to require all features together, because nfs_export cannot
61 # be enabled when index is disabled
62 _require_scratch_overlay_features index nfs_export redirect_dir
63
64 # Lower is on test partition
65 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
66 # Upper/work are on scratch partition
67 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
68 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
69 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
70
71 NUMFILES=1
72
73 # Create test dir and empty test files
74 create_test_files()
75 {
76         local dir=$1
77         local opt=$2
78
79         mkdir -p $dir
80         $here/src/open_by_handle -cp $opt $dir $NUMFILES
81 }
82
83 # Test encode/decode file handles on overlay mount
84 test_file_handles()
85 {
86         local dir=$1
87         shift
88
89         echo test_file_handles $dir $* | _filter_scratch | \
90                                 sed -e "s,$tmp\.,,g"
91         $here/src/open_by_handle $* $dir $NUMFILES
92 }
93
94 # Re-create lower/middle/upper/work dirs
95 create_dirs()
96 {
97         # Create lower dir on test partition
98         rm -rf $lower
99         mkdir $lower
100
101         # Create middle/upper/work dirs on scratch partition
102         _scratch_mkfs
103 }
104
105 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
106 # and middle and upper layer on scratch partition
107 mount_dirs()
108 {
109         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
110                                 -o "index=on,nfs_export=on,redirect_dir=on"
111 }
112
113 # Unmount the overlay without unmounting base fs and check the
114 # underlying dirs
115 unmount_dirs()
116 {
117         $UMOUNT_PROG $SCRATCH_MNT
118
119         _overlay_check_scratch_dirs $middle:$lower $upper $work \
120                                 -o "index=on,nfs_export=on,redirect_dir=on"
121 }
122
123 # Check file handles of dir with ancestor under lower redirect
124 create_dirs
125 create_test_files $lower/origin -w
126 create_test_files $lower/origin/dir -w
127 create_test_files $lower/origin/dir/subdir -w
128 create_test_files $lower/origin/parent/child -w
129 # Create lower redirected merge dir
130 mkdir $middle/merged
131 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
132 mount_dirs
133 # Check encode/decode/read of lower dir with parent under lower redirect
134 # This is expected to copy up merged/dir and encode an upper file handle
135 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
136 test -d $upper/merged/dir || echo "merged/dir not copied up"
137 # Check encode/decode/read of lower dir with grandparent under lower redirect
138 # This is expected to encode a lower file handle
139 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
140 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
141 # This is expected to copy up parent and encode a lower file handle
142 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
143 test -d $upper/merged/parent || echo "merged/parent not copied up"
144 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
145
146 # Rename lower redirected merge dir
147 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
148 # Check open, read and readdir from stored file handles
149 # (testdir argument is the mount point and NOT the dir
150 #  we are trying to open by stored file handle)
151 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
152 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
153 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
154 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
155 # (providing the ancestor dir argument pins the ancestor to dcache)
156 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
157 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
158 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles
159 unmount_dirs
160
161 status=0
162 exit