dcf0f38b5d33e3b970ee2d6d3ac7cb26c80fc904
[xfstests-dev.git] / 200
1 #! /bin/bash
2 # FS QA Test No. 200
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 # creator
24 owner=hch@lst.de
25
26 seq=`basename $0`
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 _filter_scratch()
34 {
35         sed -e "s,$SCRATCH_DEV,SCRATCH_DEV,g" | \
36                 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
37 }
38
39 _cleanup()
40 {
41         cd /
42         blockdev --setrw $SCRATCH_DEV
43 }
44 trap "_cleanup; exit \$status" 0 1 2 3 15
45
46 # get standard environment, filters and checks
47 . ./common.rc
48 . ./common.filter
49
50 # real QA test starts here
51 _supported_fs xfs
52 _supported_os Linux
53
54 _require_scratch
55
56 _scratch_mkfs_xfs >/dev/null 2>&1
57
58 #
59 # Mark the device read-only
60 #
61 echo "setting device read-only"
62 blockdev --setro $SCRATCH_DEV
63
64 #
65 # Mount it, and make sure we can't write to it, and we can unmount it again
66 #
67 echo "mounting read-only block device:"
68 _scratch_mount 2>&1 | _filter_scratch
69
70 echo "touching file on read-only filesystem (should fail)"
71 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
72
73 #
74 # Apparently this used to be broken at some point:
75 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
76 #
77 echo "unmounting read-only filesystem"
78 umount $SCRATCH_MNT 2>&1 | _filter_scratch
79
80 echo "setting device read-write"
81 blockdev --setrw $SCRATCH_DEV
82
83 echo "mounting read-write block device:"
84 _scratch_mount 2>&1 | _filter_scratch
85
86 echo "touch files"
87 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
88
89 echo "going down:"
90 src/godown -f $SCRATCH_MNT
91
92 echo "unmounting shutdown filesystem:"
93 umount $SCRATCH_MNT 2>&1 | _filter_scratch
94
95 echo "setting device read-only"
96 blockdev --setro $SCRATCH_DEV
97
98 #
99 # Mounting a filesystem that requires log-recovery fails unless
100 # -o norecovery is used.
101 #
102 echo "mounting filesystem that needs recovery on a read-only device:"
103 _scratch_mount 2>&1 | _filter_scratch
104
105 echo "unmounting read-only filesystem"
106 umount $SCRATCH_MNT 2>&1 | _filter_scratch
107
108 #
109 # This is the way out if the underlying device really is read-only.
110 # Doesn't mean it's a good idea in practive, more a last resort
111 # data recovery hack.
112 #
113 echo "mounting filesystem with -o norecovery on a read-only device:"
114 _scratch_mount -o norecovery 2>&1 | _filter_scratch
115
116 echo "unmounting read-only filesystem"
117 umount $SCRATCH_MNT 2>&1 | _filter_scratch
118
119 echo "setting device read-write"
120 blockdev --setrw $SCRATCH_DEV
121
122 #
123 # But log recovery is performed when mount with -o ro as long as
124 # the underlying device is not write protected.
125 #
126 echo "mounting filesystem that needs recovery with -o ro:"
127 _scratch_mount -o ro 2>&1 | _filter_scratch
128
129
130 # success, all done
131 echo "*** done"
132 rm -f $seq.full
133 status=0