summaryrefslogtreecommitdiff
path: root/tests/xfs/050
blob: 2220e47016aa539c68cda8ef7cd8b1f73445867e (plain)
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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# FS QA Test No. 050
#
# Exercises basic XFS quota functionality
#       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
#
. ./common/preamble
_begin_fstest quota auto quick

# Import common functions.
. ./common/filter
. ./common/quota

# Override the default cleanup function.
_cleanup()
{
	cd /
	_scratch_unmount 2>/dev/null
	rm -f $tmp.*
}

# real QA test starts here
_supported_fs xfs

cp /dev/null $seqres.full
chmod a+rwx $seqres.full	# arbitrary users will write here

_require_scratch
_require_xfs_quota

_scratch_mkfs >/dev/null 2>&1
_scratch_mount
bsize=$(_get_file_block_size $SCRATCH_MNT)
_scratch_unmount

bsoft=$(( 200 * $bsize ))
bhard=$(( 1000 * $bsize ))
isoft=4
ihard=10

# The actual point at which limit enforcement takes place for the
# hard block limit is variable depending on filesystem blocksize,
# and iosize.  What we want to test is that the limit is enforced
# (ie. blksize less than limit but not unduly less - ~85% is kind)
# nowadays we actually get much closer to the limit before EDQUOT.
#
_filter_and_check_blks()
{
	perl -npe '
		if (/^\#'$id'\s+(\d+)/ && '$enforce') {
			$maximum = '$bhard';
			$minimum = '$bhard' * 85/100;
			$used = $1 * 1024;
			if (($used < $minimum || $used > $maximum) && '$noextsz') {
				printf(" URK %d: %d is out of range! [%d,%d]\n",
					'$id', $used, $minimum, $maximum);
			}
			s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
		}
	' | _filter_quota_report
}

_exercise()
{
	_scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
	cat $tmp.mkfs >>$seqres.full

	# keep the blocksize and data size for dd later
	. $tmp.mkfs

	_qmount

	# Figure out whether we're doing large allocations
	# (bail out if they're so large they stuff the test up)
	_test_inode_flag extsz-inherit $SCRATCH_MNT
	noextsz=$?
	extsize=`_test_inode_extsz $SCRATCH_MNT`
	[ $extsize -ge 512000 ] && \
		_notrun "Extent size hint is too large ($extsize bytes)"

	_qsetup $1

	echo "Using type=$type id=$id" >>$seqres.full
	echo
	echo "*** report no quota settings" | tee -a $seqres.full
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_quota_report | LC_COLLATE=POSIX sort -ru

	echo
	echo "*** report initial settings" | tee -a $seqres.full
	_file_as_id $SCRATCH_MNT/initme $id $type 1024 0
	echo "ls -l $SCRATCH_MNT" >>$seqres.full
	ls -l $SCRATCH_MNT >>$seqres.full
	$XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
		-c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
		-c "limit -$type isoft=$isoft ihard=$ihard $id" \
		$SCRATCH_DEV
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_quota_report | LC_COLLATE=POSIX sort -ru

	echo
	echo "*** push past the soft inode limit" | tee -a $seqres.full
	_file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
	_file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
	_file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
	_file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
	_qmount
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_quota_report | LC_COLLATE=POSIX sort -ru

	echo
	echo "*** push past the soft block limit" | tee -a $seqres.full
	_file_as_id $SCRATCH_MNT/softie $id $type $bsize 300
	_qmount
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_quota_report | LC_COLLATE=POSIX sort -ru

	echo
	# Note: for quota accounting (not enforcement), EDQUOT is not expected
	echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
	for i in 1 2 3 4 5 6 7 8 9 10 11 12
	do
		_file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
	done
	_qmount
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_quota_report | LC_COLLATE=POSIX sort -ru

	echo
	# Note: for quota accounting (not enforcement), EDQUOT is not expected
	echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
	_file_as_id $SCRATCH_MNT/softie $id $type $bsize 1200
	echo "ls -l $SCRATCH_MNT" >>$seqres.full
	ls -l $SCRATCH_MNT >>$seqres.full
	_qmount
	$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
		-c "repquota -birnN -$type" $SCRATCH_DEV |
		_filter_and_check_blks | LC_COLLATE=POSIX sort -ru

	echo
	echo "*** unmount"
	_scratch_unmount

}

cat >$tmp.projects <<EOF
1:$SCRATCH_MNT
EOF

cat >$tmp.projid <<EOF
root:0
scrach:1
EOF

projid_file="$tmp.projid"

echo "*** user"
_qmount_option "uquota"
_exercise u

echo "*** group"
_qmount_option "gquota"
_exercise g

echo "*** uqnoenforce"
_qmount_option "uqnoenforce"
_exercise uno

echo "*** gqnoenforce"
_qmount_option "gqnoenforce"
_exercise gno

echo "*** pquota"
_qmount_option "pquota"
_exercise p

echo "*** pqnoenforce"
_qmount_option "pqnoenforce"
_exercise pno

# success, all done
status=0
exit