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