4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright (c) 2019 Dell EMC Isilon
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # "umount: unmount of /mnt failed: Device busy" seen:
32 # https://people.freebsd.org/~pho/stress/log/fcntl2.txt
35 [ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
40 sed '1,/^EOF/d' < $odir/$0 > $dir/fcntl2.c
41 mycc -o fcntl2 -Wall -Wextra -O0 -g fcntl2.c || exit 1
46 mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
47 [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
48 mdconfig -a -t swap -s 2g -u $mdstart
49 newfs $newfs_flags md$mdstart > /dev/null
50 mount /dev/md$mdstart $mntpoint
53 (cd $odir/../testcases/swap; ./swap -t 3m -i 20) &
55 limits -n 10000 $dir/fcntl2
57 [ -f fcntl2.core -a $s -eq 0 ] &&
58 { ls -l fcntl2.core; mv fcntl2.core $dir; s=1; }
60 while pkill swap; do :; done
63 mount | grep -q "on $mntpoint " || break
64 umount $mntpoint && break || sleep 10
66 { echo FATAL; fstat -mf $mntpoint; exit 1; }
68 mdconfig -d -u $mdstart
73 #include <sys/param.h>
78 #include <machine/atomic.h>
88 static volatile u_int *share;
91 #define RUNTIME (3 * 60)
94 #define N (128 * 1024 / (int)sizeof(u_int32_t))
95 static u_int32_t r[N];
104 i = arc4random() % 100;
107 if (i >= 20 && i < 40)
109 if (i >= 40 && i < 60)
110 val = (unsigned long)(r) | (val & 0xffff);
111 #if defined(__LP64__)
113 val = (val << 32) | arc4random();
115 val = val & 0x00007fffffffffffUL;
126 int cmd, fd, i, n, success;
129 atomic_add_int(&share[SYNC], 1);
130 while (share[SYNC] != PARALLEL)
134 snprintf(file, sizeof(file), "file.%d", getpid());
135 if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE))
137 err(1, "open(%s)", file);
138 n = arc4random() % 100 + 1;
139 for (i = 0; i < n; i++)
140 if (write(fd, file, sizeof(file)) != sizeof(file))
143 while (time(NULL) - start < 60) {
144 cmd = arc4random() % 20;
147 if (fcntl(fd, cmd, arg3) != -1)
160 pid_t pids[PARALLEL];
166 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
167 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
171 while ((time(NULL) - start) < RUNTIME) {
172 for (i = 0; i < N; i++)
175 for (i = 0; i < PARALLEL; i++) {
176 if ((pids[i] = fork()) == 0)
181 for (i = 0; i < PARALLEL; i++) {
182 if (waitpid(pids[i], &status, 0) == -1)
183 err(1, "waitpid(%d)", pids[i]);