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
169 [ $? -eq 0 ] || echo "mount failed unexpectedly!"
172 _try_scratch_mount -o remount,nobarrier
173 [ $? -eq 0 ] || _fail "remount nobarrier failed"
174 _check_mount rw nobarrier
176 _try_scratch_mount -o remount,barrier
177 [ $? -eq 0 ] || _fail "remount barrier failed"
184 # Example fstab entry
185 # /dev/sdb2 /mnt/scratch1 xfs defaults 0 0
189 # comment out any existing SCRATCH_DEV
190 $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
192 # add our fstab entry
193 echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
196 _modify_scratch_fstab()
200 # modify our fstab entry that we added
201 # modify opts by looking for last word which has non-space chars
202 $SED_PROG -i "s; [^ ]* 0 0 # $tag; $opts 0 0 # $tag;" /etc/fstab
205 _putback_scratch_fstab()
207 # uncomment out any existing SCRATCH_DEV
208 $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
210 # remove the one we added at the end
211 $SED_PROG -i "/# $tag/d" /etc/fstab
214 # get standard environment, filters and checks
219 # real QA test starts here
230 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
237 echo "add noikeep to fstab for scratch"
238 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
241 _putback_scratch_fstab
242 _test_remount_barrier