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 _begin_fstest mount auto quick
39 tag="added by qa $seq"
41 # Override the default cleanup function.
45 _scratch_unmount 2>/dev/null
46 _putback_scratch_fstab
52 sed -e "s#$SCRATCH_DEV#SCRATCH_DEV#" \
53 -e "s#$SCRATCH_MNT#SCRATCH_MNT#" \
54 -e "s#,context.*s0\"##"
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
69 [ -z "$expected_val" ] && expected_val=$1
71 _mount | grep $SCRATCH_MNT | _scratch_filter | \
73 grep $rw_or_ro | grep $expected_val > /dev/null
75 echo -n "SCRATCH_DEV on SCRATCH_MNT type xfs ($rw_or_ro"
76 if [ ! -z "$2" ]; then
85 # use filestreams as a hopefully never default option
87 echo "try remount ro,filestreams -> rw,filestreams"
89 _try_scratch_mount -o ro,filestreams
90 [ $? -eq 0 ] || echo "ro,filestreams mount failed unexpectedly"
91 _check_mount ro filestreams
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
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
106 echo "try remount ro,noattr2 -> rw,attr2"
108 _try_scratch_mount -o ro,noattr2
109 [ $? -eq 0 ] || echo "ro,noattr2 mount failed unexpectedly"
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"
123 # make sure we really can write to a filesystem after remount,rw
125 _test_remount_write()
128 echo "try touching file after remount ro -> rw with options"
131 [ $? -eq 0 ] || echo "mount (1) failed unexpectedly"
133 touch $SCRATCH_MNT/foobar
134 [ $? -eq 0 ] || echo "touch (1) failed unexpectedly"
138 _try_scratch_mount -o ro
139 [ $? -eq 0 ] || echo "mount (2) failed unexpectedly"
141 _mount -o remount,rw,filestreams $SCRATCH_MNT
142 [ $? -eq 0 ] || echo "remount failed unexpectedly"
144 touch $SCRATCH_MNT/foobar
145 [ $? -eq 0 ] || echo "touch (2) failed unexpectedly"
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.
155 _test_remount_barrier()
158 echo "Do remount barrier tests"
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
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
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)
175 [ $? -eq 0 ] || echo "mount failed unexpectedly!"
178 _try_scratch_mount -o remount,nobarrier
179 [ $? -eq 0 ] || _fail "remount nobarrier failed"
180 _check_mount rw nobarrier
182 _try_scratch_mount -o remount,barrier
183 [ $? -eq 0 ] || _fail "remount barrier failed"
190 # Example fstab entry
191 # /dev/sdb2 /mnt/scratch1 xfs defaults 0 0
195 # comment out any existing SCRATCH_DEV
196 $SED_PROG -i "s;$SCRATCH_DEV;#$SCRATCH_DEV;" /etc/fstab
198 # add our fstab entry
199 echo "$SCRATCH_DEV $SCRATCH_MNT xfs defaults 0 0 # $tag" >> /etc/fstab
202 _modify_scratch_fstab()
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
211 _putback_scratch_fstab()
213 # uncomment out any existing SCRATCH_DEV
214 $SED_PROG -i "s;#$SCRATCH_DEV;$SCRATCH_DEV;" /etc/fstab
216 # remove the one we added at the end
217 $SED_PROG -i "/# $tag/d" /etc/fstab
220 # Import common functions.
224 # real QA test starts here
234 _scratch_mkfs_xfs | _filter_mkfs 2>/dev/null
241 echo "add noikeep to fstab for scratch"
242 _modify_scratch_fstab noikeep # noikeep is not default for non dmapi
245 _putback_scratch_fstab
246 _test_remount_barrier