Bring in FreeBSD's stress2 stress testing suite.
[dragonfly.git] / test / stress / stress2 / misc / umountf3.sh
1 #!/bin/sh
2
3 #
4 # Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27 #
28 # $FreeBSD$
29 #
30
31 # Demonstrate livelock with "umount -f" seen both with UFS and MSDOS
32
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34
35 . ../default.cfg
36
37 D=$diskimage
38 dede $D 1m 1k || exit 1
39
40 odir=`pwd`
41
42 cd /tmp
43 sed '1,/^EOF/d' < $odir/$0 > umountf3.c
44 cc -o umountf3 -Wall umountf3.c
45 rm -f umountf3.c
46 cd $odir
47
48
49 mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint
50 mdconfig -l | grep md${mdstart} > /dev/null &&  mdconfig -d -u ${mdstart}
51
52 mdconfig -a -t vnode -f $D -u ${mdstart}
53 bsdlabel -w md${mdstart} auto
54 newfs md${mdstart}${part} > /dev/null 2>&1
55 mount /dev/md${mdstart}${part} $mntpoint
56 #newfs_msdos -F 32 -b 8192 /dev/md${mdstart}a
57 #mount -t msdosfs /dev/md${mdstart}a $mntpoint
58 export RUNDIR=$mntpoint/stressX
59 for i in `jot 25`; do
60         (cd /$mntpoint; /tmp/umountf3) &
61 done
62 sleep $((4 * 60))
63 echo "umount -f $mntpoint"
64 umount -f $mntpoint
65 mdconfig -d -u $mdstart
66 rm -f $D /tmp/umountf3
67 exit
68 EOF
69
70 #include <stdio.h>
71 #include <stdlib.h>
72 #include <unistd.h>
73 #include <fcntl.h>
74 #include <sys/stat.h>
75 #include <sys/param.h>
76 #include <err.h>
77
78 static unsigned long size = 1024 * 1024 * 2;
79
80 int
81 main(int argc, char **argv)
82 {
83         int buf[1024], index, to, n;
84         int fd;
85         char file[128];
86
87
88         sprintf(file,"p%06d", getpid());
89         if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1)
90                 err(1, "creat(%s)", file);
91
92         to = sizeof(buf);
93         for (;;) {
94                 index = 0;
95                 while (index < size) {
96                         if (index + to > size)
97                                 to = size - index;
98                         index += to;
99                         if (write(fd, buf, to) != to)
100                                 err(1, "write(%s), %s:%d", file, __FILE__, __LINE__);
101                 }
102
103                 if (lseek(fd, 0, 0) == -1)
104                         err(1, "lseek");
105                 index = 0;
106                 while (index < size) {
107                         if (index + to > size)
108                                 to = size - index;
109                         if ((n = read(fd, buf, to)) != to)
110                                 err(1, "rw read(%d, %d, %d). %s.%d", n, to, index,  __FILE__, __LINE__);
111                         index += to;
112                 }
113                 if (lseek(fd, 0, 0) == -1)
114                         err(1, "lseek");
115         }
116
117         if (close(fd) == -1)
118                 err(1, "close(%s), %s:%d", file, __FILE__, __LINE__);
119         if (unlink(file) == -1)
120                 err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__);
121         return (0);
122 }