2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
7 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
21 blockdev --setrw $SCRATCH_DEV
23 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
29 # real QA test starts here
33 _require_scratch_nocheck
34 _require_scratch_shutdown
35 _require_local_device $SCRATCH_DEV
38 # Select appropriate output file
40 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
43 _link_out_file "$features"
45 _scratch_mkfs >/dev/null 2>&1
50 if [ -n "$expect_mount_failure" ]; then
51 arg="s|mount: $SCRATCH_MNT: permission denied|mount: device write-protected, mounting read-only|g"
53 sed -e "$arg" | _filter_ro_mount
56 # Mounting with quota on XFS requires a writable fs, which means
57 # we expect to fail the ro blockdev test with with EPERM.
59 if [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
60 expect_mount_failure=1
64 # Mark the device read-only
66 echo "setting device read-only"
67 blockdev --setro $SCRATCH_DEV
70 # Mount it, and make sure we can't write to it, and we can unmount it again
72 echo "mounting read-only block device:"
73 _try_scratch_mount 2>&1 | filter_ro_mount
74 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
75 echo "touching file on read-only filesystem (should fail)"
76 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
79 # Apparently this used to be broken at some point:
80 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
82 echo "unmounting read-only filesystem"
83 _scratch_unmount 2>&1 | _filter_scratch
84 elif [ -n "${expect_mount_failure}" ]; then
85 # Mount failed, so simulate EROFS instead of scribbling on root fs
86 echo "touching file on read-only filesystem (should fail)"
87 echo "touch: cannot touch 'SCRATCH_MNT/foo': Read-only file system"
88 echo "unmounting read-only filesystem"
90 echo "Mount failed, though it wasn't supposed to!"
93 echo "setting device read-write"
94 blockdev --setrw $SCRATCH_DEV
96 echo "mounting read-write block device:"
97 _try_scratch_mount 2>&1 | _filter_scratch
100 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
105 echo "unmounting shutdown filesystem:"
106 _scratch_unmount 2>&1 | _filter_scratch
108 echo "setting device read-only"
109 blockdev --setro $SCRATCH_DEV
112 # Mounting a filesystem that requires log-recovery fails unless
113 # -o norecovery is used.
115 echo "mounting filesystem that needs recovery on a read-only device:"
116 _try_scratch_mount 2>&1 | _filter_ro_mount
118 echo "unmounting read-only filesystem"
119 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
122 # This is the way out if the underlying device really is read-only.
123 # Doesn't mean it's a good idea in practice, more a last resort
124 # data recovery hack.
126 echo "mounting filesystem with -o norecovery on a read-only device:"
127 _try_scratch_mount -o norecovery 2>&1 | filter_ro_mount
128 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
129 echo "unmounting read-only filesystem"
130 _scratch_unmount 2>&1 | _filter_scratch
131 elif [ -n "${expect_mount_failure}" ]; then
132 # Mount failed, simulate correct output
133 echo "unmounting read-only filesystem"
135 echo "Mount failed, though it wasn't supposed to!"
138 echo "setting device read-write"
139 blockdev --setrw $SCRATCH_DEV
142 # But log recovery is performed when mount with -o ro as long as
143 # the underlying device is not write protected.
145 echo "mounting filesystem that needs recovery with -o ro:"
146 _try_scratch_mount -o ro 2>&1 | _filter_scratch