t_umountstress.sh revision 1.2 1 # $NetBSD: t_umountstress.sh,v 1.2 2013/04/20 09:00:03 mlelstv 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 umountstress cleanup
37 umountstress_head()
38 {
39 atf_set "descr" "Checks stressing unmounting a busy filesystem"
40 atf_set "require.user" "root"
41 }
42 umountstress_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 touch ${TMPMP}/under_the_mount
57 atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860
58 atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM}
59 atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288
60 atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART}
61 atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP}
62
63 echo "*** Testing unmount"
64
65 touch ${TMPMP}/hold
66 exec 9< ${TMPMP}/hold
67
68 (
69 for j in 0 1 2 3 4 5 6 7 8 9; do
70 for k in 0 1 2 3 4 5 6 7 8 9; do
71 if ! dd msgfmt=quiet if=/dev/zero \
72 count=1 of=${TMPMP}/test$i$j$k; then
73 echo 1
74 exit
75 fi
76 done
77 done
78 echo 0
79 ) > result &
80 busypid=$!
81
82 while kill 2>/dev/null -0 $busypid; do
83 if err=$(umount ${TMPMP} 2>&1); then
84 kill $busypid
85 exec 9<&-
86 wait
87 atf_fail "Unmount succeeded while busy"
88 return
89 fi
90
91 case $err in
92 *:\ Device\ busy)
93 ;;
94 *)
95 kill $busypid
96 exec 9<&-
97 wait
98 atf_fail "Unmount failed: $err"
99 return
100 ;;
101 esac
102 done
103
104 exec 9<&-
105 wait
106
107 rc=`cat result`
108 rm -f result
109
110 case $rc in
111 0) ;;
112 *) atf_fail "File operation failed with rc $rc"
113 esac
114 }
115 umountstress_cleanup()
116 {
117 echo "*** Cleaning up ${TMPMP}, ${TMPIM}."
118 umount -f "${TMPMP}"
119 vnconfig -u "${VND}"
120 }
121
122 atf_init_test_cases()
123 {
124 atf_add_test_case umountstress
125 }
126