xfstests: add local.config example
[xfstests-dev.git] / 189
1 #! /bin/bash
2 # FS QA Test No. 189
3 #
4 # Test remount behaviour
5 # Initial motivation was for pv#985710 and pv#983964
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=hch@lst.de
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35 tag="added by qa $seq"
36
37 _cleanup()
38 {
39         cd /
40         umount $SCRATCH_MNT 2>/dev/null
41         _putback_scratch_fstab
42         rm -f $tmp.*
43 }
44
45 _scratch_filter()
46 {
47         sed -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
48             -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
49             -e "s#,context.*s0\"##"
50 }
51
52 _check_mount()
53 {
54         # assumes that we don't have extra ops in fstab
55         _mount | grep $SCRATCH_MNT | _scratch_filter
56 }
57
58 #
59 # mount(8) adds all options from mtab and fstab to the mount command
60 # line.  So the filesystem either must not reject any option at all
61 # if it can't change it, or compare the value on the command line
62 # to the existing state and only reject it if it would change
63 # something that can't be changed.
64 #
65 # Test this behaviour by mounting a filesystem read-only with a non-
66 # default option and then try to remount it rw.
67 #
68 # note that mount(8) doesn't add the options when specifying both the
69 # device node and mount point, so test out the various mounting
70 # alternatives
71 #
72 _test_remount_rw()
73 {
74         # use filestreams as a hopefully never default option
75         echo
76         echo "try remount ro,filestreams -> rw,filestreams"
77         echo
78         _scratch_mount -o ro,filestreams
79         [ $? -eq 0 ] || echo "ro,filestreams mount failed unexpectedly"
80         _check_mount
81
82         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
83                 echo "mounting given: $dev_mnt" | _scratch_filter
84                 _mount -o remount,rw $dev_mnt
85                 [ $? -eq 0 ] || echo "remount rw failed"
86                 _check_mount
87         done
88
89         umount $SCRATCH_MNT
90
91         echo
92         echo "try remount ro,noattr2 -> rw,attr2"
93         echo
94         _scratch_mount -o ro,noattr2
95         [ $? -eq 0 ] || echo "ro,noattr2 mount failed unexpectedly"
96         _check_mount
97
98         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
99                 echo "mounting given: $dev_mnt" | _scratch_filter
100                 _mount -o remount,rw,attr2 $dev_mnt
101                 [ $? -eq 0 ] || echo "remount rw,attr2 failed"
102                 _check_mount
103         done
104
105         umount $SCRATCH_MNT
106 }
107
108 #
109 # make sure we really can write to a filesystem after remount,rw
110 #
111 _test_remount_write()
112 {
113         echo
114         echo "try touching file after remount ro -> rw with options"
115         echo
116         _scratch_mount
117         [ $? -eq 0 ] || echo "mount (1) failed unexpectedly"
118
119         touch $SCRATCH_MNT/foobar
120         [ $? -eq 0 ] || echo "touch (1) failed unexpectedly"
121
122         umount $SCRATCH_MNT
123
124         _scratch_mount -o ro
125         [ $? -eq 0 ] || echo "mount (2) failed unexpectedly"
126
127         _mount -o remount,rw,filestreams $SCRATCH_MNT
128         [ $? -eq 0 ] || echo "remount failed unexpectedly"
129
130         touch $SCRATCH_MNT/foobar
131         [ $? -eq 0 ] || echo "touch (2) failed unexpectedly"
132
133         umount $SCRATCH_MNT
134 }
135
136 #
137 # barrier is the only option we can change besides ro<->rw which is partially
138 # handled by the VFS and tested elsewhere.  Make sure mount accepts going
139 # from barrier (which also is the default) to nobarrier and back.
140 #
141 _test_remount_barrier()
142 {
143         echo
144         echo "Do remount barrier tests"
145         echo
146
147         # mention barrier explicitly even if it's currently the default just to be sure
148         _scratch_mount -o barrier
149         [ $? -eq 0 ] || echo "mount failed unexpectedly!"
150         _check_mount
151
152         _scratch_mount -o remount,nobarrier
153         [ $? -eq 0 ] || _fail "remount nobarrier failed"
154         _check_mount
155
156         _scratch_mount -o remount,barrier
157         [ $? -eq 0 ] || _fail "remount barrier failed"
158         _check_mount
159
160         umount $SCRATCH_MNT
161 }
162
163
164 #
165 # Example fstab entry
166 # /dev/sdb2            /mnt/scratch1        xfs       defaults 0 0
167 #
168 _add_scratch_fstab()
169 {
170         # comment out any existing SCRATCH_DEV
171         $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
172
173         # add our fstab entry
174         echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
175 }
176
177 _modify_scratch_fstab()
178 {
179         opts=$1
180
181         # modify our fstab entry that we added
182         # modify opts by looking for last word which has non-space chars
183         $SED_PROG -i "s; [^ ]* 0 0 # $tag; $opts 0 0 # $tag;" /etc/fstab
184 }
185
186 _putback_scratch_fstab()
187 {
188         # uncomment out any existing SCRATCH_DEV
189         $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
190
191         # remove the one we added at the end
192         $SED_PROG -i "/# $tag/d" /etc/fstab
193 }
194
195 # get standard environment, filters and checks
196 . ./common.rc
197 . ./common.filter
198
199 # real QA test starts here
200 _supported_fs xfs
201 _supported_os Linux
202
203 _need_to_be_root
204 _require_scratch
205
206 unset SCRATCH_RTDEV
207 unset SCRATCH_LOGDEV
208
209 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
210
211 _add_scratch_fstab
212 _test_remount_rw
213 _test_remount_write
214
215 echo
216 echo "add noikeep to fstab for scratch"
217 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
218 _test_remount_rw
219
220 _putback_scratch_fstab
221 _test_remount_barrier
222
223 # success, all done
224 echo "*** done"
225 rm -f $seq.full
226 status=0