fstests: fix group list generation for whacky test names
[xfstests-dev.git] / tests / xfs / 189
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 189
6 #
7 # Test remount behaviour
8 # Initial motivation was for pv#985710 and pv#983964
9 #
10 # mount(8) adds all options from mtab and fstab to the mount command line.  So
11 # the filesystem either must not reject any option at all if it can't change it,
12 # or compare the value on the command line to the existing state and only reject
13 # it if it would change something that can't be changed.
14 #
15 # Test this behaviour by mounting a filesystem read-only with a non- default
16 # option and then try to remount it rw.
17 #
18 # note that mount(8) doesn't add the options when specifying both the device
19 # node and mount point, so test out the various mounting alternatives
20 #
21 # <---- Bbbzzzzzzztttt ---->
22 #
23 # Right, but the kernel /proc/mounts output in no way reflects what mount passes
24 # into the kernel, so the entire assumption of this test that what mount outputs
25 # is the same as what it inputs is completely wrong.
26 #
27 # Hence the test now checks to see if the expected options are in the mount
28 # options in /etc/mtab rather than looking for an exact match. Hence the tests
29 # check what we know should change, not what mount thinks has changed. As a
30 # result, the test now passes regardless of whether mount or the kernel controls
31 # the contents of /etc/mtab....
32 #
33 # <---- Normal programming is resumed ---->
34 #
35 #
36 . ./common/preamble
37 _begin_fstest mount auto quick
38
39 tag="added by qa $seq"
40
41 # Override the default cleanup function.
42 _cleanup()
43 {
44         cd /
45         _scratch_unmount 2>/dev/null
46         _putback_scratch_fstab
47         rm -f $tmp.*
48 }
49
50 _scratch_filter()
51 {
52         sed -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
53             -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
54             -e "s#,context.*s0\"##"
55 }
56
57 #
58 # the output from /proc/mounts in no way matches what mount puts into the kernel
59 # as options. Work around it as best possible by matching the strings passed in
60 # rather than assuming they are the only options that will be set. If they match
61 # output them to the output file so that the golden image and the filtering
62 # doesn't need to care about what options may or may not be present in /etc/mtab
63 #
64 _check_mount()
65 {
66         rw_or_ro=$1
67         expected_val=$2
68
69         [ -z "$expected_val" ] && expected_val=$1
70
71         _mount | grep $SCRATCH_MNT | _scratch_filter | \
72                 tee -a $seqres.full |
73                 grep $rw_or_ro | grep $expected_val > /dev/null
74         if [ $? -eq 0 ]; then
75                 echo -n "SCRATCH_DEV on SCRATCH_MNT type xfs ($rw_or_ro"
76                 if [ ! -z "$2" ]; then
77                         echo -n ",$2"
78                 fi
79                 echo ")"
80         fi
81 }
82
83 _test_remount_rw()
84 {
85         # use filestreams as a hopefully never default option
86         echo
87         echo "try remount ro,filestreams -> rw,filestreams"
88         echo
89         _try_scratch_mount -o ro,filestreams
90         [ $? -eq 0 ] || echo "ro,filestreams mount failed unexpectedly"
91         _check_mount ro filestreams
92
93         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
94                 echo "mounting given: $dev_mnt" | _scratch_filter
95                 _mount -o remount,rw,filestreams $dev_mnt
96                 [ $? -eq 0 ] || echo "remount rw failed"
97                 _check_mount rw filestreams
98         done
99
100         _scratch_unmount
101
102         # remount ignores attr2, and noattr2 mount option does does not result
103         # in any "attr2" specific option in /proc/mounts, so we can only check
104         # for ro/rw here.
105         echo
106         echo "try remount ro,noattr2 -> rw,attr2"
107         echo
108         _try_scratch_mount -o ro,noattr2
109         [ $? -eq 0 ] || echo "ro,noattr2 mount failed unexpectedly"
110         _check_mount ro
111
112         for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
113                 echo "mounting given: $dev_mnt" | _scratch_filter
114                 _mount -o remount,rw,attr2 $dev_mnt
115                 [ $? -eq 0 ] || echo "remount rw,attr2 failed"
116                 _check_mount rw
117         done
118
119         _scratch_unmount
120 }
121
122 #
123 # make sure we really can write to a filesystem after remount,rw
124 #
125 _test_remount_write()
126 {
127         echo
128         echo "try touching file after remount ro -> rw with options"
129         echo
130         _try_scratch_mount
131         [ $? -eq 0 ] || echo "mount (1) failed unexpectedly"
132
133         touch $SCRATCH_MNT/foobar
134         [ $? -eq 0 ] || echo "touch (1) failed unexpectedly"
135
136         _scratch_unmount
137
138         _try_scratch_mount -o ro
139         [ $? -eq 0 ] || echo "mount (2) failed unexpectedly"
140
141         _mount -o remount,rw,filestreams $SCRATCH_MNT
142         [ $? -eq 0 ] || echo "remount failed unexpectedly"
143
144         touch $SCRATCH_MNT/foobar
145         [ $? -eq 0 ] || echo "touch (2) failed unexpectedly"
146
147         _scratch_unmount
148 }
149
150 #
151 # barrier is the only option we can change besides ro<->rw which is partially
152 # handled by the VFS and tested elsewhere.  Make sure mount accepts going
153 # from barrier (which also is the default) to nobarrier and back.
154 #
155 _test_remount_barrier()
156 {
157         echo
158         echo "Do remount barrier tests"
159         echo
160
161         # mention barrier explicitly even if it's currently the default just to be sure
162         _try_scratch_mount -o barrier > $tmp.barriermount 2>&1
163
164         # If the kernel doesn't recognize 'barrier' as a mount option then
165         # just fake the output.  The barrier option was removed in 4.19.
166         if grep -q "bad option" $tmp.barriermount; then
167                 cat << ENDL
168 SCRATCH_DEV on SCRATCH_MNT type xfs (rw)
169 SCRATCH_DEV on SCRATCH_MNT type xfs (rw,nobarrier)
170 SCRATCH_DEV on SCRATCH_MNT type xfs (rw)
171 ENDL
172                 return
173         fi
174
175         [ $? -eq 0 ] || echo "mount failed unexpectedly!"
176         _check_mount rw
177
178         _try_scratch_mount -o remount,nobarrier
179         [ $? -eq 0 ] || _fail "remount nobarrier failed"
180         _check_mount rw nobarrier
181
182         _try_scratch_mount -o remount,barrier
183         [ $? -eq 0 ] || _fail "remount barrier failed"
184         _check_mount rw
185
186         _scratch_unmount
187 }
188
189 #
190 # Example fstab entry
191 # /dev/sdb2            /mnt/scratch1        xfs       defaults 0 0
192 #
193 _add_scratch_fstab()
194 {
195         # comment out any existing SCRATCH_DEV
196         $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
197
198         # add our fstab entry
199         echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
200 }
201
202 _modify_scratch_fstab()
203 {
204         opts=$1
205
206         # modify our fstab entry that we added
207         # modify opts by looking for last word which has non-space chars
208         $SED_PROG -i "s; [^ ]* 0 0 # $tag; $opts 0 0 # $tag;" /etc/fstab
209 }
210
211 _putback_scratch_fstab()
212 {
213         # uncomment out any existing SCRATCH_DEV
214         $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
215
216         # remove the one we added at the end
217         $SED_PROG -i "/# $tag/d" /etc/fstab
218 }
219
220 # Import common functions.
221 . ./common/filter
222 . ./common/attr
223
224 # real QA test starts here
225 _supported_fs xfs
226
227 _require_no_realtime
228 _require_scratch
229 _require_noattr2
230
231 unset SCRATCH_RTDEV
232 unset SCRATCH_LOGDEV
233
234 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
235
236 _add_scratch_fstab
237 _test_remount_rw
238 _test_remount_write
239
240 echo
241 echo "add noikeep to fstab for scratch"
242 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
243 _test_remount_rw
244
245 _putback_scratch_fstab
246 _test_remount_barrier
247
248 # success, all done
249 echo "*** done"
250 status=0