d1b2c19b8becf8aa605ee73f720ad13f1141a566
[xfstests-dev.git] / tests / overlay / 035
1 #! /bin/bash
2 # FS QA Test 035
3 #
4 # Test cases that force read-only mount
5 #
6 # - No upper dir
7 # - Failure to create work dir
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
11 # Author: Amir Goldstein <amir73il@gmail.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
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         $CHATTR_PROG -i $workdir
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 # remove previous $seqres.full before test
49 rm -f $seqres.full
50
51 # real QA test starts here
52 _supported_fs overlay
53 _supported_os Linux
54 # Use non-default scratch underlying overlay dirs, we need to check
55 # them explicity after test.
56 _require_scratch_nocheck
57 _require_chattr i
58
59 # Remove all files from previous tests
60 _scratch_mkfs
61
62 # Create multiple lowerdirs and upperdir, workdir
63 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
64 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
65 upperdir=$OVL_BASE_SCRATCH_MNT/upper
66 workdir=$OVL_BASE_SCRATCH_MNT/workdir
67 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir
68
69 # Mount overlay with lower layers only.
70 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
71 $MOUNT_PROG -t overlay -o"lowerdir=$lowerdir2:$lowerdir1" \
72                         $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT
73 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
74 _scratch_remount rw 2>&1 | _filter_ro_mount
75 $UMOUNT_PROG $SCRATCH_MNT
76
77 # Make workdir immutable to prevent workdir re-create on mount
78 $CHATTR_PROG +i $workdir
79
80 # Mount overlay with upper and workdir and expect failure to re-create workdir.
81 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
82 _overlay_scratch_mount_dirs $lowerdir2 $upperdir $workdir
83 touch $SCRATCH_MNT/bar 2>&1 | _filter_scratch
84 _scratch_remount rw 2>&1 | _filter_ro_mount
85
86 # check overlayfs
87 _overlay_check_scratch_dirs $lowerdir2 $upperdir $workdir
88
89 # success, all done
90 status=0
91 exit