common/xfs: refactor commands to select a particular xfs backing device
[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 # Use non-default scratch underlying overlay dirs, we need to check
38 # them explicity after test.
39 _require_scratch_nocheck
40 _require_chattr i
41
42 # Remove all files from previous tests
43 _scratch_mkfs
44
45 # Create multiple lowerdirs and upperdir, workdir
46 lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1
47 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
48 upperdir=$OVL_BASE_SCRATCH_MNT/upper
49 workdir=$OVL_BASE_SCRATCH_MNT/workdir
50 mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir
51
52 # Mount overlay with lower layers only.
53 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
54 $MOUNT_PROG -t overlay -o"lowerdir=$lowerdir2:$lowerdir1" \
55                         $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT
56 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
57 $MOUNT_PROG -o remount,rw $SCRATCH_MNT 2>&1 | _filter_ro_mount
58 $UMOUNT_PROG $SCRATCH_MNT
59
60 # Make workdir immutable to prevent workdir re-create on mount
61 $CHATTR_PROG +i $workdir
62
63 # Mount overlay with upper and workdir and expect failure to re-create workdir.
64 # Verify that overlay is mounted read-only and that it cannot be remounted rw.
65 _overlay_scratch_mount_dirs $lowerdir2 $upperdir $workdir
66 touch $SCRATCH_MNT/bar 2>&1 | _filter_scratch
67 _scratch_remount rw 2>&1 | _filter_ro_mount
68
69 # check overlayfs
70 _overlay_check_scratch_dirs $lowerdir2 $upperdir $workdir
71
72 # success, all done
73 status=0
74 exit