t_umountstress.sh revision 1.5.2.2 1 # $NetBSD: t_umountstress.sh,v 1.5.2.2 2013/06/23 06:28:56 tls Exp $
2 #
3 # Copyright (c) 2013 The NetBSD Foundation, Inc.
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 TMPMP=umount-stress_mount
29 TMPIM=umount-stress.im
30
31 VND=vnd0
32 BVND=/dev/${VND}
33 CVND=/dev/r${VND}
34 MPART=a
35
36 atf_test_case fileop cleanup
37 fileop_head()
38 {
39 atf_set "descr" "Checks unmounting a filesystem doing file operations"
40 atf_set "require.user" "root"
41 }
42 fileop_body()
43 {
44 cat >disktab <<EOF
45 floppy288|2.88MB 3.5in Extra High Density Floppy:\
46 :ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
47 :pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
48 :pb#5760:ob#0:\
49 :pc#5760:oc#0:
50 EOF
51
52 echo "*** Creating a dummy directory tree at" \
53 "${TMPMP} mounted on ${TMPIM}"
54
55 atf_check -o ignore -e ignore mkdir ${TMPMP}
56 atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860
57 atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM}
58 atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288
59 atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART}
60 atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP}
61
62 echo "*** Testing fileops"
63
64 touch ${TMPMP}/hold
65 exec 9< ${TMPMP}/hold
66
67 (
68 for j in 0 1 2; do
69 for k in 0 1 2 3 4 5 6 7 8 9; do
70 if ! dd msgfmt=quiet if=/dev/zero \
71 count=1 of=${TMPMP}/test$i$j$k; then
72 echo 1 >result
73 exit
74 fi
75 done
76 done
77 echo 0 >result
78 ) &
79 busypid=$!
80
81 while ! test -f result; do
82 if err=$(umount ${TMPMP} 2>&1); then
83 kill $busypid
84 exec 9<&-
85 wait
86 atf_fail "Unmount succeeded while busy"
87 return
88 fi
89
90 case $err in
91 *:\ Device\ busy)
92 ;;
93 *)
94 kill $busypid
95 exec 9<&-
96 wait
97 atf_fail "Unmount failed: $err"
98 return
99 ;;
100 esac
101 done
102
103 exec 9<&-
104 wait
105
106 rc=`cat result`
107 rm -f result
108
109 case $rc in
110 0) ;;
111 *) atf_fail "File operation failed"
112 esac
113 }
114 fileop_cleanup()
115 {
116 echo "*** Cleaning up ${TMPMP}, ${TMPIM}."
117 umount -f "${TMPMP}"
118 vnconfig -u "${VND}"
119 }
120
121 atf_test_case mountlist cleanup
122 mountlist_head()
123 {
124 atf_set "descr" "Checks unmounting a filesystem using mountlist"
125 atf_set "require.user" "root"
126 }
127 mountlist_body()
128 {
129 cat >disktab <<EOF
130 floppy288|2.88MB 3.5in Extra High Density Floppy:\
131 :ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
132 :pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
133 :pb#5760:ob#0:\
134 :pc#5760:oc#0:
135 EOF
136
137 echo "*** Creating a dummy directory tree at" \
138 "${TMPMP} mounted on ${TMPIM}"
139
140 atf_check -o ignore -e ignore mkdir ${TMPMP}
141 atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860
142 atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM}
143 atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288
144 atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART}
145 atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP}
146
147 echo "*** Testing mountlist"
148
149 (
150 for j in 0 1 2 3 4 5 6 7 8 9; do
151 for k in 0 1 2 3 4 5 6 7 8 9; do
152 if ! out=$(mount); then
153 echo 1 >result
154 exit
155 fi
156 done
157 done
158 echo 0 >result
159 ) &
160 busypid=$!
161
162 while ! test -f result; do
163 if err=$(umount ${TMPMP} 2>&1); then
164 if ! mount -o async ${BVND}${MPART} ${TMPMP}; then
165 kill $busypid
166 exec 9<&-
167 wait
168 atf_fail "Remount failed"
169 return
170 fi
171 continue
172 fi
173
174 case $err in
175 *:\ Device\ busy)
176 ;;
177 *)
178 kill $busypid
179 exec 9<&-
180 wait
181 atf_fail "Unmount failed: $err"
182 return
183 ;;
184 esac
185 done
186
187 exec 9<&-
188 wait
189
190 rc=`cat result`
191 rm -f result
192
193 case $rc in
194 0) ;;
195 *) atf_fail "Mountlist operation failed"
196 esac
197 }
198 mountlist_cleanup()
199 {
200 echo "*** Cleaning up ${TMPMP}, ${TMPIM}."
201 umount -f "${TMPMP}"
202 vnconfig -u "${VND}"
203 }
204
205 atf_init_test_cases()
206 {
207 atf_add_test_case fileop
208 atf_add_test_case mountlist
209 }
210