2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test mount error cases with exclusive directories
9 # Overlayfs is often used to mount several mounts that share a single
10 # lower dir, but every overlayfs mount should have its own private
11 # upperdir and private workdir.
13 # Overlayfs mount on kernel <= v4.12 does not check if upper/work dirs
14 # are currently in-use by another overlayfs mount on the system and bad
15 # things can happen with such configuration.
17 # Commit 2cac0c00a6cd ("ovl: get exclusive ownership on upper/work dirs")
18 # in kernel v4.13 enforces upper/work dir in-use for any overlayfs mount.
19 # Later stable fix commit 85fdee1eef1a ("ovl: fix regression caused by
20 # exclusive upper/work dir protection") relaxes mount failure to a warning
21 # for index=off mount and fails mount with EBUSY for index=on mount.
23 # This test expects success with index=off and EBUSY with index=on
24 # when trying to mount overlay with:
25 # - Upper dir is in-use by another overlay mount
26 # - Work dir is in-use by another overlay mount
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # unmount the two extra mounts in case they did not fail
42 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
43 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
46 # get standard environment, filters and checks
50 # remove previous $seqres.full before test
53 # real QA test starts here
56 # Use non-default scratch underlying overlay dirs, we need to check
57 # them explicity after test.
58 _require_scratch_nocheck
59 _require_scratch_feature index
61 # Remove all files from previous tests
64 # Create multiple lowerdirs, upperdirs and workdirs
65 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
66 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
67 upperdir=$OVL_BASE_SCRATCH_MNT/upper
68 upperdir2=$OVL_BASE_SCRATCH_MNT/upper2
69 workdir=$OVL_BASE_SCRATCH_MNT/workdir
70 workdir2=$OVL_BASE_SCRATCH_MNT/workdir2
71 mkdir -p $lowerdir $lowerdir2 $upperdir $upperdir2 $workdir $workdir2
73 # Mount overlay with lowerdir, upperdir, workdir
74 _overlay_mount_dirs $lowerdir $upperdir $workdir \
77 # Try to mount another overlay with the same upperdir
78 # with index=off - expect success
79 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
80 overlay0 $SCRATCH_MNT -oindex=off && \
81 $UMOUNT_PROG $SCRATCH_MNT
83 # Try to mount another overlay with the same workdir
84 # with index=off - expect success
85 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
86 overlay1 $SCRATCH_MNT -oindex=off && \
87 $UMOUNT_PROG $SCRATCH_MNT
89 # Try to mount another overlay with the same upperdir
90 # with index=on - expect EBUSY
91 _overlay_mount_dirs $lowerdir $upperdir $workdir2 \
92 overlay2 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
94 # Try to mount another overlay with the same workdir
95 # with index=on - expect EBUSY
96 _overlay_mount_dirs $lowerdir2 $upperdir2 $workdir \
97 overlay3 $SCRATCH_MNT -oindex=on 2>&1 | _filter_busy_mount
100 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir