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