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
32 _require_scratch_nocheck
33 _require_scratch_shutdown
34 _require_local_device $SCRATCH_DEV
37 # Select appropriate output file
39 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
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.
46 _link_out_file "$features"
48 _scratch_mkfs >/dev/null 2>&1
51 # Mark the device read-only
53 echo "setting device read-only"
54 blockdev --setro $SCRATCH_DEV
57 # Mount it, and make sure we can't write to it, and we can unmount it again
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
67 # Apparently this used to be broken at some point:
68 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
70 echo "unmounting read-only filesystem"
71 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
73 echo "setting device read-write"
74 blockdev --setrw $SCRATCH_DEV
76 echo "mounting read-write block device:"
77 _try_scratch_mount 2>&1 | _filter_scratch
80 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
85 echo "unmounting shutdown filesystem:"
86 _scratch_unmount 2>&1 | _filter_scratch
88 echo "setting device read-only"
89 blockdev --setro $SCRATCH_DEV
92 # Mounting a filesystem that requires log-recovery fails unless
93 # -o norecovery is used.
95 echo "mounting filesystem that needs recovery on a read-only device:"
96 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
98 echo "unmounting read-only filesystem"
99 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
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.
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
111 echo "setting device read-write"
112 blockdev --setrw $SCRATCH_DEV
115 # But log recovery is performed when mount with -o ro as long as
116 # the underlying device is not write protected.
118 echo "mounting filesystem that needs recovery with -o ro:"
119 _try_scratch_mount -o ro 2>&1 | _filter_scratch