common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 050
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
4 #
5 # FS QA Test No. 050
6 #
7 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
8 #
9 seqfull=$0
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17
18 _cleanup()
19 {
20         cd /
21         blockdev --setrw $SCRATCH_DEV
22 }
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs generic
31
32 _require_scratch_nocheck
33 _require_scratch_shutdown
34 _require_local_device $SCRATCH_DEV
35 _require_norecovery
36
37 # Select appropriate output file
38 features=""
39 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
40         features="nojournal"
41 elif [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
42         # Mounting with quota on XFS requires a writable fs, which means
43         # we expect to fail the ro blockdev test with with EPERM.
44         features="xfsquota"
45 fi
46 _link_out_file "$features"
47
48 _scratch_mkfs >/dev/null 2>&1
49
50 #
51 # Mark the device read-only
52 #
53 echo "setting device read-only"
54 blockdev --setro $SCRATCH_DEV
55
56 #
57 # Mount it, and make sure we can't write to it, and we can unmount it again
58 #
59 echo "mounting read-only block device:"
60 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
61 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
62         echo "touching file on read-only filesystem (should fail)"
63         touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
64 fi
65
66 #
67 # Apparently this used to be broken at some point:
68 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
69 #
70 echo "unmounting read-only filesystem"
71 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
72
73 echo "setting device read-write"
74 blockdev --setrw $SCRATCH_DEV
75
76 echo "mounting read-write block device:"
77 _try_scratch_mount 2>&1 | _filter_scratch
78
79 echo "touch files"
80 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
81
82 echo "going down:"
83 _scratch_shutdown -f
84
85 echo "unmounting shutdown filesystem:"
86 _scratch_unmount 2>&1 | _filter_scratch
87
88 echo "setting device read-only"
89 blockdev --setro $SCRATCH_DEV
90
91 #
92 # Mounting a filesystem that requires log-recovery fails unless
93 # -o norecovery is used.
94 #
95 echo "mounting filesystem that needs recovery on a read-only device:"
96 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
97
98 echo "unmounting read-only filesystem"
99 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
100
101 #
102 # This is the way out if the underlying device really is read-only.
103 # Doesn't mean it's a good idea in practice, more a last resort
104 # data recovery hack.
105 #
106 echo "mounting filesystem with -o norecovery on a read-only device:"
107 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
108 echo "unmounting read-only filesystem"
109 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
110
111 echo "setting device read-write"
112 blockdev --setrw $SCRATCH_DEV
113
114 #
115 # But log recovery is performed when mount with -o ro as long as
116 # the underlying device is not write protected.
117 #
118 echo "mounting filesystem that needs recovery with -o ro:"
119 _try_scratch_mount -o ro 2>&1 | _filter_scratch
120
121 # success, all done
122 echo "*** done"
123 rm -f $seqres.full
124 status=0