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
72 # Use non-default scratch underlying overlay dirs, we need to check
73 # them explicity after test.
74 _require_scratch_nocheck
75 _require_scratch_feature index
77 # Remove all files from previous tests
80 # Create multiple lowerdirs, upperdirs and workdirs
81 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
82 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
83 upperdir=$OVL_BASE_SCRATCH_MNT/upper
84 upperdir2=$OVL_BASE_SCRATCH_MNT/upper2
85 workdir=$OVL_BASE_SCRATCH_MNT/workdir
86 workdir2=$OVL_BASE_SCRATCH_MNT/workdir2
87 mkdir -p $lowerdir $lowerdir2 $upperdir $upperdir2 $workdir $workdir2
89 # Mount overlay with lowerdir, upperdir, workdir
90 _overlay_mount_dirs $lowerdir $upperdir $workdir \
93 # Try to mount another overlay with the same upperdir
94 # with index=off - expect success
95 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
96 overlay0 $SCRATCH_MNT -oindex=off && \
97 $UMOUNT_PROG $SCRATCH_MNT
99 # Try to mount another overlay with the same workdir
100 # with index=off - expect success
101 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
102 overlay1 $SCRATCH_MNT -oindex=off && \
103 $UMOUNT_PROG $SCRATCH_MNT
105 # Try to mount another overlay with the same upperdir
106 # with index=on - expect EBUSY
107 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
108 overlay2 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
110 # Try to mount another overlay with the same workdir
111 # with index=on - expect EBUSY
112 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
113 overlay3 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
116 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir