1272343Sngie# $NetBSD: t_miscquota.sh,v 1.8 2013/01/22 06:24:11 dholland Exp $ 
2272343Sngie#
3272343Sngie#  Copyright (c) 2011 Manuel Bouyer
4272343Sngie#  All rights reserved.
5272343Sngie# 
6272343Sngie#  Redistribution and use in source and binary forms, with or without
7272343Sngie#  modification, are permitted provided that the following conditions
8272343Sngie#  are met:
9272343Sngie#  1. Redistributions of source code must retain the above copyright
10272343Sngie#     notice, this list of conditions and the following disclaimer.
11272343Sngie#  2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#     notice, this list of conditions and the following disclaimer in the
13272343Sngie#     documentation and/or other materials provided with the distribution.
14272343Sngie# 
15272343Sngie#  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie#  POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngietest_case_root walk_list_user quota_walk_list \
29272343Sngie    "walk user quota list over several disk blocks" -b le 1 user
30272343Sngie
31272343Sngietest_case_root psnapshot_user quota_snap \
32272343Sngie    "create a persistent shapshot of quota-enabled fs, and do some writes" \
33272343Sngie    -b le 1 user
34272343Sngie
35272343Sngietest_case_root npsnapshot_user quota_snap \
36272343Sngie    "create a non-persistent shapshot of quota-enabled fs, and do some writes" \
37272343Sngie    -boL le 1 user
38272343Sngie
39272343Sngietest_case_root psnapshot_unconf_user quota_snap \
40272343Sngie    "create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
41272343Sngie    -boC le 1 user
42272343Sngie
43272343Sngietest_case_root npsnapshot_unconf_user quota_snap \
44272343Sngie    "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
45272343Sngie    -boLC le 1 user
46272343Sngie
47272343Sngietest_case log_unlink quota_log \
48272343Sngie    "an unlinked file cleaned by the log replay should update quota" \
49272343Sngie    -l le 1 user
50272343Sngie
51272343Sngietest_case log_unlink_remount quota_log \
52272343Sngie    "an unlinked file cleaned by the log replay after remount" \
53272343Sngie    -oRL le 1 user
54272343Sngie
55272343Sngie
56272343Sngietest_case_root default_deny_user quota_default_deny \
57272343Sngie    "new quota entry denied by default entry" 5 -b le 1 user
58272343Sngie
59272343Sngietest_case_root default_deny_user_big quota_default_deny \
60272343Sngie    "new quota entry denied by default entry, with list on more than one block" 5000 -b le 1 user
61272343Sngie
62272343Sngie
63272343Sngiequota_walk_list()
64272343Sngie{
65272343Sngie	create_ffs_server $*
66272343Sngie	local q=$4
67272343Sngie	local expect
68272343Sngie
69272343Sngie	case ${q} in
70272343Sngie	user)
71272343Sngie		expect=u
72272343Sngie		fail=g
73272343Sngie		;;
74272343Sngie	group)
75272343Sngie		expect=g
76272343Sngie		fail=u
77272343Sngie		;;
78272343Sngie	*)
79272343Sngie		atf_fail "wrong quota type"
80272343Sngie		;;
81272343Sngie	esac
82272343Sngie
83272343Sngie	# create 100 users, all in the same hash list
84272343Sngie	local i=1;
85272343Sngie	while [ $i -lt 101 ]; do
86272343Sngie		atf_check -s exit:0 \
87272343Sngie		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
88272343Sngie		   -s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
89272343Sngie		i=$((i + 1))
90272343Sngie	done
91272343Sngie	# do a repquota
92272343Sngie	atf_check -s exit:0 -o 'match:user 409600 block  *81920 20 0' \
93272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -x -${expect} /mnt
94272343Sngie	rump_quota_shutdown
95272343Sngie}
96272343Sngie
97272343Sngiequota_snap()
98272343Sngie{
99272343Sngie	local flag=$1; shift
100272343Sngie	create_ffs $*
101272343Sngie	local q=$3
102272343Sngie	local expect
103272343Sngie
104272343Sngie	case ${q} in
105272343Sngie	user)
106272343Sngie		expect=u
107272343Sngie		fail=g
108272343Sngie		;;
109272343Sngie	group)
110272343Sngie		expect=g
111272343Sngie		fail=u
112272343Sngie		;;
113272343Sngie	*)
114272343Sngie		atf_fail "wrong quota type"
115272343Sngie		;;
116272343Sngie	esac
117272343Sngie
118272343Sngie	#start our server which takes a snapshot
119272343Sngie	atf_check -s exit:0 -o ignore \
120272343Sngie	    $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
121272343Sngie	# create a few users
122272343Sngie	local i=1;
123272343Sngie	while [ $i -lt 11 ]; do
124272343Sngie		atf_check -s exit:0 \
125272343Sngie		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
126272343Sngie		   -s10k/20 -h40M/50k -t 2W/3D $i
127272343Sngie		i=$((i + 1))
128272343Sngie	done
129272343Sngie	# we should have 5 files (root + 4 regular files)
130272343Sngie	atf_check -s exit:0 \
131272343Sngie	    -o 'match:-        -  7days         5       -       -  7days' \
132272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -av
133272343Sngie	#shutdown and check filesystem
134272343Sngie	rump_quota_shutdown
135272343Sngie}
136272343Sngie
137272343Sngiequota_log()
138272343Sngie{
139272343Sngie	local srv2args=$1; shift
140272343Sngie	create_ffs $*
141272343Sngie	local q=$3
142272343Sngie	local expect
143272343Sngie
144272343Sngie	case ${q} in
145272343Sngie	user)
146272343Sngie		expect=u
147272343Sngie		fail=g
148272343Sngie		;;
149272343Sngie	group)
150272343Sngie		expect=g
151272343Sngie		fail=u
152272343Sngie		;;
153272343Sngie	*)
154272343Sngie		atf_fail "wrong quota type"
155272343Sngie		;;
156272343Sngie	esac
157272343Sngie
158272343Sngie	#start our server which create a file and unlink while keeping
159272343Sngie	# it open. The server halts itself without flush
160272343Sngie	atf_check -s exit:0 -o ignore \
161272343Sngie	    $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
162272343Sngie	# we should have one unlinked file, but the log covers it.
163272343Sngie	atf_check -s exit:0 -o match:'3 files' -e ignore \
164272343Sngie	    fsck_ffs -nf -F ${IMG}
165272343Sngie	# have a kernel mount the fs again; it should cleanup the
166272343Sngie	# unlinked file
167272343Sngie	atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
168272343Sngie	    ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
169272343Sngie	#shutdown and check filesystem
170272343Sngie	rump_quota_shutdown
171272343Sngie}
172272343Sngie
173272343Sngiequota_default_deny()
174272343Sngie{
175272343Sngie	local nusers=$1; shift
176272343Sngie	create_ffs_server $*
177272343Sngie	local q=$4
178272343Sngie	local expect
179272343Sngie
180272343Sngie	case ${q} in
181272343Sngie	user)
182272343Sngie		expect=u
183272343Sngie		fail=g
184272343Sngie		;;
185272343Sngie	group)
186272343Sngie		expect=g
187272343Sngie		fail=u
188272343Sngie		;;
189272343Sngie	*)
190272343Sngie		atf_fail "wrong quota type"
191272343Sngie		;;
192272343Sngie	esac
193272343Sngie
194272343Sngie	# create $nusers users, so we are sure the free list has entries
195272343Sngie	# from block 1. Start from 10, as non-root id is 1.
196272343Sngie	# set default to deny all
197272343Sngie	( echo "@format netbsd-quota-dump v1"
198272343Sngie	  echo "# idtype id objtype   hard soft usage expire grace"
199272343Sngie	  echo "$q default block   0 0 0 0 0"
200272343Sngie	  echo "$q default file   0 0 0 0 0"
201272343Sngie	  local i=10;
202272343Sngie	  while [ $i -lt $(($nusers + 10)) ]; do
203272343Sngie		echo "$q $i block   0 0 0 0 0"
204272343Sngie		echo "$q $i file   0 0 0 0 0"
205272343Sngie		i=$((i + 1))
206272343Sngie	  done
207272343Sngie	) | atf_check -s exit:0 \
208272343Sngie		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quotarestore -d /mnt
209272343Sngie	atf_check -s exit:0 rump.halt
210272343Sngie	#now start the server which does the limits tests
211272343Sngie	$(atf_get_srcdir)/h_quota2_tests -oC -b 0 ${IMG} ${RUMP_SERVER}
212272343Sngie	rump_quota_shutdown
213272343Sngie}
214