overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / overlay / 036
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 036
6 #
7 # Test mount error cases with exclusive directories
8 #
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.
12 #
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.
16 #
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.
22 #
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
27 #
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.*
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
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49
50 # remove previous $seqres.full before test
51 rm -f $seqres.full
52
53 # real QA test starts here
54 _supported_fs overlay
55 _supported_os Linux
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
60
61 # Remove all files from previous tests
62 _scratch_mkfs
63
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
72
73 # Mount overlay with lowerdir, upperdir, workdir
74 _overlay_mount_dirs $lowerdir $upperdir $workdir \
75                     overlay $SCRATCH_MNT
76
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
82
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
88
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
93
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
98
99 # check overlayfs
100 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir
101
102 # success, all done
103 status=0
104 exit