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