overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / overlay / 035
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test 035
6 #
7 # Test cases that force read-only mount
8 #
9 # - No upper dir
10 # - Failure to create work dir
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         $CHATTR_PROG -i $workdir
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36 _supported_fs overlay
37 _supported_os Linux
38 # Use non-default scratch underlying overlay dirs, we need to check
39 # them explicity after test.
40 _require_scratch_nocheck
41 _require_chattr i
42
43 # Remove all files from previous tests
44 _scratch_mkfs
45
46 # Create multiple lowerdirs and upperdir, workdir
47 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
48 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
49 upperdir=$OVL_BASE_SCRATCH_MNT/upper
50 workdir=$OVL_BASE_SCRATCH_MNT/workdir
51 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir
52
53 # Mount overlay with lower layers only.
54 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
55 $MOUNT_PROG -t overlay -o"lowerdir=$lowerdir2:$lowerdir1" \
56                         $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT
57 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
58 $MOUNT_PROG -o remount,rw $SCRATCH_MNT 2>&1 | _filter_ro_mount
59 $UMOUNT_PROG $SCRATCH_MNT
60
61 # Make workdir immutable to prevent workdir re-create on mount
62 $CHATTR_PROG +i $workdir
63
64 # Mount overlay with upper and workdir and expect failure to re-create workdir.
65 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
66 _overlay_scratch_mount_dirs $lowerdir2 $upperdir $workdir
67 touch $SCRATCH_MNT/bar 2>&1 | _filter_scratch
68 _scratch_remount rw 2>&1 | _filter_ro_mount
69
70 # check overlayfs
71 _overlay_check_scratch_dirs $lowerdir2 $upperdir $workdir
72
73 # success, all done
74 status=0
75 exit