dbf0ac5cd1853a05f1206a785df7fd52e184b4b4
[xfstests-dev.git] / tests / generic / 050
1 #! /bin/bash
2 # FS QA Test No. 050
3 #
4 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Christoph Hellwig.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31
32 _cleanup()
33 {
34         cd /
35         blockdev --setrw $SCRATCH_DEV
36 }
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44 _supported_fs generic
45 _supported_os Linux
46
47 _require_local_device $SCRATCH_DEV
48 _require_scratch_nocheck
49 _require_scratch_shutdown
50 _require_norecovery
51
52 _scratch_mkfs >/dev/null 2>&1
53
54 #
55 # Mark the device read-only
56 #
57 echo "setting device read-only"
58 blockdev --setro $SCRATCH_DEV
59
60 #
61 # Mount it, and make sure we can't write to it, and we can unmount it again
62 #
63 echo "mounting read-only block device:"
64 _scratch_mount 2>&1 | _filter_ro_mount
65
66 echo "touching file on read-only filesystem (should fail)"
67 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
68
69 #
70 # Apparently this used to be broken at some point:
71 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
72 #
73 echo "unmounting read-only filesystem"
74 _scratch_unmount 2>&1 | _filter_scratch
75
76 echo "setting device read-write"
77 blockdev --setrw $SCRATCH_DEV
78
79 echo "mounting read-write block device:"
80 _scratch_mount 2>&1 | _filter_scratch
81
82 echo "touch files"
83 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
84
85 echo "going down:"
86 src/godown -f $SCRATCH_MNT
87
88 echo "unmounting shutdown filesystem:"
89 _scratch_unmount 2>&1 | _filter_scratch
90
91 echo "setting device read-only"
92 blockdev --setro $SCRATCH_DEV
93
94 #
95 # Mounting a filesystem that requires log-recovery fails unless
96 # -o norecovery is used.
97 #
98 echo "mounting filesystem that needs recovery on a read-only device:"
99 _scratch_mount 2>&1 | _filter_ro_mount
100
101 echo "unmounting read-only filesystem"
102 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
103
104 #
105 # This is the way out if the underlying device really is read-only.
106 # Doesn't mean it's a good idea in practive, more a last resort
107 # data recovery hack.
108 #
109 echo "mounting filesystem with -o norecovery on a read-only device:"
110 _scratch_mount -o norecovery 2>&1 | _filter_ro_mount
111
112 echo "unmounting read-only filesystem"
113 _scratch_unmount 2>&1 | _filter_scratch
114
115 echo "setting device read-write"
116 blockdev --setrw $SCRATCH_DEV
117
118 #
119 # But log recovery is performed when mount with -o ro as long as
120 # the underlying device is not write protected.
121 #
122 echo "mounting filesystem that needs recovery with -o ro:"
123 _scratch_mount -o ro 2>&1 | _filter_scratch
124
125 # success, all done
126 echo "*** done"
127 rm -f $seqres.full
128 status=0