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 _begin_fstest shutdown mount auto quick
13 # Override the default cleanup function.
17 blockdev --setrw $SCRATCH_DEV
20 # Import common functions.
23 # real QA test starts here
26 _require_scratch_nocheck
27 _require_scratch_shutdown
28 _require_local_device $SCRATCH_DEV
31 # Select appropriate output file
33 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
35 elif [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
36 # Mounting with quota on XFS requires a writable fs, which means
37 # we expect to fail the ro blockdev test with with EPERM.
40 _link_out_file "$features"
42 _scratch_mkfs >/dev/null 2>&1
45 # Mark the device read-only
47 echo "setting device read-only"
48 blockdev --setro $SCRATCH_DEV
51 # Mount it, and make sure we can't write to it, and we can unmount it again
53 echo "mounting read-only block device:"
54 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
55 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
56 echo "touching file on read-only filesystem (should fail)"
57 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
61 # Apparently this used to be broken at some point:
62 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
64 echo "unmounting read-only filesystem"
65 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
67 echo "setting device read-write"
68 blockdev --setrw $SCRATCH_DEV
70 echo "mounting read-write block device:"
71 _try_scratch_mount 2>&1 | _filter_scratch
74 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
79 echo "unmounting shutdown filesystem:"
80 _scratch_unmount 2>&1 | _filter_scratch
82 echo "setting device read-only"
83 blockdev --setro $SCRATCH_DEV
86 # Mounting a filesystem that requires log-recovery fails unless
87 # -o norecovery is used.
89 echo "mounting filesystem that needs recovery on a read-only device:"
90 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
92 echo "unmounting read-only filesystem"
93 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
96 # This is the way out if the underlying device really is read-only.
97 # Doesn't mean it's a good idea in practice, more a last resort
100 echo "mounting filesystem with -o norecovery on a read-only device:"
101 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
102 echo "unmounting read-only filesystem"
103 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
105 echo "setting device read-write"
106 blockdev --setrw $SCRATCH_DEV
109 # But log recovery is performed when mount with -o ro as long as
110 # the underlying device is not write protected.
112 echo "mounting filesystem that needs recovery with -o ro:"
113 _try_scratch_mount -o ro 2>&1 | _filter_scratch