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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (c) 2021 Christian Brauner <christian.brauner@ubuntu.com>
# All Rights Reserved.
#
# FS QA Test No. 152
#
# Exercise basic xfs_quota functionality (user/group/project quota)
# Use of "sync" mount option here is an attempt to get deterministic
# allocator behaviour.
#
. ./common/preamble
_begin_fstest auto quick quota idmapped
wipe_mounts()
{
umount "${SCRATCH_MNT}/idmapped" >/dev/null 2>&1
_scratch_unmount >/dev/null 2>&1
}
# Override the default cleanup function.
_cleanup()
{
cd /
wipe_mounts
rm -f $tmp.*
}
# Import common functions.
. ./common/filter
. ./common/quota
# real QA test starts here
_supported_fs xfs
_require_idmapped_mounts
_require_test_program "vfs/mount-idmapped"
_require_scratch
_require_xfs_quota
_require_user fsgqa
_require_user fsgqa2
_require_group fsgqa
_require_group fsgqa2
_scratch_mkfs_xfs >>$seqres.full 2>&1
uqid=`id -u fsgqa`
gqid=`id -g fsgqa`
uqid2=`id -u fsgqa2`
gqid2=`id -g fsgqa2`
pqid=10
cat >$tmp.projects <<EOF
$pqid:$SCRATCH_MNT
EOF
cat >$tmp.projid <<EOF
root:0
fsgqa:$pqid
EOF
create_files_unmapped()
{
local bs=$1
local inum=$2
echo "Using type=$type id=$id" >> $seqres.full
for ((i=0; i<$((inum-1)); i++)); do
_file_as_id $SCRATCH_MNT/unmapped/inode$i $id $type 1024 0
done
_file_as_id $SCRATCH_MNT/unmapped/block $id $type $bs 1
}
create_files_idmapped()
{
local bs=$1
local inum=$2
echo "Using type=$type id=$id2" >> $seqres.full
for ((i=0; i<$((inum-1)); i++)); do
_file_as_id $SCRATCH_MNT/idmapped/inode$i $id2 $type 1024 0
done
_file_as_id $SCRATCH_MNT/idmapped/block $id2 $type $bs 1
}
clean_files()
{
rm -rf $SCRATCH_MNT/unmapped 2>/dev/null
rm -rf $SCRATCH_MNT/idmapped 2>/dev/null
rm -rf $tmp.quot 2>/dev/null
rm -rf $tmp.quota 2>/dev/null
}
filter_quot()
{
_filter_quota | grep -v "root \|\#0 " \
| sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
}
filter_report()
{
_filter_quota | grep -v "^root \|^\#0 " \
| sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
}
filter_quota()
{
_filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
-e "/Disk quotas for/s/#[0-9]*/#ID/g"
}
filter_state()
{
_filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
-e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
-e "/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]//g" \
-e '/max warnings:/d'
}
test_quot()
{
local opt="$*"
echo "checking quot command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
}
test_report()
{
local opt="$*"
echo "checking report command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "report -$type $opt -bi" \
$SCRATCH_MNT | filter_report
}
test_quota()
{
local opt="$*"
echo "checking quota command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "quota -$type $opt -bi $id" \
$SCRATCH_MNT | filter_quota
}
test_limit()
{
local bs=$1
local bh=$2
local is=$3
local ih=$4
echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
-c "limit -$type isoft=$is ihard=$ih fsgqa" \
$SCRATCH_MNT
# let the timer day transition happen
sleep 2
}
test_timer()
{
echo "checking timer command (type=$type)"
# set 3days+1h for time won't become 2days soon
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "timer -$type -bi 73h" \
$SCRATCH_MNT | _filter_scratch
}
test_disable()
{
echo "checking disable command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "disable -$type -v" \
$SCRATCH_MNT | filter_state
}
test_enable()
{
echo "checking enable command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "enable -$type -v" $SCRATCH_MNT | filter_state
}
test_off()
{
echo "checking off command (type=$type)"
_scratch_unmount
_qmount_option ""
_qmount
}
test_remove()
{
echo "checking remove command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "remove -$type -v" \
$SCRATCH_MNT | _filter_scratch
}
test_state()
{
echo "checking state command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "state -$type" $SCRATCH_MNT | filter_state
}
test_dump()
{
echo "checking dump command (type=$type)"
rm -f $tmp.backup 2>>/dev/null
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "dump -$type -f $tmp.backup" \
$SCRATCH_MNT | _filter_scratch
}
test_restore()
{
echo "checking restore command (type=$type)"
$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
-c "restore -$type -f $tmp.backup" \
$SCRATCH_MNT | _filter_scratch
}
wipe_scratch()
{
wipe_mounts
_scratch_mkfs_xfs >>$seqres.full 2>&1
}
qmount_idmapped()
{
wipe_mounts
_try_scratch_mount || _fail "qmount failed"
mkdir -p "${SCRATCH_MNT}/unmapped"
mkdir -p "${SCRATCH_MNT}/idmapped"
$here/src/idmapped-mounts/mount-idmapped \
--map-mount b:$id:$id2:1 \
--map-mount b:0:0:1 \
"$SCRATCH_MNT/unmapped" "$SCRATCH_MNT/idmapped" || _fail "mount-idmapped failed"
chmod ugo+rwx $SCRATCH_MNT
chmod ugo+rwx $SCRATCH_MNT/unmapped
chmod ugo+rwx $SCRATCH_MNT/idmapped
}
test_xfs_quota()
{
local quota_options="$1"
# init quota
echo "init quota limit and timer, and dump it"
if [ "$idmapped" -eq 1 ]; then
echo "create_files_idmapped 1024k 15"; create_files_idmapped 1024k 15
else
echo "create_files_unmapped 1024k 15"; create_files_unmapped 1024k 15
fi
echo "quota remount"; qmount_idmapped
echo ; test_quot
echo ; test_timer
echo ; test_limit 512k 2048k 10 20
echo ; test_dump
# report options test
echo "report options test"
echo ; test_report
echo "-N option"; test_report -N
echo "-L -U options"; test_report -L $id -U $id
echo "-t option"; test_report -t
echo "-n option"; test_report -n
echo "-h option"; test_report -h
# quot options test
echo "quot options test"
echo ; test_quot
echo "-f option"; test_quot -f $tmp.quot
cat $tmp.quot | filter_quot
echo "-n option"; test_quot -n
# quota options test
echo ; test_quota
echo "-f option"; test_quota -f $tmp.quota
cat $tmp.quota | filter_quota
echo "-N option"; test_quota -N
echo "-n option"; test_quota -n
echo "-h option"; test_quota -h
# disable/enable test
echo "disable quota"
echo ; test_disable
echo ; test_report -N
echo "expect a remove error at here"; test_remove
echo ; test_enable
echo ; test_report -N
# off and remove test
echo "off and remove test"
echo ; test_limit 100m 100m 100 100
echo ; test_quota -N
echo ; test_off
echo ; test_state
echo ; test_remove
echo ; test_report -N
echo "quota remount"
_qmount_option "$quota_options"
_qmount
qmount_idmapped
echo ; test_report -N
# restore test
echo "restore quota"
echo ; test_restore
echo ; test_report -N
echo ; test_state
echo "cleanup files"; clean_files
}
echo "----------------------- uquota,sync,unmapped ---------------------------"
wipe_scratch
_qmount_option "uquota,sync"
type=u
id=$uqid
id2=$uqid2
idmapped=0
qmount_idmapped
test_xfs_quota "uquota,sync"
echo "----------------------- uquota,sync,idmapped ---------------------------"
wipe_scratch
_qmount_option "uquota,sync"
type=u
id=$uqid
id2=$uqid2
idmapped=1
qmount_idmapped
test_xfs_quota "uquota,sync"
echo "----------------------- gquota,sync,unmapped ---------------------------"
wipe_scratch
_qmount_option "gquota,sync"
type=g
id=$gqid
id2=$gqid2
idmapped=0
qmount_idmapped
test_xfs_quota "gquota,sync"
echo "----------------------- gquota,sync,idmapped ---------------------------"
wipe_scratch
_qmount_option "gquota,sync"
type=g
id=$gqid
id2=$gqid2
idmapped=1
qmount_idmapped
test_xfs_quota "gquota,sync"
wipe_mounts
# success, all done
status=0
exit
|