t_umountstress.sh revision 1.3 1 1.3 mlelstv # $NetBSD: t_umountstress.sh,v 1.3 2013/04/27 07:45:07 mlelstv Exp $
2 1.1 mlelstv #
3 1.1 mlelstv # Copyright (c) 2013 The NetBSD Foundation, Inc.
4 1.1 mlelstv # All rights reserved.
5 1.1 mlelstv #
6 1.1 mlelstv # Redistribution and use in source and binary forms, with or without
7 1.1 mlelstv # modification, are permitted provided that the following conditions
8 1.1 mlelstv # are met:
9 1.1 mlelstv # 1. Redistributions of source code must retain the above copyright
10 1.1 mlelstv # notice, this list of conditions and the following disclaimer.
11 1.1 mlelstv # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mlelstv # notice, this list of conditions and the following disclaimer in the
13 1.1 mlelstv # documentation and/or other materials provided with the distribution.
14 1.1 mlelstv #
15 1.1 mlelstv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 mlelstv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 mlelstv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 mlelstv # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 mlelstv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 mlelstv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 mlelstv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 mlelstv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 mlelstv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 mlelstv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 mlelstv # POSSIBILITY OF SUCH DAMAGE.
26 1.1 mlelstv #
27 1.1 mlelstv
28 1.1 mlelstv TMPMP=umount-stress_mount
29 1.1 mlelstv TMPIM=umount-stress.im
30 1.1 mlelstv
31 1.1 mlelstv VND=vnd0
32 1.1 mlelstv BVND=/dev/${VND}
33 1.1 mlelstv CVND=/dev/r${VND}
34 1.1 mlelstv MPART=a
35 1.1 mlelstv
36 1.1 mlelstv atf_test_case umountstress cleanup
37 1.1 mlelstv umountstress_head()
38 1.1 mlelstv {
39 1.1 mlelstv atf_set "descr" "Checks stressing unmounting a busy filesystem"
40 1.1 mlelstv atf_set "require.user" "root"
41 1.1 mlelstv }
42 1.1 mlelstv umountstress_body()
43 1.1 mlelstv {
44 1.1 mlelstv cat >disktab <<EOF
45 1.1 mlelstv floppy288|2.88MB 3.5in Extra High Density Floppy:\
46 1.1 mlelstv :ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
47 1.1 mlelstv :pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
48 1.1 mlelstv :pb#5760:ob#0:\
49 1.1 mlelstv :pc#5760:oc#0:
50 1.1 mlelstv EOF
51 1.1 mlelstv
52 1.1 mlelstv echo "*** Creating a dummy directory tree at" \
53 1.1 mlelstv "${TMPMP} mounted on ${TMPIM}"
54 1.1 mlelstv
55 1.1 mlelstv atf_check -o ignore -e ignore mkdir ${TMPMP}
56 1.1 mlelstv atf_check -o ignore -e ignore touch ${TMPMP}/under_the_mount
57 1.1 mlelstv atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860
58 1.1 mlelstv atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM}
59 1.1 mlelstv atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288
60 1.1 mlelstv atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART}
61 1.1 mlelstv atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP}
62 1.1 mlelstv
63 1.1 mlelstv echo "*** Testing unmount"
64 1.1 mlelstv
65 1.1 mlelstv touch ${TMPMP}/hold
66 1.2 mlelstv exec 9< ${TMPMP}/hold
67 1.1 mlelstv
68 1.1 mlelstv (
69 1.3 mlelstv for j in 0 1 2 3 4; do
70 1.1 mlelstv for k in 0 1 2 3 4 5 6 7 8 9; do
71 1.2 mlelstv if ! dd msgfmt=quiet if=/dev/zero \
72 1.2 mlelstv count=1 of=${TMPMP}/test$i$j$k; then
73 1.2 mlelstv echo 1
74 1.2 mlelstv exit
75 1.1 mlelstv fi
76 1.1 mlelstv done
77 1.1 mlelstv done
78 1.2 mlelstv echo 0
79 1.2 mlelstv ) > result &
80 1.1 mlelstv busypid=$!
81 1.1 mlelstv
82 1.1 mlelstv while kill 2>/dev/null -0 $busypid; do
83 1.1 mlelstv if err=$(umount ${TMPMP} 2>&1); then
84 1.1 mlelstv kill $busypid
85 1.2 mlelstv exec 9<&-
86 1.1 mlelstv wait
87 1.1 mlelstv atf_fail "Unmount succeeded while busy"
88 1.2 mlelstv return
89 1.1 mlelstv fi
90 1.2 mlelstv
91 1.2 mlelstv case $err in
92 1.2 mlelstv *:\ Device\ busy)
93 1.2 mlelstv ;;
94 1.2 mlelstv *)
95 1.2 mlelstv kill $busypid
96 1.2 mlelstv exec 9<&-
97 1.2 mlelstv wait
98 1.2 mlelstv atf_fail "Unmount failed: $err"
99 1.2 mlelstv return
100 1.2 mlelstv ;;
101 1.2 mlelstv esac
102 1.1 mlelstv done
103 1.2 mlelstv
104 1.2 mlelstv exec 9<&-
105 1.1 mlelstv wait
106 1.2 mlelstv
107 1.2 mlelstv rc=`cat result`
108 1.2 mlelstv rm -f result
109 1.2 mlelstv
110 1.2 mlelstv case $rc in
111 1.2 mlelstv 0) ;;
112 1.3 mlelstv *) atf_fail "File operation failed"
113 1.2 mlelstv esac
114 1.1 mlelstv }
115 1.1 mlelstv umountstress_cleanup()
116 1.1 mlelstv {
117 1.1 mlelstv echo "*** Cleaning up ${TMPMP}, ${TMPIM}."
118 1.1 mlelstv umount -f "${TMPMP}"
119 1.1 mlelstv vnconfig -u "${VND}"
120 1.1 mlelstv }
121 1.1 mlelstv
122 1.1 mlelstv atf_init_test_cases()
123 1.1 mlelstv {
124 1.1 mlelstv atf_add_test_case umountstress
125 1.1 mlelstv }
126