2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
4 # Copyright (c) 2020 Lukas Czerner.
8 # Copied from tests generic/050 and adjusted to support testing
9 # read-only external journal device on ext4.
11 # Check out various mount/remount/unmount scenarious on a read-only
14 # This problem has been addressed with proposed kernel patch
15 # https://lore.kernel.org/linux-ext4/20200717090605.2612-1-lczerner@redhat.com/
19 _begin_fstest shutdown mount auto quick
21 # Override the default cleanup function.
25 blockdev --setrw $SCRATCH_LOGDEV
26 blockdev --setrw $SCRATCH_DEV
29 # Import common functions.
32 # real QA test starts here
33 _supported_fs ext4 ext3
35 _require_scratch_nocheck
36 _require_scratch_shutdown
38 _require_local_device $SCRATCH_DEV
39 _require_local_device $SCRATCH_LOGDEV
42 _scratch_mkfs >/dev/null 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
46 # Mark the log device read-only
48 echo "setting log device read-only"
49 blockdev --setro $SCRATCH_LOGDEV
52 # Mount it, and make sure we can't write to it, and we can unmount it again
54 echo "mounting with read-only log device:"
55 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
56 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
57 echo "touching file on read-only filesystem (should fail)"
58 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
61 echo "unmounting read-only filesystem"
62 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
64 echo "setting log device read-write"
65 blockdev --setrw $SCRATCH_LOGDEV
67 echo "mounting with read-write log device:"
68 _try_scratch_mount 2>&1 | _filter_scratch
71 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
76 echo "unmounting shutdown filesystem:"
77 _scratch_unmount 2>&1 | _filter_scratch
79 echo "setting log device read-only"
80 blockdev --setro $SCRATCH_LOGDEV
83 # Mounting a filesystem that requires log-recovery fails even with
84 # -o norecovery unless the fs device is read only or it's mounted
87 echo "mounting filesystem that needs recovery with a read-only log device:"
88 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
90 echo "unmounting read-only filesystem"
91 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
93 echo "mounting filesystem with -o norecovery with a read-only log device:"
94 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
95 echo "unmounting read-only filesystem"
96 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
99 # This is the way out if the log device really is read-only.
100 # Doesn't mean it's a good idea in practice, more a last resort
101 # data recovery hack. Either the underlying fs device needs
102 # to be read only as well, or we mount the file system read only
104 echo "setting fs device read-only"
105 blockdev --setro $SCRATCH_DEV
106 echo "mounting filesystem with -o norecovery with a read-only fs and log 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
110 echo "setting fs device read-write"
111 blockdev --setrw $SCRATCH_DEV
113 echo "mounting filesystem with -o norecovery,ro with a read-only log device:"
114 _try_scratch_mount -o norecovery,ro 2>&1 | _filter_ro_mount | _filter_scratch
115 echo "unmounting read-only filesystem"
116 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
118 echo "setting log device read-write"
119 blockdev --setrw $SCRATCH_LOGDEV
122 # But log recovery is performed when mount with -o ro as long as
123 # the underlying device is not write protected.
125 echo "mounting filesystem that needs recovery with -o ro:"
126 _try_scratch_mount -o ro 2>&1 | _filter_scratch