t_miscquota.sh revision 1.2 1 # $NetBSD: t_miscquota.sh,v 1.2 2011/03/06 17:08:40 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
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 quota_walk_list()
57 {
58 create_with_quotas_server $*
59 local q=$4
60 local expect
61
62 case ${q} in
63 user)
64 expect=u
65 fail=g
66 ;;
67 group)
68 expect=g
69 fail=u
70 ;;
71 *)
72 atf_fail "wrong quota type"
73 ;;
74 esac
75
76 # create 100 users, all in the same hash list
77 local i=1;
78 while [ $i -lt 101 ]; do
79 atf_check -s exit:0 \
80 $(atf_get_srcdir)/rump_edquota -${expect} \
81 -s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
82 i=$((i + 1))
83 done
84 # do a repquota
85 atf_check -s exit:0 -o 'match:<integer>0x64000' \
86 $(atf_get_srcdir)/rump_repquota -x -${expect} /mnt
87 rump_shutdown
88 }
89
90 quota_snap()
91 {
92 local flag=$1; shift
93 create_with_quotas $*
94 local q=$3
95 local expect
96
97 case ${q} in
98 user)
99 expect=u
100 fail=g
101 ;;
102 group)
103 expect=g
104 fail=u
105 ;;
106 *)
107 atf_fail "wrong quota type"
108 ;;
109 esac
110
111 #start our server which takes a snapshot
112 atf_check -s exit:0 -o ignore \
113 $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
114 # create a few users
115 local i=1;
116 while [ $i -lt 11 ]; do
117 atf_check -s exit:0 \
118 $(atf_get_srcdir)/rump_edquota -${expect} \
119 -s10k/20 -h40M/50k -t 2W/3D $i
120 i=$((i + 1))
121 done
122 # we should have 5 files (root + 4 regular files)
123 atf_check -s exit:0 \
124 -o 'match:- - 7days 5 - - 7days' \
125 $(atf_get_srcdir)/rump_repquota -av
126 #shutdown and check filesystem
127 rump_shutdown
128 }
129
130 quota_log()
131 {
132 local srv2args=$1; shift
133 create_with_quotas $*
134 local q=$3
135 local expect
136
137 case ${q} in
138 user)
139 expect=u
140 fail=g
141 ;;
142 group)
143 expect=g
144 fail=u
145 ;;
146 *)
147 atf_fail "wrong quota type"
148 ;;
149 esac
150
151 #start our server which create a file and unlink while keeping
152 # it open. The server halts itself without flush
153 atf_check -s exit:0 -o ignore \
154 $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
155 # we should have one unlinked file, but the log covers it.
156 atf_check -s exit:0 -o match:'3 files' -e ignore \
157 fsck_ffs -nf -F ${IMG}
158 # have a kernel mount the fs again; it should cleanup the
159 # unlinked file
160 atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
161 ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
162 #shutdown and check filesystem
163 rump_shutdown
164 }
165