xref: /minix3/tests/fs/ffs/t_miscquota.sh (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc# $NetBSD: t_miscquota.sh,v 1.8 2013/01/22 06:24:11 dholland Exp $
2*11be35a1SLionel Sambuc#
3*11be35a1SLionel Sambuc#  Copyright (c) 2011 Manuel Bouyer
4*11be35a1SLionel Sambuc#  All rights reserved.
5*11be35a1SLionel Sambuc#
6*11be35a1SLionel Sambuc#  Redistribution and use in source and binary forms, with or without
7*11be35a1SLionel Sambuc#  modification, are permitted provided that the following conditions
8*11be35a1SLionel Sambuc#  are met:
9*11be35a1SLionel Sambuc#  1. Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc#     notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc#  2. Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc#     notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc#     documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc#
15*11be35a1SLionel Sambuc#  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16*11be35a1SLionel Sambuc#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17*11be35a1SLionel Sambuc#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18*11be35a1SLionel Sambuc#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19*11be35a1SLionel Sambuc#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*11be35a1SLionel Sambuc#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*11be35a1SLionel Sambuc#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*11be35a1SLionel Sambuc#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*11be35a1SLionel Sambuc#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*11be35a1SLionel Sambuc#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*11be35a1SLionel Sambuc#  POSSIBILITY OF SUCH DAMAGE.
26*11be35a1SLionel Sambuc#
27*11be35a1SLionel Sambuc
28*11be35a1SLionel Sambuctest_case_root walk_list_user quota_walk_list \
29*11be35a1SLionel Sambuc    "walk user quota list over several disk blocks" -b le 1 user
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuctest_case_root psnapshot_user quota_snap \
32*11be35a1SLionel Sambuc    "create a persistent shapshot of quota-enabled fs, and do some writes" \
33*11be35a1SLionel Sambuc    -b le 1 user
34*11be35a1SLionel Sambuc
35*11be35a1SLionel Sambuctest_case_root npsnapshot_user quota_snap \
36*11be35a1SLionel Sambuc    "create a non-persistent shapshot of quota-enabled fs, and do some writes" \
37*11be35a1SLionel Sambuc    -boL le 1 user
38*11be35a1SLionel Sambuc
39*11be35a1SLionel Sambuctest_case_root psnapshot_unconf_user quota_snap \
40*11be35a1SLionel Sambuc    "create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
41*11be35a1SLionel Sambuc    -boC le 1 user
42*11be35a1SLionel Sambuc
43*11be35a1SLionel Sambuctest_case_root npsnapshot_unconf_user quota_snap \
44*11be35a1SLionel Sambuc    "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
45*11be35a1SLionel Sambuc    -boLC le 1 user
46*11be35a1SLionel Sambuc
47*11be35a1SLionel Sambuctest_case log_unlink quota_log \
48*11be35a1SLionel Sambuc    "an unlinked file cleaned by the log replay should update quota" \
49*11be35a1SLionel Sambuc    -l le 1 user
50*11be35a1SLionel Sambuc
51*11be35a1SLionel Sambuctest_case log_unlink_remount quota_log \
52*11be35a1SLionel Sambuc    "an unlinked file cleaned by the log replay after remount" \
53*11be35a1SLionel Sambuc    -oRL le 1 user
54*11be35a1SLionel Sambuc
55*11be35a1SLionel Sambuc
56*11be35a1SLionel Sambuctest_case_root default_deny_user quota_default_deny \
57*11be35a1SLionel Sambuc    "new quota entry denied by default entry" 5 -b le 1 user
58*11be35a1SLionel Sambuc
59*11be35a1SLionel Sambuctest_case_root default_deny_user_big quota_default_deny \
60*11be35a1SLionel Sambuc    "new quota entry denied by default entry, with list on more than one block" 5000 -b le 1 user
61*11be35a1SLionel Sambuc
62*11be35a1SLionel Sambuc
63*11be35a1SLionel Sambucquota_walk_list()
64*11be35a1SLionel Sambuc{
65*11be35a1SLionel Sambuc	create_ffs_server $*
66*11be35a1SLionel Sambuc	local q=$4
67*11be35a1SLionel Sambuc	local expect
68*11be35a1SLionel Sambuc
69*11be35a1SLionel Sambuc	case ${q} in
70*11be35a1SLionel Sambuc	user)
71*11be35a1SLionel Sambuc		expect=u
72*11be35a1SLionel Sambuc		fail=g
73*11be35a1SLionel Sambuc		;;
74*11be35a1SLionel Sambuc	group)
75*11be35a1SLionel Sambuc		expect=g
76*11be35a1SLionel Sambuc		fail=u
77*11be35a1SLionel Sambuc		;;
78*11be35a1SLionel Sambuc	*)
79*11be35a1SLionel Sambuc		atf_fail "wrong quota type"
80*11be35a1SLionel Sambuc		;;
81*11be35a1SLionel Sambuc	esac
82*11be35a1SLionel Sambuc
83*11be35a1SLionel Sambuc	# create 100 users, all in the same hash list
84*11be35a1SLionel Sambuc	local i=1;
85*11be35a1SLionel Sambuc	while [ $i -lt 101 ]; do
86*11be35a1SLionel Sambuc		atf_check -s exit:0 \
87*11be35a1SLionel Sambuc		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
88*11be35a1SLionel Sambuc		   -s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
89*11be35a1SLionel Sambuc		i=$((i + 1))
90*11be35a1SLionel Sambuc	done
91*11be35a1SLionel Sambuc	# do a repquota
92*11be35a1SLionel Sambuc	atf_check -s exit:0 -o 'match:user 409600 block  *81920 20 0' \
93*11be35a1SLionel Sambuc	    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -x -${expect} /mnt
94*11be35a1SLionel Sambuc	rump_quota_shutdown
95*11be35a1SLionel Sambuc}
96*11be35a1SLionel Sambuc
97*11be35a1SLionel Sambucquota_snap()
98*11be35a1SLionel Sambuc{
99*11be35a1SLionel Sambuc	local flag=$1; shift
100*11be35a1SLionel Sambuc	create_ffs $*
101*11be35a1SLionel Sambuc	local q=$3
102*11be35a1SLionel Sambuc	local expect
103*11be35a1SLionel Sambuc
104*11be35a1SLionel Sambuc	case ${q} in
105*11be35a1SLionel Sambuc	user)
106*11be35a1SLionel Sambuc		expect=u
107*11be35a1SLionel Sambuc		fail=g
108*11be35a1SLionel Sambuc		;;
109*11be35a1SLionel Sambuc	group)
110*11be35a1SLionel Sambuc		expect=g
111*11be35a1SLionel Sambuc		fail=u
112*11be35a1SLionel Sambuc		;;
113*11be35a1SLionel Sambuc	*)
114*11be35a1SLionel Sambuc		atf_fail "wrong quota type"
115*11be35a1SLionel Sambuc		;;
116*11be35a1SLionel Sambuc	esac
117*11be35a1SLionel Sambuc
118*11be35a1SLionel Sambuc	#start our server which takes a snapshot
119*11be35a1SLionel Sambuc	atf_check -s exit:0 -o ignore \
120*11be35a1SLionel Sambuc	    $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
121*11be35a1SLionel Sambuc	# create a few users
122*11be35a1SLionel Sambuc	local i=1;
123*11be35a1SLionel Sambuc	while [ $i -lt 11 ]; do
124*11be35a1SLionel Sambuc		atf_check -s exit:0 \
125*11be35a1SLionel Sambuc		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
126*11be35a1SLionel Sambuc		   -s10k/20 -h40M/50k -t 2W/3D $i
127*11be35a1SLionel Sambuc		i=$((i + 1))
128*11be35a1SLionel Sambuc	done
129*11be35a1SLionel Sambuc	# we should have 5 files (root + 4 regular files)
130*11be35a1SLionel Sambuc	atf_check -s exit:0 \
131*11be35a1SLionel Sambuc	    -o 'match:-        -  7days         5       -       -  7days' \
132*11be35a1SLionel Sambuc	    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -av
133*11be35a1SLionel Sambuc	#shutdown and check filesystem
134*11be35a1SLionel Sambuc	rump_quota_shutdown
135*11be35a1SLionel Sambuc}
136*11be35a1SLionel Sambuc
137*11be35a1SLionel Sambucquota_log()
138*11be35a1SLionel Sambuc{
139*11be35a1SLionel Sambuc	local srv2args=$1; shift
140*11be35a1SLionel Sambuc	create_ffs $*
141*11be35a1SLionel Sambuc	local q=$3
142*11be35a1SLionel Sambuc	local expect
143*11be35a1SLionel Sambuc
144*11be35a1SLionel Sambuc	case ${q} in
145*11be35a1SLionel Sambuc	user)
146*11be35a1SLionel Sambuc		expect=u
147*11be35a1SLionel Sambuc		fail=g
148*11be35a1SLionel Sambuc		;;
149*11be35a1SLionel Sambuc	group)
150*11be35a1SLionel Sambuc		expect=g
151*11be35a1SLionel Sambuc		fail=u
152*11be35a1SLionel Sambuc		;;
153*11be35a1SLionel Sambuc	*)
154*11be35a1SLionel Sambuc		atf_fail "wrong quota type"
155*11be35a1SLionel Sambuc		;;
156*11be35a1SLionel Sambuc	esac
157*11be35a1SLionel Sambuc
158*11be35a1SLionel Sambuc	#start our server which create a file and unlink while keeping
159*11be35a1SLionel Sambuc	# it open. The server halts itself without flush
160*11be35a1SLionel Sambuc	atf_check -s exit:0 -o ignore \
161*11be35a1SLionel Sambuc	    $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
162*11be35a1SLionel Sambuc	# we should have one unlinked file, but the log covers it.
163*11be35a1SLionel Sambuc	atf_check -s exit:0 -o match:'3 files' -e ignore \
164*11be35a1SLionel Sambuc	    fsck_ffs -nf -F ${IMG}
165*11be35a1SLionel Sambuc	# have a kernel mount the fs again; it should cleanup the
166*11be35a1SLionel Sambuc	# unlinked file
167*11be35a1SLionel Sambuc	atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
168*11be35a1SLionel Sambuc	    ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
169*11be35a1SLionel Sambuc	#shutdown and check filesystem
170*11be35a1SLionel Sambuc	rump_quota_shutdown
171*11be35a1SLionel Sambuc}
172*11be35a1SLionel Sambuc
173*11be35a1SLionel Sambucquota_default_deny()
174*11be35a1SLionel Sambuc{
175*11be35a1SLionel Sambuc	local nusers=$1; shift
176*11be35a1SLionel Sambuc	create_ffs_server $*
177*11be35a1SLionel Sambuc	local q=$4
178*11be35a1SLionel Sambuc	local expect
179*11be35a1SLionel Sambuc
180*11be35a1SLionel Sambuc	case ${q} in
181*11be35a1SLionel Sambuc	user)
182*11be35a1SLionel Sambuc		expect=u
183*11be35a1SLionel Sambuc		fail=g
184*11be35a1SLionel Sambuc		;;
185*11be35a1SLionel Sambuc	group)
186*11be35a1SLionel Sambuc		expect=g
187*11be35a1SLionel Sambuc		fail=u
188*11be35a1SLionel Sambuc		;;
189*11be35a1SLionel Sambuc	*)
190*11be35a1SLionel Sambuc		atf_fail "wrong quota type"
191*11be35a1SLionel Sambuc		;;
192*11be35a1SLionel Sambuc	esac
193*11be35a1SLionel Sambuc
194*11be35a1SLionel Sambuc	# create $nusers users, so we are sure the free list has entries
195*11be35a1SLionel Sambuc	# from block 1. Start from 10, as non-root id is 1.
196*11be35a1SLionel Sambuc	# set default to deny all
197*11be35a1SLionel Sambuc	( echo "@format netbsd-quota-dump v1"
198*11be35a1SLionel Sambuc	  echo "# idtype id objtype   hard soft usage expire grace"
199*11be35a1SLionel Sambuc	  echo "$q default block   0 0 0 0 0"
200*11be35a1SLionel Sambuc	  echo "$q default file   0 0 0 0 0"
201*11be35a1SLionel Sambuc	  local i=10;
202*11be35a1SLionel Sambuc	  while [ $i -lt $(($nusers + 10)) ]; do
203*11be35a1SLionel Sambuc		echo "$q $i block   0 0 0 0 0"
204*11be35a1SLionel Sambuc		echo "$q $i file   0 0 0 0 0"
205*11be35a1SLionel Sambuc		i=$((i + 1))
206*11be35a1SLionel Sambuc	  done
207*11be35a1SLionel Sambuc	) | atf_check -s exit:0 \
208*11be35a1SLionel Sambuc		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quotarestore -d /mnt
209*11be35a1SLionel Sambuc	atf_check -s exit:0 rump.halt
210*11be35a1SLionel Sambuc	#now start the server which does the limits tests
211*11be35a1SLionel Sambuc	$(atf_get_srcdir)/h_quota2_tests -oC -b 0 ${IMG} ${RUMP_SERVER}
212*11be35a1SLionel Sambuc	rump_quota_shutdown
213*11be35a1SLionel Sambuc}
214