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