generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 050
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
4 #
5 # FS QA Test No. 050
6 #
7 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
8 #
9 seqfull=$0
10 . ./common/preamble
11 _begin_fstest shutdown mount auto quick
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         blockdev --setrw $SCRATCH_DEV
18 }
19
20 # Import common functions.
21 . ./common/filter
22
23 # real QA test starts here
24 _supported_fs generic
25
26 _require_scratch_nocheck
27 _require_scratch_shutdown
28 _require_local_device $SCRATCH_DEV
29 _require_norecovery
30
31 # Select appropriate output file
32 features=""
33 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
34         features="nojournal"
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.
38         features="xfsquota"
39 fi
40 _link_out_file "$features"
41
42 _scratch_mkfs >/dev/null 2>&1
43
44 #
45 # Mark the device read-only
46 #
47 echo "setting device read-only"
48 blockdev --setro $SCRATCH_DEV
49
50 #
51 # Mount it, and make sure we can't write to it, and we can unmount it again
52 #
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
58 fi
59
60 #
61 # Apparently this used to be broken at some point:
62 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
63 #
64 echo "unmounting read-only filesystem"
65 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
66
67 echo "setting device read-write"
68 blockdev --setrw $SCRATCH_DEV
69
70 echo "mounting read-write block device:"
71 _try_scratch_mount 2>&1 | _filter_scratch
72
73 echo "touch files"
74 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
75
76 echo "going down:"
77 _scratch_shutdown -f
78
79 echo "unmounting shutdown filesystem:"
80 _scratch_unmount 2>&1 | _filter_scratch
81
82 echo "setting device read-only"
83 blockdev --setro $SCRATCH_DEV
84
85 #
86 # Mounting a filesystem that requires log-recovery fails unless
87 # -o norecovery is used.
88 #
89 echo "mounting filesystem that needs recovery on a read-only device:"
90 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
91
92 echo "unmounting read-only filesystem"
93 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
94
95 #
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
98 # data recovery hack.
99 #
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
104
105 echo "setting device read-write"
106 blockdev --setrw $SCRATCH_DEV
107
108 #
109 # But log recovery is performed when mount with -o ro as long as
110 # the underlying device is not write protected.
111 #
112 echo "mounting filesystem that needs recovery with -o ro:"
113 _try_scratch_mount -o ro 2>&1 | _filter_scratch
114
115 # success, all done
116 echo "*** done"
117 status=0