overlay: run unionmount testsuite test cases
[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 _supported_os Linux
56 _require_test
57 _require_test_program "open_by_handle"
58 # Use non-default scratch underlying overlay dirs, we need to check
59 # them explicity after test.
60 _require_scratch_nocheck
61 # We need to require all features together, because nfs_export cannot
62 # be enabled when index is disabled
63 _require_scratch_overlay_features index nfs_export redirect_dir
64
65 # Lower is on test partition
66 lower=$OVL_BASE_TEST_DIR/$OVL_LOWER-$seq
67 # Upper/work are on scratch partition
68 middle=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
69 upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
70 work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
71
72 NUMFILES=1
73
74 # Create test dir and empty test files
75 create_test_files()
76 {
77         local dir=$1
78         local opt=$2
79
80         mkdir -p $dir
81         $here/src/open_by_handle -cp $opt $dir $NUMFILES
82 }
83
84 # Test encode/decode file handles on overlay mount
85 test_file_handles()
86 {
87         local dir=$1
88         shift
89
90         echo test_file_handles $dir $* | _filter_scratch | \
91                                 sed -e "s,$tmp\.,,g"
92         $here/src/open_by_handle $* $dir $NUMFILES
93 }
94
95 # Re-create lower/middle/upper/work dirs
96 create_dirs()
97 {
98         # Create lower dir on test partition
99         rm -rf $lower
100         mkdir $lower
101
102         # Create middle/upper/work dirs on scratch partition
103         _scratch_mkfs
104 }
105
106 # Mount an overlay on $SCRATCH_MNT with lower layer on test partition
107 # and middle and upper layer on scratch partition
108 mount_dirs()
109 {
110         _overlay_scratch_mount_dirs $middle:$lower $upper $work \
111                                 -o "index=on,nfs_export=on,redirect_dir=on"
112 }
113
114 # Unmount the overlay without unmounting base fs and check the
115 # underlying dirs
116 unmount_dirs()
117 {
118         $UMOUNT_PROG $SCRATCH_MNT
119
120         _overlay_check_scratch_dirs $middle:$lower $upper $work \
121                                 -o "index=on,nfs_export=on,redirect_dir=on"
122 }
123
124 # Check file handles of dir with ancestor under lower redirect
125 create_dirs
126 create_test_files $lower/origin -w
127 create_test_files $lower/origin/dir -w
128 create_test_files $lower/origin/dir/subdir -w
129 create_test_files $lower/origin/parent/child -w
130 # Create lower redirected merge dir
131 mkdir $middle/merged
132 setfattr -n "trusted.overlay.redirect" -v "origin" $middle/merged
133 mount_dirs
134 # Check encode/decode/read of lower dir with parent under lower redirect
135 # This is expected to copy up merged/dir and encode an upper file handle
136 test_file_handles $SCRATCH_MNT/merged/dir -p -o $tmp.dir_file_handles
137 test -d $upper/merged/dir || echo "merged/dir not copied up"
138 # Check encode/decode/read of lower dir with grandparent under lower redirect
139 # This is expected to encode a lower file handle
140 test_file_handles $SCRATCH_MNT/merged/dir/subdir -p -o $tmp.subdir_file_handles
141 test -d $upper/merged/dir/subdir && echo "merged/dir/subdir unexpected copy up"
142 # This is expected to copy up parent and encode a lower file handle
143 test_file_handles $SCRATCH_MNT/merged/parent/child -p -o $tmp.child_file_handles
144 test -d $upper/merged/parent || echo "merged/parent not copied up"
145 test -d $upper/merged/parent/child && echo "merged/parent/child unexpected copy up"
146
147 # Rename lower redirected merge dir
148 mv $SCRATCH_MNT/merged $SCRATCH_MNT/merged.new/
149 # Check open, read and readdir from stored file handles
150 # (testdir argument is the mount point and NOT the dir
151 #  we are trying to open by stored file handle)
152 test_file_handles $SCRATCH_MNT -rp -i $tmp.dir_file_handles
153 test_file_handles $SCRATCH_MNT -rp -i $tmp.subdir_file_handles
154 test_file_handles $SCRATCH_MNT -rp -i $tmp.child_file_handles
155 # Retry decoding lower subdir file handles when indexed ancestor is in dcache
156 # (providing the ancestor dir argument pins the ancestor to dcache)
157 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.dir_file_handles
158 test_file_handles $SCRATCH_MNT/merged.new/dir -rp -i $tmp.subdir_file_handles
159 test_file_handles $SCRATCH_MNT/merged.new/parent -rp -i $tmp.child_file_handles
160 unmount_dirs
161
162 status=0
163 exit