xfstests: include test subdirectory support
[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
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 trap "_cleanup; exit \$status" 0 1 2 3 15
33 tag="added by qa $seq"
34
35 _cleanup()
36 {
37         cd /
38         umount $SCRATCH_MNT 2>/dev/null
39         _putback_scratch_fstab
40         rm -f $tmp.*
41 }
42
43 _scratch_filter()
44 {
45         sed -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
46             -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
47             -e "s#,context.*s0\"##"
48 }
49
50 _check_mount()
51 {
52         # assumes that we don't have extra ops in fstab
53         _mount | grep $SCRATCH_MNT | _scratch_filter
54 }
55
56 #
57 # mount(8) adds all options from mtab and fstab to the mount command
58 # line.  So the filesystem either must not reject any option at all
59 # if it can't change it, or compare the value on the command line
60 # to the existing state and only reject it if it would change
61 # something that can't be changed.
62 #
63 # Test this behaviour by mounting a filesystem read-only with a non-
64 # default option and then try to remount it rw.
65 #
66 # note that mount(8) doesn't add the options when specifying both the
67 # device node and mount point, so test out the various mounting
68 # alternatives
69 #
70 _test_remount_rw()
71 {
72         # use filestreams as a hopefully never default option
73         echo
74         echo "try remount ro,filestreams -> rw,filestreams"
75         echo
76         _scratch_mount -o ro,filestreams
77         [ $? -eq 0 ] || echo "ro,filestreams mount failed unexpectedly"
78         _check_mount
79
80         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
81                 echo "mounting given: $dev_mnt" | _scratch_filter
82                 _mount -o remount,rw $dev_mnt
83                 [ $? -eq 0 ] || echo "remount rw failed"
84                 _check_mount
85         done
86
87         umount $SCRATCH_MNT
88
89         echo
90         echo "try remount ro,noattr2 -> rw,attr2"
91         echo
92         _scratch_mount -o ro,noattr2
93         [ $? -eq 0 ] || echo "ro,noattr2 mount failed unexpectedly"
94         _check_mount
95
96         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
97                 echo "mounting given: $dev_mnt" | _scratch_filter
98                 _mount -o remount,rw,attr2 $dev_mnt
99                 [ $? -eq 0 ] || echo "remount rw,attr2 failed"
100                 _check_mount
101         done
102
103         umount $SCRATCH_MNT
104 }
105
106 #
107 # make sure we really can write to a filesystem after remount,rw
108 #
109 _test_remount_write()
110 {
111         echo
112         echo "try touching file after remount ro -> rw with options"
113         echo
114         _scratch_mount
115         [ $? -eq 0 ] || echo "mount (1) failed unexpectedly"
116
117         touch $SCRATCH_MNT/foobar
118         [ $? -eq 0 ] || echo "touch (1) failed unexpectedly"
119
120         umount $SCRATCH_MNT
121
122         _scratch_mount -o ro
123         [ $? -eq 0 ] || echo "mount (2) failed unexpectedly"
124
125         _mount -o remount,rw,filestreams $SCRATCH_MNT
126         [ $? -eq 0 ] || echo "remount failed unexpectedly"
127
128         touch $SCRATCH_MNT/foobar
129         [ $? -eq 0 ] || echo "touch (2) failed unexpectedly"
130
131         umount $SCRATCH_MNT
132 }
133
134 #
135 # barrier is the only option we can change besides ro<->rw which is partially
136 # handled by the VFS and tested elsewhere.  Make sure mount accepts going
137 # from barrier (which also is the default) to nobarrier and back.
138 #
139 _test_remount_barrier()
140 {
141         echo
142         echo "Do remount barrier tests"
143         echo
144
145         # mention barrier explicitly even if it's currently the default just to be sure
146         _scratch_mount -o barrier
147         [ $? -eq 0 ] || echo "mount failed unexpectedly!"
148         _check_mount
149
150         _scratch_mount -o remount,nobarrier
151         [ $? -eq 0 ] || _fail "remount nobarrier failed"
152         _check_mount
153
154         _scratch_mount -o remount,barrier
155         [ $? -eq 0 ] || _fail "remount barrier failed"
156         _check_mount
157
158         umount $SCRATCH_MNT
159 }
160
161
162 #
163 # Example fstab entry
164 # /dev/sdb2            /mnt/scratch1        xfs       defaults 0 0
165 #
166 _add_scratch_fstab()
167 {
168         # comment out any existing SCRATCH_DEV
169         $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
170
171         # add our fstab entry
172         echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
173 }
174
175 _modify_scratch_fstab()
176 {
177         opts=$1
178
179         # modify our fstab entry that we added
180         # modify opts by looking for last word which has non-space chars
181         $SED_PROG -i "s; [^ ]* 0 0 # $tag; $opts 0 0 # $tag;" /etc/fstab
182 }
183
184 _putback_scratch_fstab()
185 {
186         # uncomment out any existing SCRATCH_DEV
187         $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
188
189         # remove the one we added at the end
190         $SED_PROG -i "/# $tag/d" /etc/fstab
191 }
192
193 # get standard environment, filters and checks
194 . ./common.rc
195 . ./common.filter
196
197 # real QA test starts here
198 _supported_fs xfs
199 _supported_os Linux
200
201 _need_to_be_root
202 _require_scratch
203
204 unset SCRATCH_RTDEV
205 unset SCRATCH_LOGDEV
206
207 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
208
209 _add_scratch_fstab
210 _test_remount_rw
211 _test_remount_write
212
213 echo
214 echo "add noikeep to fstab for scratch"
215 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
216 _test_remount_rw
217
218 _putback_scratch_fstab
219 _test_remount_barrier
220
221 # success, all done
222 echo "*** done"
223 rm -f $seq.full
224 status=0