4 # Test mount error cases with exclusive directories
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.
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.
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.
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
25 #-----------------------------------------------------------------------
26 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
27 # Author: Amir Goldstein <amir73il@gmail.com>
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.
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.
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 #-----------------------------------------------------------------------
45 seqres=$RESULT_DIR/$seq
46 echo "QA output created by $seq"
50 status=1 # failure is the default!
51 trap "_cleanup; exit \$status" 0 1 2 3 15
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
62 # get standard environment, filters and checks
66 # remove previous $seqres.full before test
69 # real QA test starts here
73 _require_scratch_feature index
75 # Remove all files from previous tests
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
87 # Mount overlay with lowerdir, upperdir, workdir
88 _overlay_mount_dirs $lowerdir $upperdir $workdir \
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
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
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
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