]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/netbsd-tests/fs/ffs/t_miscquota.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / netbsd-tests / fs / ffs / t_miscquota.sh
1 # $NetBSD: t_miscquota.sh,v 1.8 2013/01/22 06:24:11 dholland 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
28 test_case_root walk_list_user quota_walk_list \
29     "walk user quota list over several disk blocks" -b le 1 user
30
31 test_case_root psnapshot_user quota_snap \
32     "create a persistent shapshot of quota-enabled fs, and do some writes" \
33     -b le 1 user
34
35 test_case_root npsnapshot_user quota_snap \
36     "create a non-persistent shapshot of quota-enabled fs, and do some writes" \
37     -boL le 1 user
38
39 test_case_root psnapshot_unconf_user quota_snap \
40     "create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
41     -boC le 1 user
42
43 test_case_root npsnapshot_unconf_user quota_snap \
44     "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
45     -boLC le 1 user
46
47 test_case log_unlink quota_log \
48     "an unlinked file cleaned by the log replay should update quota" \
49     -l le 1 user
50
51 test_case log_unlink_remount quota_log \
52     "an unlinked file cleaned by the log replay after remount" \
53     -oRL le 1 user
54
55
56 test_case_root default_deny_user quota_default_deny \
57     "new quota entry denied by default entry" 5 -b le 1 user
58
59 test_case_root default_deny_user_big quota_default_deny \
60     "new quota entry denied by default entry, with list on more than one block" 5000 -b le 1 user
61
62
63 quota_walk_list()
64 {
65         create_ffs_server $*
66         local q=$4
67         local expect
68
69         case ${q} in
70         user)
71                 expect=u
72                 fail=g
73                 ;;
74         group)
75                 expect=g
76                 fail=u
77                 ;;
78         *)
79                 atf_fail "wrong quota type"
80                 ;;
81         esac
82
83         # create 100 users, all in the same hash list
84         local i=1;
85         while [ $i -lt 101 ]; do
86                 atf_check -s exit:0 \
87                    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
88                    -s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
89                 i=$((i + 1))
90         done
91         # do a repquota
92         atf_check -s exit:0 -o 'match:user 409600 block  *81920 20 0' \
93             env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -x -${expect} /mnt
94         rump_quota_shutdown
95 }
96
97 quota_snap()
98 {
99         local flag=$1; shift
100         create_ffs $*
101         local q=$3
102         local expect
103
104         case ${q} in
105         user)
106                 expect=u
107                 fail=g
108                 ;;
109         group)
110                 expect=g
111                 fail=u
112                 ;;
113         *)
114                 atf_fail "wrong quota type"
115                 ;;
116         esac
117
118         #start our server which takes a snapshot
119         atf_check -s exit:0 -o ignore \
120             $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
121         # create a few users
122         local i=1;
123         while [ $i -lt 11 ]; do
124                 atf_check -s exit:0 \
125                    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
126                    -s10k/20 -h40M/50k -t 2W/3D $i
127                 i=$((i + 1))
128         done
129         # we should have 5 files (root + 4 regular files)
130         atf_check -s exit:0 \
131             -o 'match:-        -  7days         5       -       -  7days' \
132             env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -av
133         #shutdown and check filesystem
134         rump_quota_shutdown
135 }
136
137 quota_log()
138 {
139         local srv2args=$1; shift
140         create_ffs $*
141         local q=$3
142         local expect
143
144         case ${q} in
145         user)
146                 expect=u
147                 fail=g
148                 ;;
149         group)
150                 expect=g
151                 fail=u
152                 ;;
153         *)
154                 atf_fail "wrong quota type"
155                 ;;
156         esac
157
158         #start our server which create a file and unlink while keeping
159         # it open. The server halts itself without flush
160         atf_check -s exit:0 -o ignore \
161             $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
162         # we should have one unlinked file, but the log covers it.
163         atf_check -s exit:0 -o match:'3 files' -e ignore \
164             fsck_ffs -nf -F ${IMG}
165         # have a kernel mount the fs again; it should cleanup the
166         # unlinked file
167         atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
168             ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
169         #shutdown and check filesystem
170         rump_quota_shutdown
171 }
172
173 quota_default_deny()
174 {
175         local nusers=$1; shift
176         create_ffs_server $*
177         local q=$4
178         local expect
179
180         case ${q} in
181         user)
182                 expect=u
183                 fail=g
184                 ;;
185         group)
186                 expect=g
187                 fail=u
188                 ;;
189         *)
190                 atf_fail "wrong quota type"
191                 ;;
192         esac
193
194         # create $nusers users, so we are sure the free list has entries
195         # from block 1. Start from 10, as non-root id is 1.
196         # set default to deny all
197         ( echo "@format netbsd-quota-dump v1"
198           echo "# idtype id objtype   hard soft usage expire grace"
199           echo "$q default block   0 0 0 0 0"
200           echo "$q default file   0 0 0 0 0"
201           local i=10;
202           while [ $i -lt $(($nusers + 10)) ]; do
203                 echo "$q $i block   0 0 0 0 0"
204                 echo "$q $i file   0 0 0 0 0"
205                 i=$((i + 1))
206           done
207         ) | atf_check -s exit:0 \
208                    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quotarestore -d /mnt
209         atf_check -s exit:0 rump.halt
210         #now start the server which does the limits tests
211         $(atf_get_srcdir)/h_quota2_tests -oC -b 0 ${IMG} ${RUMP_SERVER}
212         rump_quota_shutdown
213 }