overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / overlay / 065
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 065
6 #
7 # Test mount error cases with overlapping layers
8 #
9 # - Same upperdir/lowerdir
10 # - Overlapping upperdir/lowerdir
11 # - Overlapping lowerdir layers
12 # - Overlapping lowerdir with other mount upperdir/workdir
13 #
14 # Overlapping layers on mount or lookup results in ELOOP.
15 # Overlapping lowerdir with other mount upperdir/workdir
16 # result in EBUSY (only if index=on is used).
17 #
18 # This is a regression test for kernel commit:
19 #
20 #    146d62e5a586 "ovl: detect overlapping layers"
21 #
22 # and its followup fix commit:
23 #    0be0bfd2de9d "ovl: fix regression caused by overlapping layers detection"
24 #
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38         $UMOUNT_PROG $mnt2 2>/dev/null
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # real QA test starts here
49 _supported_fs overlay
50 _supported_os Linux
51 # Use non-default scratch underlying overlay dirs, we need to check
52 # them explicity after test.
53 _require_scratch_nocheck
54 _require_scratch_feature index
55
56 # Remove all files from previous tests
57 _scratch_mkfs
58
59 # Create multiple lowerdirs, upperdirs and workdirs
60 basedir=$OVL_BASE_SCRATCH_MNT
61 lowerdir=$basedir/lower
62 upperdir=$basedir/upper
63 workdir=$basedir/workdir
64 upperdir2=$basedir/upper.2
65 workdir2=$basedir/workdir.2
66 mnt2=$basedir/mnt.2
67
68 mkdir -p $lowerdir/lower $upperdir $workdir
69
70 # Try to mount an overlay with the same upperdir/lowerdir - expect ELOOP
71 echo Conflicting upperdir/lowerdir
72 _overlay_scratch_mount_dirs $upperdir $upperdir $workdir \
73         2>&1 | _filter_error_mount
74 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
75
76 # Use new upper/work dirs for each test to avoid ESTALE errors
77 # on mismatch lowerdir/upperdir (see test overlay/037)
78 rm -rf $upperdir $workdir
79 mkdir $upperdir $workdir
80
81 # Try to mount an overlay with the same workdir/lowerdir - expect ELOOP
82 # because $workdir/work overlaps with lowerdir
83 echo Conflicting workdir/lowerdir
84 _overlay_scratch_mount_dirs $workdir $upperdir $workdir \
85         -oindex=off 2>&1 | _filter_error_mount
86 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
87
88 rm -rf $upperdir $workdir
89 mkdir $upperdir $workdir
90
91 # Try to mount an overlay with overlapping upperdir/lowerdir - expect ELOOP
92 echo Overlapping upperdir/lowerdir
93 _overlay_scratch_mount_dirs $basedir $upperdir $workdir \
94         2>&1 | _filter_error_mount
95 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
96
97 rm -rf $upperdir $workdir
98 mkdir $upperdir $workdir
99
100 # Try to mount an overlay with the same lower layers - expect ELOOP
101 echo Conflicting lower layers
102 _overlay_scratch_mount_dirs $lowerdir:$lowerdir $upperdir $workdir \
103         2>&1 | _filter_error_mount
104 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
105
106 rm -rf $upperdir $workdir
107 mkdir $upperdir $workdir
108
109 # Try to mount an overlay with overlapping lower layers - expect ELOOP
110 echo Overlapping lower layers below
111 _overlay_scratch_mount_dirs $lowerdir:$lowerdir/lower $upperdir $workdir \
112         2>&1 | _filter_error_mount
113 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
114
115 rm -rf $upperdir $workdir
116 mkdir $upperdir $workdir
117
118 # Try to mount an overlay with overlapping lower layers - expect ELOOP
119 echo Overlapping lower layers above
120 _overlay_scratch_mount_dirs $lowerdir/lower:$lowerdir $upperdir $workdir \
121         2>&1 | _filter_error_mount
122 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
123
124 rm -rf $upperdir $workdir
125 mkdir -p $upperdir/upper $workdir $mnt2
126
127 # Mount overlay with non overlapping lowerdir, upperdir, workdir -
128 # expect success
129 _overlay_mount_dirs $lowerdir $upperdir $workdir overlay $mnt2
130
131 rm -rf $upperdir2 $workdir2
132 mkdir -p $upperdir2 $workdir2 $mnt2
133
134 # Try to mount an overlay with layers overlapping with another overlayfs
135 # upperdir - expect EBUSY with index=on and success with index=off
136 echo "Overlapping with upperdir of another instance (index=on)"
137 _overlay_scratch_mount_dirs $upperdir/upper $upperdir2 $workdir2 \
138         -oindex=on 2>&1 | _filter_busy_mount
139 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
140
141 rm -rf $upperdir2 $workdir2
142 mkdir -p $upperdir2 $workdir2
143
144 echo "Overlapping with upperdir of another instance (index=off)"
145 _overlay_scratch_mount_dirs $upperdir/upper $upperdir2 $workdir2 \
146         -oindex=off && $UMOUNT_PROG $SCRATCH_MNT
147
148 rm -rf $upperdir2 $workdir2
149 mkdir -p $upperdir2 $workdir2
150
151 # Try to mount an overlay with layers overlapping with another overlayfs
152 # workdir - expect EBUSY with index=on and success with index=off
153 echo "Overlapping with workdir of another instance (index=on)"
154 _overlay_scratch_mount_dirs $workdir/work $upperdir2 $workdir2 \
155         -oindex=on 2>&1 | _filter_busy_mount
156 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
157
158 rm -rf $upperdir2 $workdir2
159 mkdir -p $upperdir2 $workdir2
160
161 echo "Overlapping with workdir of another instance (index=off)"
162 _overlay_scratch_mount_dirs $workdir/work $upperdir2 $workdir2 \
163         -oindex=off && $UMOUNT_PROG $SCRATCH_MNT
164
165 # Move upper layer root into lower layer after mount
166 echo Overlapping upperdir/lowerdir after mount
167 mv $upperdir $lowerdir/
168 # Lookup files in overlay mount with overlapping layers -
169 # expect ELOOP when upper layer root is found in lower layer
170 find $mnt2/upper 2>&1 | _filter_scratch
171
172 # success, all done
173 status=0
174 exit