2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
7 # Test remount behaviour
8 # Initial motivation was for pv#985710 and pv#983964
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.
15 # Test this behaviour by mounting a filesystem read-only with a non- default
16 # option and then try to remount it rw.
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
21 # <---- Bbbzzzzzzztttt ---->
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.
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....
33 # <---- Normal programming is resumed ---->
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
42 status=1 # failure is the default!
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44 tag="added by qa $seq"
51 _scratch_unmount 2>/dev/null
52 _putback_scratch_fstab
58 sed -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
59 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
60 -e "s#,context.*s0\"##"
64 # the output from /proc/mounts in no way matches what mount puts into the kernel
65 # as options. Work around it as best possible by matching the strings passed in
66 # rather than assuming they are the only options that will be set. If they match
67 # output them to the output file so that the golden image and the filtering
68 # doesn't need to care about what options may or may not be present in /etc/mtab
75 [ -z "$expected_val" ] && expected_val=$1
77 _mount | grep $SCRATCH_MNT | _scratch_filter | \
79 grep $rw_or_ro | grep $expected_val > /dev/null
81 echo -n "SCRATCH_DEV on SCRATCH_MNT type xfs ($rw_or_ro"
82 if [ ! -z "$2" ]; then
91 # use filestreams as a hopefully never default option
93 echo "try remount ro,filestreams -> rw,filestreams"
95 _try_scratch_mount -o ro,filestreams
96 [ $? -eq 0 ] || echo "ro,filestreams mount failed unexpectedly"
97 _check_mount ro filestreams
99 for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
100 echo "mounting given: $dev_mnt" | _scratch_filter
101 _mount -o remount,rw,filestreams $dev_mnt
102 [ $? -eq 0 ] || echo "remount rw failed"
103 _check_mount rw filestreams
108 # remount ignores attr2, and noattr2 mount option does does not result
109 # in any "attr2" specific option in /proc/mounts, so we can only check
112 echo "try remount ro,noattr2 -> rw,attr2"
114 _try_scratch_mount -o ro,noattr2
115 [ $? -eq 0 ] || echo "ro,noattr2 mount failed unexpectedly"
118 for dev_mnt in $SCRATCH_DEV $SCRATCH_MNT "$SCRATCH_DEV $SCRATCH_MNT"; do
119 echo "mounting given: $dev_mnt" | _scratch_filter
120 _mount -o remount,rw,attr2 $dev_mnt
121 [ $? -eq 0 ] || echo "remount rw,attr2 failed"
129 # make sure we really can write to a filesystem after remount,rw
131 _test_remount_write()
134 echo "try touching file after remount ro -> rw with options"
137 [ $? -eq 0 ] || echo "mount (1) failed unexpectedly"
139 touch $SCRATCH_MNT/foobar
140 [ $? -eq 0 ] || echo "touch (1) failed unexpectedly"
144 _try_scratch_mount -o ro
145 [ $? -eq 0 ] || echo "mount (2) failed unexpectedly"
147 _mount -o remount,rw,filestreams $SCRATCH_MNT
148 [ $? -eq 0 ] || echo "remount failed unexpectedly"
150 touch $SCRATCH_MNT/foobar
151 [ $? -eq 0 ] || echo "touch (2) failed unexpectedly"
157 # barrier is the only option we can change besides ro<->rw which is partially
158 # handled by the VFS and tested elsewhere. Make sure mount accepts going
159 # from barrier (which also is the default) to nobarrier and back.
161 _test_remount_barrier()
164 echo "Do remount barrier tests"
167 # mention barrier explicitly even if it's currently the default just to be sure
168 _try_scratch_mount -o barrier > $tmp.barriermount 2>&1
170 # If the kernel doesn't recognize 'barrier' as a mount option then
171 # just fake the output. The barrier option was removed in 4.19.
172 if grep -q "bad option" $tmp.barriermount; then
174 SCRATCH_DEV on SCRATCH_MNT type xfs (rw)
175 SCRATCH_DEV on SCRATCH_MNT type xfs (rw,nobarrier)
176 SCRATCH_DEV on SCRATCH_MNT type xfs (rw)
181 [ $? -eq 0 ] || echo "mount failed unexpectedly!"
184 _try_scratch_mount -o remount,nobarrier
185 [ $? -eq 0 ] || _fail "remount nobarrier failed"
186 _check_mount rw nobarrier
188 _try_scratch_mount -o remount,barrier
189 [ $? -eq 0 ] || _fail "remount barrier failed"
196 # Example fstab entry
197 # /dev/sdb2 /mnt/scratch1 xfs defaults 0 0
201 # comment out any existing SCRATCH_DEV
202 $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
204 # add our fstab entry
205 echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
208 _modify_scratch_fstab()
212 # modify our fstab entry that we added
213 # modify opts by looking for last word which has non-space chars
214 $SED_PROG -i "s; [^ ]* 0 0 # $tag; $opts 0 0 # $tag;" /etc/fstab
217 _putback_scratch_fstab()
219 # uncomment out any existing SCRATCH_DEV
220 $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
222 # remove the one we added at the end
223 $SED_PROG -i "/# $tag/d" /etc/fstab
226 # get standard environment, filters and checks
231 # real QA test starts here
241 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
248 echo "add noikeep to fstab for scratch"
249 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
252 _putback_scratch_fstab
253 _test_remount_barrier