overlay/036: fix upper/lower dir mismatch
[xfstests-dev.git] / tests / overlay / 036
1 #! /bin/bash
2 # FS QA Test 036
3 #
4 # Test mount error cases with exclusive directories
5 #
6 # Overlayfs is often used to mount several mounts that share a single
7 # lower dir, but every overlayfs mount should have its own private
8 # upperdir and private workdir.
9 #
10 # Overlayfs mount on kernel <= v4.12 does not check if upper/work dirs
11 # are currently in-use by another overlayfs mount on the system and bad
12 # things can happen with such configuration.
13 #
14 # Commit 2cac0c00a6cd ("ovl: get exclusive ownership on upper/work dirs")
15 # in kernel v4.13 enforces upper/work dir in-use for any overlayfs mount.
16 # Later stable fix commit 85fdee1eef1a ("ovl: fix regression caused by
17 # exclusive upper/work dir protection") relaxes mount failure to a warning
18 # for index=off mount and fails mount with EBUSY for index=on mount.
19 #
20 # This test expects success with index=off and EBUSY with index=on
21 # when trying to mount overlay with:
22 # - Upper dir is in-use by another overlay mount
23 # - Work dir is in-use by another overlay mount
24 #
25 #-----------------------------------------------------------------------
26 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
27 # Author: Amir Goldstein <amir73il@gmail.com>
28 #
29 # This program is free software; you can redistribute it and/or
30 # modify it under the terms of the GNU General Public License as
31 # published by the Free Software Foundation.
32 #
33 # This program is distributed in the hope that it would be useful,
34 # but WITHOUT ANY WARRANTY; without even the implied warranty of
35 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36 # GNU General Public License for more details.
37 #
38 # You should have received a copy of the GNU General Public License
39 # along with this program; if not, write the Free Software Foundation,
40 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
41 #-----------------------------------------------------------------------
42 #
43
44 seq=`basename $0`
45 seqres=$RESULT_DIR/$seq
46 echo "QA output created by $seq"
47
48 here=`pwd`
49 tmp=/tmp/$$
50 status=1        # failure is the default!
51 trap "_cleanup; exit \$status" 0 1 2 3 15
52
53 _cleanup()
54 {
55         cd /
56         rm -f $tmp.*
57         # unmount the two extra mounts in case they did not fail
58         $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
59         $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
60 }
61
62 # get standard environment, filters and checks
63 . ./common/rc
64 . ./common/filter
65
66 # remove previous $seqres.full before test
67 rm -f $seqres.full
68
69 # real QA test starts here
70 _supported_fs overlay
71 _supported_os Linux
72 _require_scratch
73 _require_scratch_feature index
74
75 # Remove all files from previous tests
76 _scratch_mkfs
77
78 # Create multiple lowerdirs, upperdirs and workdirs
79 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
80 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
81 upperdir=$OVL_BASE_SCRATCH_MNT/upper
82 upperdir2=$OVL_BASE_SCRATCH_MNT/upper2
83 workdir=$OVL_BASE_SCRATCH_MNT/workdir
84 workdir2=$OVL_BASE_SCRATCH_MNT/workdir2
85 mkdir -p $lowerdir $lowerdir2 $upperdir $upperdir2 $workdir $workdir2
86
87 # Mount overlay with lowerdir, upperdir, workdir
88 _overlay_mount_dirs $lowerdir $upperdir $workdir \
89                     overlay $SCRATCH_MNT
90
91 # Try to mount another overlay with the same upperdir
92 # with index=off - expect success
93 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
94                     overlay0 $SCRATCH_MNT -oindex=off && \
95                     $UMOUNT_PROG $SCRATCH_MNT
96
97 # Try to mount another overlay with the same workdir
98 # with index=off - expect success
99 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
100                     overlay1 $SCRATCH_MNT -oindex=off && \
101                     $UMOUNT_PROG $SCRATCH_MNT
102
103 # Try to mount another overlay with the same upperdir
104 # with index=on - expect EBUSY
105 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
106             overlay2 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
107
108 # Try to mount another overlay with the same workdir
109 # with index=on - expect EBUSY
110 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
111             overlay3 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
112
113
114 # success, all done
115 status=0
116 exit