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
42 elif [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
43 # Mounting with quota on XFS requires a writable fs, which means
44 # we expect to fail the ro blockdev test with with EPERM.
47 _link_out_file "$features"
49 _scratch_mkfs >/dev/null 2>&1
52 # Mark the device read-only
54 echo "setting device read-only"
55 blockdev --setro $SCRATCH_DEV
58 # Mount it, and make sure we can't write to it, and we can unmount it again
60 echo "mounting read-only block device:"
61 _try_scratch_mount 2>&1 | _filter_ro_mount
62 echo "touching file on read-only filesystem (should fail)"
63 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
66 # Apparently this used to be broken at some point:
67 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
69 echo "unmounting read-only filesystem"
70 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
72 echo "setting device read-write"
73 blockdev --setrw $SCRATCH_DEV
75 echo "mounting read-write block device:"
76 _try_scratch_mount 2>&1 | _filter_scratch
79 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
84 echo "unmounting shutdown filesystem:"
85 _scratch_unmount 2>&1 | _filter_scratch
87 echo "setting device read-only"
88 blockdev --setro $SCRATCH_DEV
91 # Mounting a filesystem that requires log-recovery fails unless
92 # -o norecovery is used.
94 echo "mounting filesystem that needs recovery on a read-only device:"
95 _try_scratch_mount 2>&1 | _filter_ro_mount
97 echo "unmounting read-only filesystem"
98 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
101 # This is the way out if the underlying device really is read-only.
102 # Doesn't mean it's a good idea in practice, more a last resort
103 # data recovery hack.
105 echo "mounting filesystem with -o norecovery on a read-only device:"
106 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount
107 echo "unmounting read-only filesystem"
108 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
110 echo "setting device read-write"
111 blockdev --setrw $SCRATCH_DEV
114 # But log recovery is performed when mount with -o ro as long as
115 # the underlying device is not write protected.
117 echo "mounting filesystem that needs recovery with -o ro:"
118 _try_scratch_mount -o ro 2>&1 | _filter_scratch