xref: /freebsd/contrib/netbsd-tests/fs/ffs/t_setquota.sh (revision cd0d51baaa4509a1db83251a601d34404d20c990)
1# $NetBSD: t_setquota.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
2#
3#  Copyright (c) 2011 Manuel Bouyer
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions
8#  are met:
9#  1. Redistributions of source code must retain the above copyright
10#     notice, this list of conditions and the following disclaimer.
11#  2. Redistributions in binary form must reproduce the above copyright
12#     notice, this list of conditions and the following disclaimer in the
13#     documentation and/or other materials provided with the distribution.
14#
15#  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25#  POSSIBILITY OF SUCH DAMAGE.
26#
27
28for e in le be; do
29  for v in 1 2; do
30    for q in "user" "group"; do
31      test_case_root set_${e}_${v}_${q} set_quota \
32	 "set quota with ${q} enabled" -b ${e} ${v} ${q}
33      test_case_root set_new_${e}_${v}_${q} set_quota_new \
34	 "set quota for new id with ${q} enabled" -b ${e} ${v} ${q}
35      test_case_root set_default_${e}_${v}_${q} set_quota_default \
36	 "set default quota with ${q} enabled" -b ${e} ${v} ${q}
37    done
38    test_case_root set_${e}_${v}_"both" set_quota \
39	 "set quota with both enabled" -b ${e} ${v} "both"
40    test_case_root set_new_${e}_${v}_"both" set_quota_new \
41	 "set quota for new id with both enabled" -b ${e} ${v} "both"
42    test_case_root set_new_${e}_${v}_"both_log" set_quota_new \
43	 "set quota for new id with both enabled, WAPBL" -bl ${e} ${v} "both"
44    test_case_root set_default_${e}_${v}_"both" set_quota_default \
45	 "set default quota with both enabled" -b ${e} ${v} "both"
46  done
47done
48
49set_quota()
50{
51	create_ffs_server $*
52	local q=$4
53	local expect
54	local fail
55
56	case ${q} in
57	user)
58		expect=u
59		fail=g
60		;;
61	group)
62		expect=g
63		fail=u
64		;;
65	both)
66		expect="u g"
67		fail=""
68		;;
69	*)
70		atf_fail "wrong quota type"
71		;;
72	esac
73
74#check that we can set the expected quota
75	for q in ${expect} ; do
76		local id=$(id -${q})
77		atf_check -s exit:0 \
78		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
79		   -t 2W/3D ${id}
80		atf_check -s exit:0 \
81-o "match:/mnt        0       10    40960  2weeks       1      20   51200   3days" \
82-o "match:Disk quotas for .*: $" \
83		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
84		atf_check -s exit:0 \
85-o "match:--        0       10    40960                1      20   51200" \
86		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
87	done
88
89#check that we do not get positive reply for non-expected quota
90	for q in ${fail} ; do
91		local id=$(id -${q})
92		atf_check -s exit:0 \
93		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
94		atf_check -s exit:0 -o "not-match:/mnt" \
95		    -o "not-match:Disk quotas for .*: $" \
96		    -o "match:Disk quotas for .*: none$" \
97		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
98		atf_check -s exit:0 \
99-o "not-match:--        0        -        -" \
100		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
101	done
102	rump_quota_shutdown
103}
104
105set_quota_new()
106{
107	create_ffs_server $*
108	local q=$4
109	local expect
110	local fail
111
112	case ${q} in
113	user)
114		expect=u
115		fail=g
116		;;
117	group)
118		expect=g
119		fail=u
120		;;
121	both)
122		expect="u g"
123		fail=""
124		;;
125	*)
126		atf_fail "wrong quota type"
127		;;
128	esac
129
130#check that we can set the expected quota
131	for q in ${expect} ; do
132		local id=1
133		atf_check -s exit:0 \
134		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
135		   -t 120W/255D ${id}
136		atf_check -s exit:0 \
137-o "match:/mnt        0       10    40960  2years       0      20   51200 9months" \
138-o "match:Disk quotas for .*: $" \
139		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
140	done
141
142#check that we do not get positive reply for non-expected quota
143	for q in ${fail} ; do
144		local id=$(id -${q})
145		atf_check -s exit:0 \
146		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
147		atf_check -s exit:0 -o "not-match:/mnt" \
148		    -o "not-match:Disk quotas for .*: $" \
149		    -o "match:Disk quotas for .*: none$" \
150		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
151	done
152	rump_quota_shutdown
153}
154
155set_quota_default()
156{
157	create_ffs_server $*
158	local q=$4
159	local expect
160	local fail
161
162	case ${q} in
163	user)
164		expect=u
165		fail=g
166		;;
167	group)
168		expect=g
169		fail=u
170		;;
171	both)
172		expect="u g"
173		fail=""
174		;;
175	*)
176		atf_fail "wrong quota type"
177		;;
178	esac
179
180#check that we can set the expected quota
181	for q in ${expect} ; do
182		local id="-d"
183		atf_check -s exit:0 \
184		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
185		   -t 2H2M/3540 ${id}
186		atf_check -s exit:0 \
187-o "match:/mnt        0       10    40960     2:2       0      20   51200      59" \
188-o "match:Default (user|group) disk quotas: $" \
189		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
190	done
191
192#check that we do not get positive reply for non-expected quota
193	for q in ${fail} ; do
194		local id="-d"
195		atf_check -s exit:0 \
196		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
197		atf_check -s exit:0 -o "not-match:/mnt" \
198		    -o "not-match:Default (user|group) disk quotas: $" \
199		    -o "match:Default (user|group) disk quotas: none$" \
200		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
201	done
202	rump_quota_shutdown
203}
204