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 | _filter_scratch
62 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
63 echo "touching file on read-only filesystem (should fail)"
64 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
68 # Apparently this used to be broken at some point:
69 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
71 echo "unmounting read-only filesystem"
72 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
74 echo "setting device read-write"
75 blockdev --setrw $SCRATCH_DEV
77 echo "mounting read-write block device:"
78 _try_scratch_mount 2>&1 | _filter_scratch
81 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
86 echo "unmounting shutdown filesystem:"
87 _scratch_unmount 2>&1 | _filter_scratch
89 echo "setting device read-only"
90 blockdev --setro $SCRATCH_DEV
93 # Mounting a filesystem that requires log-recovery fails unless
94 # -o norecovery is used.
96 echo "mounting filesystem that needs recovery on a read-only device:"
97 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
99 echo "unmounting read-only filesystem"
100 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
103 # This is the way out if the underlying device really is read-only.
104 # Doesn't mean it's a good idea in practice, more a last resort
105 # data recovery hack.
107 echo "mounting filesystem with -o norecovery on a read-only device:"
108 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
109 echo "unmounting read-only filesystem"
110 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
112 echo "setting device read-write"
113 blockdev --setrw $SCRATCH_DEV
116 # But log recovery is performed when mount with -o ro as long as
117 # the underlying device is not write protected.
119 echo "mounting filesystem that needs recovery with -o ro:"
120 _try_scratch_mount -o ro 2>&1 | _filter_scratch