Index: user/pho/stress2/README =================================================================== --- user/pho/stress2/README (revision 278500) +++ user/pho/stress2/README (revision 278501) @@ -1,62 +1,64 @@ $FreeBSD$ This is the FreeBSD kernel stress test suite. The purpose is to crash the computer, by stressing selected parts of the kernel, thus exposing inadequate error handling. Do not run the syscall test as root. To build and use: make sh ./run.sh The "run.sh" script accepts an optional configuration file in order to test specific areas. For example: ./run.sh vfs.cfg To run all of the different test scenarios type: ./run.sh -a You may have to tune the stress test to make sure that your test box run low on resources. For example: INCARNATIONS=125 ./run.sh The following sub-directories exists: ./doc Documentation ./include Include file for building the test programs in ./testcases ./lib Common support files for the test programs ./misc Various test scenarios. Mostly regression tests ./testcases Test programs ./tools Supplementary tools used in stress testing These days most test development occur is stress2/misc, where the regression tests reside. To run all of these tests once, type "./all.sh -o" in the stress2/misc directory. +The default mode is to compile tests, but pre-build binaries may be used. +See default.cfg for details. The name stress2 indicates that this is the second generation of the Kernel Stress Test Suite. The first version (stress) was based mostly on scripts. 20090120: des@ pointed out it would be nice to be able to set the random seed in order to be able to reproduce errors in time. A test of this show that the occurrence of panics are still non-deterministic even with a fixed seed. The known broken unionfs was used to test this: http://people.freebsd.org/~pho/stress/log/marcus006.txt. First panic occurred after 29 loops and the second after 8 with a seed of "123". The randomness that is provided by lack of synchronization with timer interrupt, disk block layout and disk access latencies caused by platter and heads speed changes, disk firmware internal operations, and so on are _much_ bigger then the undeterminism caused by the non-repeatable random seed. Anyway, I have always view the this issue as only a slight inconvenience. Index: user/pho/stress2/default.cfg =================================================================== --- user/pho/stress2/default.cfg (revision 278500) +++ user/pho/stress2/default.cfg (revision 278501) @@ -1,92 +1,127 @@ # $FreeBSD$ # Stress Test Suite Configuration # Default values export RUNDIR=${RUNDIR:-/tmp/stressX} export RUNTIME=${RUNTIME:-2m} export VERBOSE=${VERBOSE:-1} export LOAD=20 # The INCARNATIONS variable should be set to match the number of CPUs and # the amount of RAM in the test box. # 10 for a 1,8 GHz Celeron with 256 Mb of RAM # 100 for a dual Xeon 1,8 GHz with 1024 Gb of RAM export INCARNATIONS=${INCARNATIONS:-20} # Change hostname! #export BLASTHOST=192.168.1.2 # host with udp discard enabled in inetd.conf export BLASTHOST=192.168.1.3 # host with udp discard enabled in inetd.conf #export nfs_export=somehost:mount # Used by nfs tests # Run all test cases: export runRUNTIME=${runRUNTIME:-3d} # Run tests for three days export runINCARNATIONS=1 export runLOAD=100 export swapINCARNATIONS=${swapINCARNATIONS:-$((2 * INCARNATIONS))} export swapLOAD=80 export syscallKILL=1 export swapKILL=1 # May takes a long time to stop export rwLOAD=70 export mkdirLOAD=80 export creatLOAD=80 export symlinkLOAD=20 export tcpKILL=1 #export shmKILL=1 export shmINCARNATIONS=5 export TESTPROGS=" testcases/rw/rw testcases/swap/swap testcases/creat/creat testcases/mkdir/mkdir testcases/thr1/thr1 testcases/udp/udp testcases/tcp/tcp " # # Defaults for ./misc tests # diskimage=/var/tmp/diskimage # Location of 1G disk image mntpoint=/mnt # Disk image mount point testuser=pho # Name of non root test user mdstart=5 # Start of free md units part=a # partition to use on a md FS newfs_flags="-U" # default file system flags # Wrapper for dd dede () { # file, blocksize, count local log=/tmp/$0.$$ dd if=/dev/zero of=$1 bs=$2 count=$3 > $log 2>&1 local status=$? egrep -v "records in|records out|bytes transferred" $log rm -f $log return $status } # fsck and dumpfs comparison checkfs () { dumpfs $1 | sed '/UFS2/s/..:..:../xx:xx:xx/' > /tmp/dumpfs.1 sleep 1 fsck -t ufs -y $1 > /tmp/fsck.log 2>&1 dumpfs $1 | sed '/UFS2/s/..:..:../xx:xx:xx/' > /tmp/dumpfs.2 if egrep -q "INCONSISTENCY|MODIFIED" /tmp/fsck.log || ! cmp -s /tmp/dumpfs.1 /tmp/dumpfs.2; then diff -c /tmp/dumpfs.1 /tmp/dumpfs.2 echo "fsck -t ufs -y $1" cat /tmp/fsck.log else rm -f /tmp/fsck.log /tmp/dumpfs.[12] fi } +# Support for pre-build binaries for stress2/misc tests +# Build modes: +# 1 Build and copy binary to $STRESS2BIN +# 2 Do not compile; use binary from $STRESS2BIN + +# Examples: +# BMODE=1 ./all.sh -on `grep -lw mycc *.sh` +# BMODE=2 STRESS2BIN=/home/pho/stress2/bin.i386.r276368 ./all.sh + +CC=${CC:-cc} +top=`dirname $(pwd)` # cwd for the all.sh script +STRESS2BIN=${STRESS2BIN:-$top/bin} +mycc () { # "-o" must be first argument + [ "$1" = "-o" ] && file=`basename $2` + if [ "$BMODE" = "1" ]; then + $CC $@ || return + [ -z "$file" ] && return # "-c" + [ -d $STRESS2BIN ] || mkdir $STRESS2BIN + [ -x $STRESS2BIN/$file ] && + echo "Overwriting $STRESS2BIN/$file" + echo "cp $2 $STRESS2BIN" + cp $2 $STRESS2BIN + elif [ "$BMODE" = "2" ]; then + [ -z "$file" ] && return + if [ ! -x $STRESS2BIN/$file ]; then + echo "$STRESS2BIN/$file not found" + exit 1 + fi + echo "Using binary $STRESS2BIN/$file" + cp $STRESS2BIN/$file /tmp + else + $CC $@ # default "build and run" mode + fi +} + [ -f "./`hostname`" ] && . "./`hostname`" # source in local configuration [ -f "../`hostname`" ] && . "../`hostname`" # source in local configuration Index: user/pho/stress2/misc/alternativeFlushPath.sh =================================================================== --- user/pho/stress2/misc/alternativeFlushPath.sh (revision 278500) +++ user/pho/stress2/misc/alternativeFlushPath.sh (revision 278501) @@ -1,129 +1,129 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Alternate buffer flush path test (Not verified). # Regression test for r169006. # Apply this patch to amplify the problem: # # diff -r1.520 vfs_bio.c # 894c894 # < if (bo->bo_dirty.bv_cnt > dirtybufthresh + 10) { # --- # > if (bo->bo_dirty.bv_cnt > dirtybufthresh /*+ 10*/) { . ../default.cfg odir=`pwd` dir=${RUNDIR}/alternativeFlushPath [ -d $dir ] && find $dir -type f | xargs rm rm -rf $dir mkdir -p $dir cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/alternativeFlushPath.c -cc -o /tmp/alternativeFlushPath -Wall -Wextra alternativeFlushPath.c +mycc -o /tmp/alternativeFlushPath -Wall -Wextra alternativeFlushPath.c rm -f alternativeFlushPath.c for j in `jot 10`; do /tmp/alternativeFlushPath & done for j in `jot 10`; do wait done sysctl vfs.altbufferflushes rm -rf /tmp/alternativeFlushPath $dir exit EOF #include #include #include #include #include #include #include #include #include static volatile sig_atomic_t more; static void handler(int i __unused) { more = 0; } void test(void) { int i, j; char name[80]; pid_t mypid; int *fd; struct rlimit rlp; if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) err(1, "getrlimit(RLIMIT_NOFILE)"); rlp.rlim_cur /= 10; mypid = getpid(); fd = malloc(rlp.rlim_cur * sizeof(int)); for (i = 0, j = 0; i < rlp.rlim_cur && more == 1; i++, j++) { sprintf(name, "f%05d.%05d", mypid, i); if ((fd[i] = open(name, O_CREAT|O_WRONLY, 0666)) == -1) { warn("open(%s)", name); more = 0; break; } } for (i = 0; i < j; i++) { sprintf(name, "f%05d.%05d", mypid, i); if (unlink(name) == -1) warn("unlink(%s)", name); } for (i = 0; i < j; i++) { if (close(fd[i]) == -1) warn("close(%d)", i); } free(fd); } int main() { more = 1; signal(SIGALRM, handler); alarm(20 * 60); while (more == 1) test(); return(0); } Index: user/pho/stress2/misc/callout_reset_on.sh =================================================================== --- user/pho/stress2/misc/callout_reset_on.sh (revision 278500) +++ user/pho/stress2/misc/callout_reset_on.sh (revision 278501) @@ -1,321 +1,323 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Scenario based on pr. kern/166340 # Process under FreeBSD 9.0 hangs in uninterruptable sleep with apparently # no syscall (empty wchan). # http://people.freebsd.org/~pho/stress/log/callout_reset_on.txt # Fixed in r243901. +. ../default.cfg + rm -f /tmp/crwriter /tmp/crlogger || exit 1 cat > /tmp/crwriter.c < #include #include #include char *txt[] = { "0 This is a line of text: abcdefghijklmnopqrstuvwxyz", "1 Another line of text: ABCDEFGHIJKLMNOPQRSTUVWXYZ", "2 A different line of text", "3 A very, very different text", "4 A much longer line with a lot of characters in the line", "5 Now this is a quite long line of text, with both upper and lower case letters, and one digit!" }; int main(void) { int i, j, n; char help[256]; for (i = 0; i < 100000; i++) { j = arc4random() % 6; n = arc4random() % strlen(txt[j]); strncpy(help, txt[j], n); help[n] = 0; printf("%s\n", txt[j]); if ((arc4random() % 1000) == 1) usleep(100000); } return (0); } EOF -cc -o /tmp/crwriter -Wall -Wextra -O2 -g /tmp/crwriter.c +mycc -o /tmp/crwriter -Wall -Wextra -O2 -g /tmp/crwriter.c rm -f /tmp/crwriter.c cat > /tmp/crlogger.c < #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define BARRIER_CREATE 1 #define BARRIER_WAIT 2 #define BARRIER_DELETE 3 void barrier(int mode) { int fd; char path[128]; if (mode == BARRIER_CREATE) { snprintf(path, sizeof(path), "barrier.%d", getpid()); if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "%s", path); } else if (mode == BARRIER_WAIT) { snprintf(path, sizeof(path), "barrier.%d", getppid()); for(;;) { if (access(path, R_OK) == -1) break; usleep(10000); } } else if (mode == BARRIER_DELETE) { snprintf(path, sizeof(path), "barrier.%d", getpid()); if (unlink(path) == -1) err(1, "unlink(%s)", path); } else errx(1, "Bad barrier mode: %d", mode); } pid_t pid; int bufsize; int port; int alarm_exit; void killer(void) { setproctitle("killer"); alarm(120); barrier(BARRIER_WAIT); for (;;) { if (pid == 0) break; if (kill(pid, SIGUSR1) == -1) break; usleep(1000); } _exit(0); } void handler(int s __unused) { } void ahandler(int s __unused) { if (alarm_exit) _exit(0); } /* Read form socket, discard */ static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; int n, *buf; setproctitle("reader - init"); on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); signal(SIGUSR1, handler); alarm(60); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); setproctitle("reader"); alarm(0); signal(SIGALRM, ahandler); for (;;) { ualarm(5000, 0); if ((n = recvfrom(msgsock, buf, 4, 0, NULL, NULL)) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } if (n == 0) break; if (write(msgsock, "OK", 3) != 3) err(1, "write ack. %s:%d", __FILE__, __LINE__); } close(msgsock); _exit(0); } /* read from stdin, write to socket */ static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; int i, r; char line[1024], ack[80];; pid_t ppid; setproctitle("writer - init"); ppid = getppid(); signal(SIGUSR1, handler); alarm(60); on = 1; for (i = 1; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); hostent = gethostbyname ("localhost"); bzero(&inetaddr, sizeof(inetaddr)); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); setproctitle("writer"); barrier(BARRIER_DELETE); alarm(0); while (fgets(line, sizeof(line), stdin) != NULL) { alarm(10); alarm_exit = 1; if (write(tcpsock, line, strlen(line)) < 0) err(1, "socket write(). %s:%d", __FILE__, __LINE__); alarm_exit = 0; ualarm(5000, 0); if (recvfrom(tcpsock, ack, 4, 0, NULL, NULL) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } } sleep(30); return; } int main(int argc, char **argv) { pid_t kpid; if (argc != 2) errx(1, "Usage: %s \n", argv[0]); port = atoi(argv[1]); bufsize = 128; barrier(BARRIER_CREATE); signal(SIGCHLD, SIG_IGN); if ((pid = fork()) == 0) reader(); if ((kpid = fork()) == 0) killer(); writer(); sleep(1); kill(pid, SIGINT); kill(kpid, SIGINT); return (0); } EOF -cc -o /tmp/crlogger -Wall -Wextra -O2 -g /tmp/crlogger.c +mycc -o /tmp/crlogger -Wall -Wextra -O2 -g /tmp/crlogger.c rm -f /tmp/crlogger.c N=200 for i in `jot 40`; do for j in `jot $N`; do /tmp/crwriter | /tmp/crlogger 1236$j 2>/dev/null & done for j in `jot $N`; do wait done done rm -f /tmp/crwriter /tmp/crlogger ./barrier.* Index: user/pho/stress2/misc/cmp.sh =================================================================== --- user/pho/stress2/misc/cmp.sh (revision 278500) +++ user/pho/stress2/misc/cmp.sh (revision 278501) @@ -1,185 +1,185 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Cross mount test of mkdir(2). # Page fault seen: # http://people.freebsd.org/~pho/stress/log/cmp.txt # Fixed by r275347 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > cmp.c -cc -o cmp -Wall -Wextra -O2 -g cmp.c || exit 1 +mycc -o cmp -Wall -Wextra -O2 -g cmp.c || exit 1 rm -f cmp.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto # Don't use SU due to bogus "out of inodes" messages. newfs md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint daemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ > /dev/null 2>&1 sleep 1 su $testuser -c "/tmp/cmp $mntpoint" & while kill -0 $! 2>/dev/null; do umount -f $mntpoint && mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint sleep .1 done wait while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart # tmpfs mount -t tmpfs tmpfs $mntpoint chmod 777 $mntpoint su $testuser -c "/tmp/cmp $mntpoint" & while kill -0 $! 2>/dev/null; do umount -f $mntpoint && mount -t tmpfs tmpfs $mntpoint chmod 777 $mntpoint sleep .1 done pkill -9 swap wait while pkill -9 swap; do : done > /dev/null 2>&1 while mount | grep $mntpoint | grep -q tmpfs; do umount $mntpoint || sleep 1 done rm -f /tmp/cmp exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define LOOPS 160 #define PARALLEL 16 int nbc, nbd; char *dir; void tmkdir(void) { int i, j; char d[MAXPATHLEN + 1], name[MAXPATHLEN + 1]; setproctitle(__func__); i = 0; snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); if (mkdir(name, 0755) == -1) { if (errno != ENAMETOOLONG && errno != ENOENT && errno != EBUSY && errno != EACCES && errno != EPERM) warn("mkdir(%s)", name); _exit(0); } for (;;) { snprintf(d, sizeof(d), "/%d", i++); strncat(name, d, sizeof(name) - 1); if (mkdir(name, 0755) == -1) { if (errno != ENAMETOOLONG && errno != ENOENT && errno != EBUSY && errno != EACCES && errno != EPERM) warn("mkdir(%s)", name); i--; break; } nbc++; } while (i >= 0) { snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); for (j = 0; j < i; j++) { snprintf(d, sizeof(d), "/%d", j); strncat(name, d, sizeof(name) - 1); } if (rmdir(name) == -1) { if (errno != ENOTEMPTY && errno != ENOENT && errno != EBUSY) warn("rmdir(%s)", name); } else nbd++; i--; } #if defined(TEST) if (nbc == 0) fprintf(stderr, "FAIL nbc = %d, nbd = %d\n", nbc, nbd); #endif _exit(0); } int main(int argc, char **argv) { int i, j; if (argc != 2) errx(1, "Usage: %s ", argv[0]); dir = argv[1]; for (j = 0; j < LOOPS; j++) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) tmkdir(); } for (i = 0; i < PARALLEL; i++) wait(NULL); } return(0); } Index: user/pho/stress2/misc/contigmalloc.sh =================================================================== --- user/pho/stress2/misc/contigmalloc.sh (revision 278500) +++ user/pho/stress2/misc/contigmalloc.sh (revision 278501) @@ -1,250 +1,252 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # contigmalloc(9) / contigfree(9) test scenario. # malloc() a random number of buffers with random size and then free them. # A malloc pattern might look like this: # contigmalloc(186 pages) # contigmalloc(56 pages) # contigmalloc(9 pages) # contigmalloc(202 pages) # contigmalloc(49 pages) # contigmalloc(5 pages) # "panic: vm_reserv_alloc_contig: reserv 0xff... isn't free" seen. # http://people.freebsd.org/~pho/stress/log/contigmalloc.txt # Fixed by r271351. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + odir=`pwd` -dir=/tmp/ctest +dir=/tmp/contigmalloc rm -rf $dir; mkdir -p $dir cat > $dir/ctest.c < #include #include #include #include #include #include #define min(a,b) (((a)<(b))?(a):(b)) #define CAP (64 * 1024 * 1024) /* Total allocation */ #define MAXBUF (32 * 1024 * 1024) /* Max buffer size */ #define N 512 /* Max allocations */ #define RUNTIME 120 #define TALLOC 1 #define TFREE 2 void *p[N]; long size[N]; int n; void test(int argc, char *argv[]) { long mw, s; int i, no, ps, res; if (argc == 3) { no = atoi(argv[1]); mw = atol(argv[2]); } if (argc != 3 || no == 0 || mw == 0) errx(1, "Usage: %s ", argv[0]); ps = getpagesize(); s = 0; n = arc4random() % N + 1; mw = mw / 100 * 10 * ps; /* Use 10% of vm.max_wired */ mw = min(mw, CAP); for (i = 0; i < n; i++) { size[i] = round_page((arc4random() % MAXBUF) + 1); if (s + size[i] > mw) continue; res = syscall(no, TALLOC, &p[i], &size[i]); if (res == -1) { warn("contigmalloc(%lu pages) failed at loop %d", size[i] / ps, i); } else { #if defined(TEST) fprintf(stderr, "contigmalloc(%lu pages)\n", size[i] / ps); #endif s += size[i]; } } setproctitle("%ld Mb", s / 1024 / 1024); for (i = 0; i < n; i++) { if (p[i] != NULL) { res = syscall(no, TFREE, &p[i], &size[i]); #if defined(TEST) fprintf(stderr, "contigfree(%lu pages)\n", size[i] / ps); #endif p[i] = NULL; } } } int main(int argc, char *argv[]) { time_t start; start = time(NULL); while (time(NULL) - start < RUNTIME) test(argc, argv); return (0); } EOF -cc -o $dir/ctest -Wall -Wextra -O0 -g $dir/ctest.c || exit +mycc -o /tmp/ctest -Wall -Wextra -O0 -g $dir/ctest.c || exit rm $dir/ctest.c cd $dir cat > Makefile < EOF sed '1,/^EOF2/d' < $odir/$0 > cmalloc.c make || exit 1 kldload $dir/cmalloc.ko || exit 1 cd $odir mw=`sysctl -n vm.max_wired` || exit 1 -$dir/ctest `sysctl -n debug.cmalloc_offset` $mw 2>&1 | tail -5 +/tmp/ctest `sysctl -n debug.cmalloc_offset` $mw 2>&1 | tail -5 kldunload $dir/cmalloc.ko -rm -rf $dir +rm -rf $dir /tmp/ctest exit EOF2 #include #include #include #include #include #include #include #include #include #define TALLOC 1 #define TFREE 2 /* * Hook up a syscall for contigmalloc testing. */ struct cmalloc_args { int a_op; void *a_ptr; void *a_size; }; static int cmalloc(struct thread *td, struct cmalloc_args *uap) { void *p; unsigned long size; int error; error = copyin(uap->a_size, &size, sizeof(size)); if (error != 0) { return (error); } switch (uap->a_op) { case TFREE: error = copyin(uap->a_ptr, &p, sizeof(p)); if (error == 0) { if (p != NULL) contigfree(p, size, M_TEMP); } return (error); case TALLOC: p = contigmalloc(size, M_TEMP, M_NOWAIT, 0ul, ~0ul, 4096, 0); if (p != NULL) { error = copyout(&p, uap->a_ptr, sizeof(p)); return (error); } return (ENOMEM); } return (EINVAL); } /* * The sysent for the new syscall */ static struct sysent cmalloc_sysent = { 3, /* sy_narg */ (sy_call_t *) cmalloc /* sy_call */ }; /* * The offset in sysent where the syscall is allocated. */ static int cmalloc_offset = NO_SYSCALL; SYSCTL_INT(_debug, OID_AUTO, cmalloc_offset, CTLFLAG_RD, &cmalloc_offset, 0, "cmalloc syscall number"); /* * The function called at load/unload. */ static int cmalloc_load(struct module *module, int cmd, void *arg) { int error = 0; switch (cmd) { case MOD_LOAD : break; case MOD_UNLOAD : break; default : error = EOPNOTSUPP; break; } return (error); } SYSCALL_MODULE(cmalloc_syscall, &cmalloc_offset, &cmalloc_sysent, cmalloc_load, NULL); Index: user/pho/stress2/misc/core.sh =================================================================== --- user/pho/stress2/misc/core.sh (revision 278500) +++ user/pho/stress2/misc/core.sh (revision 278501) @@ -1,79 +1,79 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test multiple (parallel) core dumps . ../default.cfg odir=`pwd` cd /tmp rm -f core sed '1,/^EOF/d' < $odir/$0 > core.c -cc -o core -Wall core.c +mycc -o core -Wall core.c rm -f core.c cd $RUNDIR for i in `jot 2`; do for j in `jot 4`; do /tmp/core & done for j in `jot 4`; do wait done done rm -f core exit EOF #include #include #include #include #include #include #include #define SIZ 10*1024*1024 int main(int argc, char **argv) { char *cp; if ((cp = malloc(SIZ)) == NULL) err(1, "Could not malloc 10Mb!"); memset(cp, 1, SIZ); sleep(120 - (time(NULL) % 120)); raise(SIGSEGV); return (0); } Index: user/pho/stress2/misc/datamove.sh =================================================================== --- user/pho/stress2/misc/datamove.sh (revision 278500) +++ user/pho/stress2/misc/datamove.sh (revision 278501) @@ -1,237 +1,237 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # There is a well-known problem in FreeBSD, caused by allowing page faults # while doing filesystem data move to or from userspace during read(2) and # write(2). The issue is that if the userspace address being read or write # from/to is backed by the mapping of the same file we are doing i/o to, # we deadlock. # Test scenario by ups [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > datamove.c -cc -o datamove -Wall datamove.c +mycc -o datamove -Wall datamove.c rm -f datamove.c n=5 old=`sysctl vm.old_msync | awk '{print $NF}'` sysctl vm.old_msync=1 for i in `jot $n`; do mkdir -p /tmp/datamove.dir.$i cd /tmp/datamove.dir.$i /tmp/datamove & done cd /tmp for i in `jot $n`; do wait done for i in `jot $n`; do rm -rf /tmp/datamove.dir.$i done sysctl vm.old_msync=$old rm -rf /tmp/datamove exit 0 EOF /*- * Copyright (c) 2006, Stephan Uphoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include int prepareFile(char* filename,int* fdp); int mapBuffer(char** bufferp,int fd1,int fd2); int startIO(int fd,char *buffer); int pagesize; #define FILESIZE (32*1024) char wbuffer[FILESIZE]; /* Create a FILESIZE sized file - then remove file data from the cache*/ int prepareFile(char* filename,int* fdp) { int fd; int len; int status; void *addr; fd = open(filename,O_CREAT | O_TRUNC | O_RDWR,S_IRWXU); if (fd == -1) { perror("Creating file"); return fd; } len = write(fd,wbuffer,FILESIZE); if (len < 0) { perror("Write failed"); return 1; } status = fsync(fd); if (status != 0) { perror("fsync failed"); return 1; } addr = mmap(NULL,FILESIZE, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } status = msync(addr,FILESIZE,MS_INVALIDATE | MS_SYNC); if (status != 0) { perror("Msync failed"); return 1; } munmap(addr,FILESIZE); *fdp = fd; return 0; } /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ int mapBuffer(char** bufferp,int fd1,int fd2) { void* addr; char *buffer; addr = mmap(NULL,pagesize*2, PROT_READ | PROT_WRITE , MAP_SHARED, fd1, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } buffer = addr; addr = mmap(buffer + pagesize,pagesize, PROT_READ | PROT_WRITE , MAP_FIXED | MAP_SHARED, fd2, 0); if (addr == MAP_FAILED) { perror("Mmap2 failed"); return 1; } *bufferp = buffer; return 0; } int startIO(int fd,char *buffer) { ssize_t len; len = write(fd,buffer,2*pagesize); if (len == -1) { perror("write failed"); return 1; } return 0; } int main(int argc,char *argv[],char *envp[]) { int fdA,fdB,fdDelayA,fdDelayB; int status; char *bufferA,*bufferB; pid_t pid; pagesize = getpagesize(); if ((prepareFile("A",&fdA)) || (prepareFile("B",&fdB)) || (prepareFile("DelayA",&fdDelayA)) || (prepareFile("DelayB",&fdDelayB)) || (mapBuffer(&bufferA,fdDelayA,fdB)) || (mapBuffer(&bufferB,fdDelayB,fdA))) exit(1); pid = fork(); if (pid == 0) { status = startIO(fdA,bufferA); exit(status); } if (pid == -1) { exit(1); } status = startIO(fdB,bufferB); exit(status); } Index: user/pho/stress2/misc/datamove2.sh =================================================================== --- user/pho/stress2/misc/datamove2.sh (revision 278500) +++ user/pho/stress2/misc/datamove2.sh (revision 278501) @@ -1,238 +1,238 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Variation of the datamove.sh scenario by not using "sysctl vm.old_msync=1" # Deadlock seen # Test scenario by ups . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > datamove2.c -cc -o datamove2 -Wall datamove2.c +mycc -o datamove2 -Wall datamove2.c rm -f datamove2.c for i in `jot 2`; do $here/../testcases/swap/swap -t 10m -i 200 -h & /tmp/datamove2 ps | grep swap | grep -v swap | awk '{print $1}' | xargs kill done rm -rf /tmp/datamove2 exit 0 EOF /*- * Copyright (c) 2006, Stephan Uphoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include int prepareFile(char *filename, int *fdp); int mapBuffer (char **bufferp, int fd1, int fd2); int startIO (int fd, char *buffer); int pagesize; #define FILESIZE (32*1024) char wbuffer [FILESIZE]; /* Create a FILESIZE sized file - then remove file data from the cache */ int prepareFile(char *filename, int *fdp) { int fd; int len; int status; void *addr; fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); if (fd == -1) { perror("Creating file"); return fd; } len = write(fd, wbuffer, FILESIZE); if (len < 0) { perror("Write failed"); return 1; } status = fsync(fd); if (status != 0) { perror("fsync failed"); return 1; } addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); if (status != 0) { perror("Msync failed"); return 1; } if (munmap(addr, FILESIZE) == -1) { perror("munmap failed"); return 1; } *fdp = fd; return 0; } /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ int mapBuffer(char **bufferp, int fd1, int fd2) { void *addr; char *buffer; addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } buffer = addr; addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd2, 0); if (addr == MAP_FAILED) { perror("Mmap2 failed"); return 1; } *bufferp = buffer; return 0; } void unmapBuffer(char *bufferp) { if (munmap(bufferp, pagesize * 2) == -1) err(1, "unmap 1. buffer"); if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) err(1, "unmap 2. buffer"); } int startIO(int fd, char *buffer) { ssize_t len; len = write(fd, buffer, 2 * pagesize); if (len == -1) { perror("write failed"); return 1; } return 0; } int main(int argc, char *argv[], char *envp[]) { int fdA, fdB, fdDelayA, fdDelayB; int status; int i; char *bufferA, *bufferB; pid_t pid; pagesize = getpagesize(); for (i = 0; i < 1000; i++) { if ((prepareFile("A", &fdA)) || (prepareFile("B", &fdB)) || (prepareFile("DelayA", &fdDelayA)) || (prepareFile("DelayB", &fdDelayB)) || (mapBuffer(&bufferA, fdDelayA, fdB)) || (mapBuffer(&bufferB, fdDelayB, fdA))) exit(1); pid = fork(); if (pid == 0) { status = startIO(fdA, bufferA); exit(status); } if (pid == -1) { perror("fork"); exit(1); } status = startIO(fdB, bufferB); if (wait(&status) == -1) err(1, "wait"); close(fdA); close(fdB); close(fdDelayA); close(fdDelayB); unmapBuffer(bufferA); unmapBuffer(bufferB); unlink("A"); unlink("B"); unlink("DelayA"); unlink("DelayB"); } exit(status); } Index: user/pho/stress2/misc/datamove3.sh =================================================================== --- user/pho/stress2/misc/datamove3.sh (revision 278500) +++ user/pho/stress2/misc/datamove3.sh (revision 278501) @@ -1,247 +1,247 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Threaded variation of datamove.sh # Based on a test scenario by ups and suggestions by kib [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > datamove3.c -cc -o datamove3 -Wall datamove3.c -lpthread +mycc -o datamove3 -Wall datamove3.c -lpthread rm -f datamove3.c n=5 old=`sysctl vm.old_msync | awk '{print $NF}'` sysctl vm.old_msync=1 for i in `jot $n`; do mkdir -p /tmp/datamove3.dir.$i cd /tmp/datamove3.dir.$i /tmp/datamove3 & done cd /tmp for i in `jot $n`; do wait done for i in `jot $n`; do rm -rf /tmp/datamove3.dir.$i done sysctl vm.old_msync=$old rm -rf /tmp/datamove3 exit 0 EOF /*- * Copyright (c) 2006, Stephan Uphoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include struct args { char *bp; int fd1; int fd2; } a[2]; int prepareFile(char *, int *); void * mapBuffer(void *); int startIO(int, char *); int pagesize; #define FILESIZE (32*1024) char wbuffer [FILESIZE]; /* Create a FILESIZE sized file - then remove file data from the cache */ int prepareFile(char *filename, int *fdp) { int fd; int len; int status; void *addr; fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); if (fd == -1) { perror("Creating file"); return fd; } len = write(fd, wbuffer, FILESIZE); if (len < 0) { perror("Write failed"); return 1; } status = fsync(fd); if (status != 0) { perror("fsync failed"); return 1; } addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); if (status != 0) { perror("Msync failed"); return 1; } munmap(addr, FILESIZE); *fdp = fd; return 0; } /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ void * mapBuffer(void *ar) { void *addr; char *buffer; int i; i = (int )ar; addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, a[i].fd1, 0); if (addr == MAP_FAILED) { err(1, "Mmap failed"); } buffer = addr; addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, a[i].fd2, 0); if (addr == MAP_FAILED) { err(1, "Mmap2 failed"); } a[i].bp = buffer; sleep(1); return (NULL); } int startIO(int fd, char *buffer) { ssize_t len; len = write(fd, buffer, 2 * pagesize); if (len == -1) { warn("startIO(%d, %p): write failed", fd, buffer); return 1; } return 0; } int main(int argc, char *argv[], char *envp[]) { int fdA, fdB, fdDelayA, fdDelayB; int r, status; char *bufferA, *bufferB; pid_t pid; pthread_t threads[2]; pagesize = getpagesize(); if ((prepareFile("A", &fdA)) || (prepareFile("B", &fdB)) || (prepareFile("DelayA", &fdDelayA)) || (prepareFile("DelayB", &fdDelayB))) exit(1); a[0].fd1 = fdDelayA; a[0].fd2 = fdB; a[1].fd1 = fdDelayB; a[1].fd2 = fdA; if ((r = pthread_create(&threads[0], NULL, mapBuffer, (void *)0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[1], NULL, mapBuffer, (void *)1)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); while (a[0].bp == NULL || a[1].bp == NULL) pthread_yield(); bufferA = a[0].bp; bufferB = a[1].bp; pid = fork(); if (pid == 0) { status = startIO(fdA, bufferA); exit(status); } if (pid == -1) { exit(1); } status = startIO(fdB, bufferB); exit(status); } Index: user/pho/stress2/misc/datamove4.sh =================================================================== --- user/pho/stress2/misc/datamove4.sh (revision 278500) +++ user/pho/stress2/misc/datamove4.sh (revision 278501) @@ -1,243 +1,243 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Variation of the datamove2.sh, using TMPFS # Deadlock seen [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > datamove4.c -cc -o datamove4 -Wall -Wextra -O2 -g datamove4.c +mycc -o datamove4 -Wall -Wextra -O2 -g datamove4.c rm -f datamove4.c mount | grep -q "$mntpoint " && umount $mntpoint mount -t tmpfs tmpfs $mntpoint chmod 777 $mntpoint for i in `jot 5`; do su $testuser -c "cd $mntpoint; /tmp/datamove4" done while mount | grep -q $mntpoint; do umount -f $mntpoint > /dev/null 2>&1 done rm -rf /tmp/datamove4 exit 0 EOF /*- * Copyright (c) 2006, Stephan Uphoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include int prepareFile(char *filename, int *fdp); int mapBuffer (char **bufferp, int fd1, int fd2); int startIO (int fd, char *buffer); int pagesize; #define FILESIZE (32*1024) char wbuffer [FILESIZE]; /* Create a FILESIZE sized file - then remove file data from the cache */ int prepareFile(char *filename, int *fdp) { int fd; int len; int status; void *addr; fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); if (fd == -1) { perror(filename); return fd; } len = write(fd, wbuffer, FILESIZE); if (len < 0) { perror("Write failed"); return 1; } status = fsync(fd); if (status != 0) { perror("fsync failed"); return 1; } addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); if (status != 0) { perror("Msync failed"); return 1; } if (munmap(addr, FILESIZE) == -1) { perror("munmap failed"); return 1; } *fdp = fd; return 0; } /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ int mapBuffer(char **bufferp, int fd1, int fd2) { void *addr; char *buffer; addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } buffer = addr; addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd2, 0); if (addr == MAP_FAILED) { perror("Mmap2 failed"); return 1; } *bufferp = buffer; return 0; } void unmapBuffer(char *bufferp) { if (munmap(bufferp, pagesize * 2) == -1) err(1, "unmap 1. buffer"); if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1) err(1, "unmap 2. buffer"); } int startIO(int fd, char *buffer) { ssize_t len; len = write(fd, buffer, 2 * pagesize); if (len == -1) { perror("write failed"); return 1; } return 0; } int main() { int fdA, fdB, fdDelayA, fdDelayB; int status; int i; char *bufferA, *bufferB; pid_t pid; pagesize = getpagesize(); for (i = 0; i < 1000; i++) { if ((prepareFile("A", &fdA)) || (prepareFile("B", &fdB)) || (prepareFile("DelayA", &fdDelayA)) || (prepareFile("DelayB", &fdDelayB)) || (mapBuffer(&bufferA, fdDelayA, fdB)) || (mapBuffer(&bufferB, fdDelayB, fdA))) exit(1); pid = fork(); if (pid == 0) { status = startIO(fdA, bufferA); exit(status); } if (pid == -1) { perror("fork"); exit(1); } status = startIO(fdB, bufferB); if (wait(&status) == -1) err(1, "wait"); close(fdA); close(fdB); close(fdDelayA); close(fdDelayB); unmapBuffer(bufferA); unmapBuffer(bufferB); unlink("A"); unlink("B"); unlink("DelayA"); unlink("DelayB"); } exit(status); } Index: user/pho/stress2/misc/devfd.sh =================================================================== --- user/pho/stress2/misc/devfd.sh (revision 278500) +++ user/pho/stress2/misc/devfd.sh (revision 278501) @@ -1,131 +1,131 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vn_lock 0xc65b5828: zero hold count" seen. # Originally found by the iknowthis test suite # by Tavis Ormandy # Fixed by r227952 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > devfd.c rm -f /tmp/devfd -cc -o devfd -Wall -Wextra -O2 -g devfd.c -lpthread || exit 1 +mycc -o devfd -Wall -Wextra -O2 -g devfd.c -lpthread || exit 1 rm -f devfd.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "(cd $mntpoint; /tmp/devfd)" while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/devfd exit EOF #include #include #include #include #include #include #include #include #include int fd[3], fd2[3]; void * thr1(void *arg __unused) { int i, j; char path[80]; for (i = 0; i < 100000; i++) { for (j = 0; j < 3; j++) { if (fd[j] != -1) close(fd[j]); sprintf(path, "fx%d", j); fd[j] = open(path, O_RDWR | O_CREAT, 0640); } } return (0); } void * thr2(void *arg __unused) { int i, j; char path[80]; for (i = 0; i < 100000; i++) { for (j = 0; j < 3; j++) { if (fd2[j] != -1) close(fd2[j]); sprintf(path, "/dev/fd/%d", j); if ((fd2[j] = open(path, O_RDONLY)) != -1) fchflags(fd2[j], UF_NODUMP); } } return (0); } int main(void) { pthread_t p1, p2; close(0); close(1); close(2); if (pthread_create(&p1, NULL, thr1, NULL) != 0) err(1, "pthread_create"); if (pthread_create(&p2, NULL, thr2, NULL) != 0) err(1, "pthread_create"); pthread_join(p1, NULL); pthread_join(p2, NULL); return (0); } Index: user/pho/stress2/misc/devfs2.sh =================================================================== --- user/pho/stress2/misc/devfs2.sh (revision 278500) +++ user/pho/stress2/misc/devfs2.sh (revision 278501) @@ -1,108 +1,110 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Stopped at devfs_open+0x23f: pushl 0x14(%ebx) # db> where # Tracing pid 46017 tid 100350 td 0xc4c08510 # devfs_open(e6d06a10) at devfs_open+0x23f # VOP_OPEN_APV(c09edda0,e6d06a10) at VOP_OPEN_APV+0x9b # vn_open_cred(e6d06b78,e6d06c78,0,c4883900,3,...) at vn_open_cred+0x41e # vn_open(e6d06b78,e6d06c78,0,3) at vn_open+0x1e # kern_open(c4c08510,8048887,0,1,0,...) at kern_open+0xb7 # open(c4c08510,e6d06d00) at open+0x18 # syscall(e6d06d38) at syscall+0x252 # Test scenario by kib@freebsd.org +. ../default.cfg + odir=`pwd` dir=/tmp cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/devfs2.c -cc -o devfs2 -Wall devfs2.c -lthr +mycc -o devfs2 -Wall devfs2.c -lthr rm -f devfs2.c ./devfs2 rm devfs2 exit EOF #include #include #include #include #include #include #include #include void * thr1(void *arg) { int fd; int i; for (i = 0; i < 1024; i++) { if ((fd = open("/dev/zero", O_RDONLY)) == -1) perror("open /dev/zero"); close(fd); } return (0); } void * thr2(void *arg) { int i; for (i = 0; i < 1024; i++) close(3); return (0); } int main() { pthread_t threads[2]; int i; int r; if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); for (i = 0; i < 2; i++) if (pthread_join(threads[i], NULL) != 0) err(1, "pthread_join(%d)", i); return (0); } Index: user/pho/stress2/misc/dup2.sh =================================================================== --- user/pho/stress2/misc/dup2.sh (revision 278500) +++ user/pho/stress2/misc/dup2.sh (revision 278501) @@ -1,71 +1,73 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for r234131. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/dup2.c -cc -o dup2 -Wall -Wextra dup2.c || exit 1 +mycc -o dup2 -Wall -Wextra dup2.c || exit 1 rm -f dup2.c cd $odir /tmp/dup2 || echo FAIL rm -f /tmp/dup2 exit EOF #include #include #include #include int main(void) { int error, fd2, i; error = 0; for (i = 0; i < 10000; i++) { fd2 = arc4random() % 1000000; if (dup2(1, fd2) == -1) { if (errno != EBADF) { warn("dup2(1, %d)", fd2); error = 1; break; } } else close(fd2); } return (error); } Index: user/pho/stress2/misc/execi386.sh =================================================================== --- user/pho/stress2/misc/execi386.sh (revision 278500) +++ user/pho/stress2/misc/execi386.sh (revision 278501) @@ -1,83 +1,85 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Calling exec*(2) in a thread of a i386 binary on amd64 caused a reboot. # Test scenario by: Steven Chamberlain # Fixed by r266464 [ `uname -p` = "amd64" ] || exit 0 +. ../default.cfg + here=`pwd` cd /tmp rm -f execi386.c execi386 pwd.i386 cat > /tmp/execi386.c < #include void * thread_main() { char *cmdline[] = { "./i386", NULL }; execve(cmdline[0], cmdline, NULL); return (NULL); } int main() { pthread_t thread; pthread_create(&thread, NULL, thread_main, NULL); pthread_join(thread, NULL); return (0); } EOF -cc -o execi386 -Wall -Wextra -O2 -g execi386.c -lpthread || exit 1 +mycc -o execi386 -Wall -Wextra -O2 -g execi386.c -lpthread || exit 1 cat > /tmp/i386.c < int main(void) { fprintf(stdout, "Hello, world\n"); return (0); } EOF -cc -m32 -o i386 -Wall -Wextra -O2 -g i386.c || exit 1 +mycc -m32 -o i386 -Wall -Wextra -O2 -g i386.c || exit 1 ./execi386 > /dev/null || echo FAIL rm -f execi386.c execi386 i386.c i386 Index: user/pho/stress2/misc/extattr.sh =================================================================== --- user/pho/stress2/misc/extattr.sh (revision 278500) +++ user/pho/stress2/misc/extattr.sh (revision 278501) @@ -1,96 +1,96 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test of extattr on a UFS2 FS using ACLs # Caused a "Duplicate free" panic. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > extattr.c -cc -o extattr -Wall extattr.c +mycc -o extattr -Wall extattr.c rm -f extattr.c cd $odir mount | grep "${mntpoint}" | grep -q md${mdstart}${part} && umount $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 20m -u $mdstart bsdlabel -w md$mdstart auto newfs -O 2 md${mdstart}${part} > /dev/null mount /dev/md${mdstart}${part} $mntpoint mkdir -p ${mntpoint}/.attribute/system cd ${mntpoint}/.attribute/system extattrctl initattr -p . 388 posix1e.acl_access extattrctl initattr -p . 388 posix1e.acl_default cd / umount /mnt tunefs -a enable /dev/md${mdstart}${part} mount /dev/md${mdstart}${part} $mntpoint mount | grep md${mdstart}${part} touch $mntpoint/acl-test setfacl -b $mntpoint/acl-test setfacl -m user:nobody:rw-,group:wheel:rw- $mntpoint/acl-test for i in `jot 5`; do /tmp/extattr $mntpoint/acl-test & done for i in `jot 5`; do wait done umount $mntpoint mdconfig -d -u $mdstart rm -f /tmp/extattr exit EOF #include #include #include int main(int argc, char **argv) { int i; struct stat sb; for (i = 0; i < 100000; i++) if (lstat(argv[1], &sb) == -1) err(1, "lstat(%s)", argv[1]); return (0); } Index: user/pho/stress2/misc/extattr_set_fd.sh =================================================================== --- user/pho/stress2/misc/extattr_set_fd.sh (revision 278500) +++ user/pho/stress2/misc/extattr_set_fd.sh (revision 278501) @@ -1,80 +1,80 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: kmem_malloc(2069012480): kmem_map too small" seen. # Fixed in r237366. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > extattr_set_fd.c -cc -o extattr_set_fd -Wall -Wextra -O2 extattr_set_fd.c +mycc -o extattr_set_fd -Wall -Wextra -O2 extattr_set_fd.c rm -f extattr_set_fd.c mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}${part} > /dev/null mount /dev/md${mdstart}${part} $mntpoint chmod 777 $mntpoint (cd $mntpoint; /tmp/extattr_set_fd) while mount | grep -q $mntpoint; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/extattr_set_fd exit 0 EOF #include #include #include #include #include char buf[4096]; int main(void) { int fd; if ((fd = open("theFile", O_RDWR | O_CREAT, 0622)) == -1) err(1, "open(%s)", "theFile"); (void) extattr_set_fd(fd, 1, "test", buf, 0x7b5294a6); return (0); } Index: user/pho/stress2/misc/f_offset.sh =================================================================== --- user/pho/stress2/misc/f_offset.sh (revision 278500) +++ user/pho/stress2/misc/f_offset.sh (revision 278501) @@ -1,160 +1,162 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Problem seen with atomic assingment of f_offset. Fixed in r238029. # Test scenario by kib@ +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > f_offset.c -cc -o f_offset -Wall -Wextra -O2 f_offset.c -lpthread +mycc -o f_offset -Wall -Wextra -O2 f_offset.c -lpthread rm -f f_offset.c /tmp/f_offset rm -f /tmp/f_offset exit 0 EOF /* Description by kib: To really exercise the race conditions, all the following items must be fulfilled simultaneously: 1. you use 32bit host, i.e. i386 2. you operate on the file offsets larger than 4GB (but see below) 3. there are several threads or processes that operate on the same file descriptor simultaneously. Please note that the normal fork(2) causes file descriptor table copy, so only rfork(2) call with RFFDG flag unset causes sharing. Or, multi-threading can be used. */ #include #include #include #include #include #include #include #include int errors, fd; char file[128]; #define START 0x100000000ULL #define N 1000000 void * t1(void *arg __unused) { int i; off_t offset; offset = START + 2; for (i = 0; i < N; i++) { if (lseek(fd, offset, SEEK_SET) == -1) err(1, "lseek error"); } return (0); } void * t2(void *arg __unused) { int i; off_t offset; offset = 1; for (i = 0; i < N; i++) { if (lseek(fd, offset, SEEK_SET) == -1) err(1, "lseek error"); } return (0); } void * t3(void *arg __unused) { int i; off_t offset; offset = 1; for (i = 0; i < N; i++) { if ((offset = lseek(fd, 0, SEEK_CUR)) == -1) err(1, "lseek error"); if (offset != 1 && offset != START + 2) fprintf(stderr, "FAIL #%d offset = %10jd (0x%09jx)\n", errors++, offset, offset); } return (0); } int main(void) { pthread_t threads[3]; int r; int i; off_t offset; snprintf(file, sizeof(file), "file.%06d", getpid()); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "%s", file); offset = 1; if (lseek(fd, offset, SEEK_SET) == -1) err(1, "lseek error"); for (i = 0; i < 20 && errors < 10; i++) { if ((r = pthread_create(&threads[0], NULL, t1, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[1], NULL, t2, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[2], NULL, t3, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if (pthread_join(threads[0], NULL) != 0) err(1, "pthread_join(%d)", 0); if (pthread_join(threads[1], NULL) != 0) err(1, "pthread_join(%d)", 1); if (pthread_join(threads[2], NULL) != 0) err(1, "pthread_join(%d)", 2); } close(fd); if (unlink(file) == -1) err(3, "unlink(%s)", file); return (0); } Index: user/pho/stress2/misc/fcntl.sh =================================================================== --- user/pho/stress2/misc/fcntl.sh (revision 278500) +++ user/pho/stress2/misc/fcntl.sh (revision 278501) @@ -1,223 +1,225 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # fcntl(2) locking scenario. No problems seen. +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fcntl.c -cc -o fcntl -Wall -Wextra -O0 -g fcntl.c || exit 1 +mycc -o fcntl -Wall -Wextra -O0 -g fcntl.c || exit 1 rm -f fcntl.c /tmp/fcntl status=$? rm -f /tmp/fcntl exit $status EOF #include #include #include #include #include #include #include #include #include #include #define PARALLEL 16 #define N 4096 static volatile sig_atomic_t completed; const char name[] = "work"; int fd; static void handler(int s __unused) { completed++; } void add(int n, int increment) { struct flock fl; off_t pos; long val, oval; int r; pos = n * sizeof(val); memset(&fl, 0, sizeof(fl)); fl.l_start = pos; fl.l_len = sizeof(val); fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; while (fcntl(fd, F_SETLK, &fl) < 0) { if (errno != EAGAIN) err(1, "F_SETLK (child)"); usleep(100); } if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); oval = 999999; while ((r = read(fd, &val, sizeof(val)) != sizeof(val))) { if (r == -1 && errno != EAGAIN) err(1, "read"); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); } oval = val; val = val + increment; #if defined(DEBUG) fprintf(stderr, "add(%d, %d) @ pos %ld: %ld = %ld + %d\n", n, increment, (long)pos, val, oval, increment); #endif if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); while ((r = write(fd, &val, sizeof(val)) != sizeof(val))) { if (r == -1 && errno != EAGAIN) err(1, "write"); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); } fl.l_type = F_UNLCK; if (fcntl(fd, F_SETLK, &fl) < 0) err(1, "F_UNLCK"); } void up(void) { int flags, i; /* Need to re-open after a fork() */ close(fd); if ((fd = open(name, O_RDWR)) == -1) err(1, "open(%s)", name); if ((flags = fcntl(fd, F_GETFL)) == -1) err(1, "fcntl(%d, T_GETFL)", fd); flags |= O_NONBLOCK; if ((flags = fcntl(fd, F_SETFL, flags)) == -1) err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); for (i = 0; i < N; i++) add(i, 1); kill(getppid(), SIGHUP); while (access("work", R_OK) == 0) usleep(100); _exit(0); } void down(void) { int flags, i; close(fd); if ((fd = open(name, O_RDWR)) == -1) err(1, "open(%s)", name); if ((flags = fcntl(fd, F_GETFL)) == -1) err(1, "fcntl(%d, T_GETFL)", fd); flags |= O_NONBLOCK; if ((flags = fcntl(fd, F_SETFL, flags)) == -1) err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); for (i = 0; i < N; i++) add(i, -1); kill(getppid(), SIGHUP); while (access("work", R_OK) == 0) usleep(100); _exit(0); } int main(void) { int flags, i; long val, sum; off_t len; signal(SIGHUP, handler); if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", name); len = N * sizeof(val); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if ((flags = fcntl(fd, F_GETFL)) == -1) err(1, "fcntl(%d, T_GETFL)", fd); flags |= O_NONBLOCK; if ((flags = fcntl(fd, F_SETFL, flags)) == -1) err(1, "fcntl(%d, T_SETFL, %d)", fd, flags); for (i = 0; i < PARALLEL; i++) { if (fork() == 0) up(); } for (i = 0; i < PARALLEL; i++) { if (fork() == 0) down(); } while (completed != PARALLEL * 2) usleep(200); if (lseek(fd, 0, SEEK_SET) == -1) err(1, "lseek"); sum = 0; for (i = 0; i < N; i++) { if (read(fd, &val, sizeof(val)) != sizeof(val)) err(1, "Final read"); if (val != 0) fprintf(stderr, "index %d: %ld\n", i, val); sum += val; } if (sum != 0) fprintf(stderr, "FAIL\n"); unlink(name); for (i = 0; i < PARALLEL; i++) { wait(NULL); wait(NULL); } close(fd); return (sum != 0); } Index: user/pho/stress2/misc/fdgrowtable.sh =================================================================== --- user/pho/stress2/misc/fdgrowtable.sh (revision 278500) +++ user/pho/stress2/misc/fdgrowtable.sh (revision 278501) @@ -1,104 +1,104 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for r236822. # http://people.freebsd.org/~pho/stress/log/fdgrowtable.txt # Fixed in r256210. . ../default.cfg max=`sysctl kern.maxfilesperproc | sed 's/.*: //'` here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fdgrowtable.c -cc -o fdgrowtable -Wall -Wextra -O2 fdgrowtable.c || exit 1 +mycc -o fdgrowtable -Wall -Wextra -O2 fdgrowtable.c || exit 1 rm -f fdgrowtable.c cd $here su ${testuser} -c "/tmp/fdgrowtable $max" & while kill -0 $! 2>/dev/null; do ../testcases/swap/swap -t 2m -i 40 -h done wait rm -d /tmp/fdgrowtable exit EOF #include #include #include #include #include #include #include #include #include #define PARALLEL 3 int max; void test(void) { int i; for (i = 0; i < max; i++) { if (dup2(1, i + 3) == -1) err(1, "dup2(%d)", i + 3); } _exit(0); } int main(int argc, char **argv) { int i, j; if (argc == 2) max = atoi(argv[1]); else err(1, "Usage: %s ", argv[0]); max = (max - 3) / PARALLEL; for (j = 0; j < 300; j++) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/fifo.sh =================================================================== --- user/pho/stress2/misc/fifo.sh (revision 278500) +++ user/pho/stress2/misc/fifo.sh (revision 278501) @@ -1,87 +1,87 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Page fault seen. # http://people.freebsd.org/~pho/stress/log/kostik652.txt # Fixed by r259522. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fifo.c rm -f /tmp/fifo -cc -o fifo -Wall -Wextra -O2 -g fifo.c || exit 1 +mycc -o fifo -Wall -Wextra -O2 -g fifo.c || exit 1 rm -f fifo.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint (cd $mntpoint; /tmp/fifo) for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 10 done rm -f /tmp/fifo exit EOF #include #include #include #include #include #include #include #include #include int main(void) { int fd; if (mkfifo("fifo", 0644) == -1) err(1, "mkfifo"); fd = open("fifo", O_RDWR | O_SHLOCK | O_EXLOCK); fd = open("fifo", 0x60e9f2, 0xc74c65b1db4be370, 0xb64a34df72368759); return (0); } Index: user/pho/stress2/misc/fifo2.sh =================================================================== --- user/pho/stress2/misc/fifo2.sh (revision 278500) +++ user/pho/stress2/misc/fifo2.sh (revision 278501) @@ -1,215 +1,215 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Page fault seen # http://people.freebsd.org/~pho/stress/log/kostik654.txt # Fixed by r259521. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg killall 2>&1 | grep -q q && q="-q" odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fifo2.c rm -f /tmp/fifo2 -cc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 +mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 rm -f fifo2.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint mkfifo $mntpoint/f chmod 777 $mntpoint/f sleeptime=12 st=`date '+%s'` while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do (cd $mntpoint; /tmp/fifo2) & start=`date '+%s'` while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do ps aux | grep -v grep | egrep -q "fifo2$" || break sleep .5 done if ps aux | grep -v grep | egrep -q "fifo2$"; then killall $q fifo2 ps aux | grep -v grep | egrep -q "fifo2 " && killall $q -9 fifo2 fi wait done killall $q -9 fifo2 ps aux | grep -v grep | egrep -v "\.sh" | grep -q fifo2 && killall $q -9 fifo2 for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint > /dev/null 2>&1 && mdconfig -d -u $mdstart && break sleep 10 done mount | grep -q md${mdstart}$part && echo "umount $mntpoint failed" rm -f /tmp/fifo2 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * calls(void *arg __unused) { int i, num; unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; for (i = 0;; i++) { arg1 = (unsigned long)(void *)"f"; arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); #if 0 fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); usleep(100000); #endif alarm(1); syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); num = 0; } return (0); } int main(void) { struct passwd *pw; struct rlimit limit; pthread_t cp[50]; time_t start; int j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); limit.rlim_cur = limit.rlim_max = 1000; if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); start = time(NULL); while ((time(NULL) - start) < 120) { if (fork() == 0) { arc4random_stir(); for (j = 0; j < 1; j++) if (pthread_create(&cp[j], NULL, calls, NULL) != 0) perror("pthread_create"); for (j = 0; j < 1; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } Index: user/pho/stress2/misc/flock_open_close.sh =================================================================== --- user/pho/stress2/misc/flock_open_close.sh (revision 278500) +++ user/pho/stress2/misc/flock_open_close.sh (revision 278501) @@ -1,166 +1,166 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Demonstrate that close() of an flock'd file is not atomic. # Fails with "flock_open_close: execv(/mnt/test): Text file busy" # Test scenario by: jhb [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > flock_open_close.c rm -f /tmp/flock_open_close -cc -o flock_open_close -Wall -Wextra -O2 -g flock_open_close.c -lpthread || exit 1 +mycc -o flock_open_close -Wall -Wextra -O2 -g flock_open_close.c -lpthread || exit 1 rm -f flock_open_close.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint cp /bin/test $mntpoint chown $testuser $mntpoint/test chmod +w $mntpoint/test su $testuser -c "/tmp/flock_open_close $mntpoint/test" & while kill -0 $! 2>/dev/null; do mksnap_ffs $mntpoint $mntpoint/.snap/snap sleep 2 rm -f $mntpoint/.snap/snap sleep 1 done wait for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 2 done if mount | grep -q md${mdstart}$part; then fstat $mntpoint echo "umount $mntpoint failed" exit 1 fi rm -f /tmp/flock_open_close exit EOF #include #include #include #include #include #include #include #include #include static void usage(void) { fprintf(stderr, "Usage: flock_close_race [args]\n"); exit(1); } static void child(const char *binary) { int fd; /* Exit as soon as our parent exits. */ while (getppid() != 1) { fd = open(binary, O_RDWR | O_EXLOCK); if (fd < 0) { /* * This may get ETXTBSY since exit() will * close its open fd's (thus releasing the * lock), before it releases the vmspace (and * mapping of the binary). */ if (errno == ETXTBSY) continue; err(1, "can't open %s", binary); } close(fd); } exit(0); } static void exec_child(char **av) { int fd; fd = open(av[0], O_RDONLY | O_SHLOCK); execv(av[0], av); /* "flock_open_close: execv(/mnt/test): Text file busy" seen */ err(127, "execv(%s)", av[0]); } int main(int ac, char **av) { struct stat sb; pid_t pid; int i, status; if (ac < 2) usage(); if (stat(av[1], &sb) != 0) err(1, "stat(%s)", av[1]); if (!S_ISREG(sb.st_mode)) errx(1, "%s not an executable", av[1]); pid = fork(); if (pid < 0) err(1, "fork"); if (pid == 0) child(av[1]); for (i = 0; i < 200000; i++) { pid = fork(); if (pid < 0) err(1, "vfork"); if (pid == 0) exec_child(av + 1); wait(&status); if (WIFEXITED(status) && WEXITSTATUS(status) == 127) { fprintf(stderr, "FAIL\n"); break; } } return (0); } Index: user/pho/stress2/misc/fork.sh =================================================================== --- user/pho/stress2/misc/fork.sh (revision 278500) +++ user/pho/stress2/misc/fork.sh (revision 278501) @@ -1,129 +1,131 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # The test program calls fork(2) from a multi-threaded process. # Test program stuck in uwrlck seen. # Fixed in r266609. # Note that program erroneously calls exit(3) and not _exit(2). +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fork.c -cc -o fork -Wall -Wextra -O2 -g fork.c -lpthread || exit 1 +mycc -o fork -Wall -Wextra -O2 -g fork.c -lpthread || exit 1 for i in `jot 100`; do /tmp/fork & done while ! pgrep -q fork; do sleep .2 done for i in `jot 30`; do pgrep -q fork || break sleep 1 done if pgrep -q fork; then echo FAIL exit 1 fi wait rm -f /tmp/fork /tmp/fork.c exit 0 EOF /* * Written by Love Hörnquist Åstrand , March 2003. * Public domain. */ #include #include #include #include #include #include #include #include #include #include static pid_t parent; static int thread_survived = 0; static void * print_pid(void *arg __unused) { sleep(3); thread_survived = 1; if (parent != getpid()) { exit(1); } return NULL; } int main(void) { int r; pthread_t p; pid_t fork_pid; parent = getpid(); r = pthread_create(&p, NULL, print_pid, NULL); if (r != 0) errx(1, "r = %d", r); fork_pid = fork(); if (fork_pid == -1) err(1, "fork"); if (fork_pid) { int status; r = pthread_join(p, NULL); if (r != 0) errx(1, "r = %d", r); if (thread_survived == 0) errx(1, "thread did not survive in parent"); waitpid(fork_pid, &status, 0); if (WIFEXITED(status) != 1) printf("WIFEXITED(status) = %d\n", WIFEXITED(status)); if (WEXITSTATUS(status) != 0) printf("WEXITSTATUS(status) = %d\n", WEXITSTATUS(status)); } else { sleep(5); exit(thread_survived ? 1 : 0); } } Index: user/pho/stress2/misc/fpclone2.sh =================================================================== --- user/pho/stress2/misc/fpclone2.sh (revision 278500) +++ user/pho/stress2/misc/fpclone2.sh (revision 278501) @@ -1,115 +1,115 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by kib@freebsd.org -# Test of +# Test of patch for Giant trick in cdevsw [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` dir=$RUNDIR/fpclone [ ! -d $dir ] && mkdir -p $dir cd $dir cat > Makefile < EOF sed '1,/^EOF2/d' < $odir/fpclone.sh > fpclone.c make kldload $dir/fpclone.ko sed '1,/^EOF2/d' < $odir/$0 > fpclone2.c -cc -o fpclone2 -Wall fpclone2.c +mycc -o /tmp/fpclone2 -Wall fpclone2.c rm -f fpclone2.c cd $odir for i in `jot 10`; do - $dir/fpclone2 & + /tmp/fpclone2 & done for i in `jot 10`; do wait done kldstat kldunload $dir/fpclone.ko -rm -rf $dir fpclone2 +rm -rf $dir /tmp/fpclone2 exit EOF2 #include #include #include #include #include #include int main(int argc, char **argv) { int fd; int i; char buf[80]; for (i = 0; i < 10000; i++) { if ((fd = open("/dev/fpclone", O_RDONLY)) == -1) err(1, "open(/dev/fpclone"); if (read(fd, buf, sizeof(buf)) <= 0) err(1, "read"); if (dup2(fd, 10) == -1) err(1, "dup"); if (dup2(fd, 11) == -1) err(1, "dup"); if (dup2(fd, 12) == -1) err(1, "dup"); if (close(fd) == -1) err(1, "close(%d)", fd); if (close(10) == -1) err(1, "close(%d)", 10); if (close(11) == -1) err(1, "close(%d)", 11); if (close(12) == -1) err(1, "close(%d)", 12); } if ((fd = open("/dev/fpclone", O_WRONLY)) == -1) err(1, "open(/dev/fpclone"); if (write(fd, "xxx", 3) == -1 && errno != ENODEV) err(1, "write"); if (close(fd) == -1) err(1, "close(%d)", fd); return (0); } Index: user/pho/stress2/misc/fpu.sh =================================================================== --- user/pho/stress2/misc/fpu.sh (revision 278500) +++ user/pho/stress2/misc/fpu.sh (revision 278501) @@ -1,105 +1,105 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for FPU changes in r208833 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fpu.c -cc -o fpu -Wall -O2 fpu.c +mycc -o fpu -Wall -O2 fpu.c rm -f fpu.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR r=`/tmp/fpu` [ "$r" = "-0.000000017, 0.000000000, 0.000000000" ] || echo $r cd $here rm -f /tmp/fpu exit 0 EOF #include #include #include #include #include #include void handler(int i) { } void test() { float val = 0; double lval = 0; long double llval = 0; int i, j; for (i = 0; i < 100000; i++) { for (j = 0; j < 100000; j++) { val = val + 0.00001; lval = lval + 0.00001; llval = llval + 0.00001; } for (j = 0; j < 100000; j++) { val = val - 0.00001; lval = lval - 0.00001; llval = llval - 0.00001; } } printf("%.9f, %.9f, %.9Lf\n", val, lval, llval); exit(0); } int main() { pid_t pid; int i; signal(SIGHUP, handler); if ((pid = fork()) == 0) test(); for (i = 0; i < 10000; i++) kill(pid, SIGHUP); wait(NULL); return (0); } Index: user/pho/stress2/misc/fragments.sh =================================================================== --- user/pho/stress2/misc/fragments.sh (revision 278500) +++ user/pho/stress2/misc/fragments.sh (revision 278501) @@ -1,280 +1,280 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Scenario that causes "panic: brelse: free buffer onto another queue???" # Idea for scenario by kib@. Fixed in r203818 # When UFS partition is full, then some high load causes # panic: brelse: free buffer onto another queue??? [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fragments.c rm -f /tmp/fragments -cc -o fragments -Wall -Wextra -O2 -g fragments.c +mycc -o fragments -Wall -Wextra -O2 -g fragments.c rm -f fragments.c cd $here mount | grep "$mntpoint" | grep -q md$mdstart && umount -f ${mntpoint} mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags -m 0 md${mdstart}$part > /dev/null 2>&1 mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint cd $mntpoint su $testuser -c "/tmp/fragments" cd $here umount $mntpoint mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart rm -f /tmp/fragments exit EOF #include #include #include #include #include #include #include #include #include #include #include #include //#define LOOPS 50000 #define LOOPS 600 #define PARALLEL 8 static pid_t pid; static char *buf; static volatile sig_atomic_t stop; void handler(int i __unused) { stop = 1; } void cleanup(int n) { int i, j, start; int nb = 0; char file[128]; struct statfs sbuf; struct stat sb; if (n == -1) { for (i = 0; i < LOOPS; i++) { sprintf(file,"t%05d", i); unlink(file); } return; } start = arc4random() % n; for (i = 0; i < LOOPS; i++) { j = (start + i) % LOOPS; sprintf(file,"t%05d", j); if (stat(file, &sb) != 0) continue; if (sb.st_size == 0) { unlink(file); continue; } if (truncate(file, 0) == 0) { nb++; continue; } if (nb > 10) break; } for (i = 0; i < 10; i++) { if (statfs(".", &sbuf) < 0) err(1, "statfs(%s)", "."); if (sbuf.f_bfree > 8) return; } for (i = 0; i < LOOPS; i++) { j = (start + i) % LOOPS; sprintf(file,"t%05d", j); if (unlink(file) == 0) { return; } } } void fragments(void) { int i, len; char file[128]; int fd; for (i = 0;; i++) { sprintf(file,"d%d/f%05d.%05d", i/1000, pid, i); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { if (errno != ENOSPC) warn("open(%s)", file); break; } len = 2 * 1024; if (write(fd, buf, len) != len) { } close(fd); } } void blocks(void) { int i, len; char file[128]; int fd; for (i = 0;; i++) { sprintf(file,"d%d/b%05d.%05d", i/1000, pid, i); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { if (errno != ENOSPC) warn("open(%s)", file); break; } len = 16 * 1024; if (write(fd, buf, len) != len) { } close(fd); } } void setup(void) { int i; char file[128]; for (i = 0; i < 300; i++) { sprintf(file,"d%d", i); if (mkdir(file, 0700) == -1) warn("mkdir(%s)", file); } blocks(); fragments(); for (i = 0;i < 8; i++) { sprintf(file,"d%d/b%05d.%05d", i/1000, pid, i); unlink(file); } for (i = 0;i < 1; i++) { sprintf(file,"d%d/f%05d.%05d", i/1000, pid, i); unlink(file); } } int test(void) { int i, len, n; char file[128]; int fd; for (i = 0; i < LOOPS; i++) { sprintf(file,"t%05d", i); if ((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) { continue; } // n = arc4random() % (12 + 1); n = 0; len = (arc4random() % (16 * 1024) + 1) + n * 16; while (len > 0) { if (write(fd, buf, len) == len) break; len = len / 2; usleep(1000); } close(fd); if (len == 0) { cleanup(i); } } exit(0); return (0); } int main() { int i, j, status; pid = getpid(); if ((buf = malloc(12 * 16 * 1024)) == NULL) err(1, "malloc()"); setup(); signal(SIGALRM, handler); alarm(30 * 60); for (j = 0; j < 50 && stop == 0; j++) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) wait(&status); cleanup(-1); } return (0); } Index: user/pho/stress2/misc/fts.sh =================================================================== --- user/pho/stress2/misc/fts.sh (revision 278500) +++ user/pho/stress2/misc/fts.sh (revision 278501) @@ -1,143 +1,143 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Run with marcus.cfg on a 1g swap backed MD # "panic: vm_radix_remove: invalid key found" seen. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > fts.c -cc -o fts -Wall -Wextra fts.c +mycc -o fts -Wall -Wextra fts.c rm -f fts.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint export runRUNTIME=30m export RUNDIR=$mntpoint/stressX su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null & pid=$! while kill -0 $pid 2> /dev/null; do /tmp/fts $mntpoint sleep 1 done while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/fts exit EOF #include #include #include #include #include #include #include #include #include #include int test(char *path) { FTS *fts; FTSENT *p; int ftsoptions; char *args[2]; ftsoptions = FTS_PHYSICAL; args[0] = path; args[1] = 0; if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { switch (p->fts_info) { case FTS_F: /* Ignore. */ break; case FTS_D: /* Ignore. */ break; case FTS_DP: break; case FTS_DC: /* Ignore. */ break; case FTS_SL: /* Ignore. */ break; case FTS_DNR: /* Warn, continue. */ case FTS_ERR: case FTS_NS: case FTS_DEFAULT: break; default: printf("%s: default, %d\n", getprogname(), p->fts_info); break; } } if (errno != 0 && errno != ENOENT) err(1, "fts_read"); if (fts_close(fts) == -1) err(1, "fts_close()"); return (0); } int main(int argc, char **argv) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); alarm(600); for (i = 0; i < 100; i++) test(argv[1]); return (0); } Index: user/pho/stress2/misc/fullpath.sh =================================================================== --- user/pho/stress2/misc/fullpath.sh (revision 278500) +++ user/pho/stress2/misc/fullpath.sh (revision 278501) @@ -1,114 +1,114 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by marcus@freebsd.org [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 [ -z "`type perl 2>/dev/null`" ] && exit 0 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fullpath.c -cc -o fullpath -Wall fullpath.c +mycc -o fullpath -Wall fullpath.c rm -f fullpath.c cd /proc for i in `jot 5`; do /tmp/fullpath & done for i in `jot 30`; do for j in `jot 25`; do pid=`perl -e 'print splice(@ARGV,rand(@ARGV),1), " ";' $(echo [0-9]*)` # echo $pid procstat -f $pid > /dev/null 2>&1 procstat -f $pid > /dev/null 2>&1 procstat -f $pid > /dev/null 2>&1 procstat -f $pid > /dev/null 2>&1 procstat -f $pid > /dev/null 2>&1 done done for i in `jot 5`; do wait done rm -f /tmp/fullpath exit EOF #include #include #include #include #include #include #include char buf[4096]; void handler(int i) { exit(0); } int test(void) { pid_t r; int status; for (;;) { r = fork(); if (r == 0) { bzero(buf, sizeof(buf)); exit(0); /*child dies */ } if (r < 0) { perror("fork"); exit(2); } wait(&status); } return 0; } int main(int argc, char **argv) { int i; i = 0; signal(SIGALRM, handler); alarm(60); return test(); } Index: user/pho/stress2/misc/fuzz.sh =================================================================== --- user/pho/stress2/misc/fuzz.sh (revision 278500) +++ user/pho/stress2/misc/fuzz.sh (revision 278501) @@ -1,180 +1,180 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Stress test UFS2 file systems by introducing single bit errors in the FS # fsck should fix the FS no matter how damaged, but e.g. this panic has been seen: # # panic(c0912b65,dfe96000,0,c09e4060,ef48c778,...) at panic+0x14b # vm_fault(c1868000,dfe96000,1,0) at vm_fault+0x1e0 # trap_pfault(ef48c894,0,dfe96000) at trap_pfault+0x137 # trap(dfe90008,ef480028,c0690028,d0560000,dfe96000,...) at trap+0x341 # calltrap() at calltrap+0x5 # --- trap 0xc, eip = 0xc08785a6, esp = 0xef48c8d4, ebp = 0xef48c958 --- # generic_bcopy(c81cd570,d0508000,c5ead600,c87b81c0,0,...) at generic_bcopy+0x1a # ffs_mount(d0508000,c5ead600,0,c09b0860,c5ecfc3c,...) at ffs_mount+0xa14 # vfs_domount(c5ead600,cd8c7280,ccb75080,0,...) at vfs_domount+0x687 # vfs_donmount(c5ead600,0,ef48cc04) at vfs_donmount+0x2ef # kernel_mount(c5660960,0,bfbfec86,0,fffffffe,...) at kernel_mount+0x6d # ffs_cmount(c5660960,bfbfde50,0,c5ead600,c09b0860,...) at ffs_cmount+0x5d # mount(c5ead600,ef48cd04) at mount+0x156 # syscall(3b,3b,3b,804abcf,bfbfe8e4,...) at syscall+0x22f [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg D=$diskimage tst() { rm -f $D truncate -s 2M $D mdconfig -a -t vnode -f $D -u $mdstart bsdlabel -w md$mdstart auto newfs -b 8192 -f 1024 $newfs_flags /dev/md${mdstart}$part > /dev/null 2>&1 mount /dev/md${mdstart}$part $mntpoint cp /etc/passwd /etc/group /etc/hosts $mntpoint cp -r /usr/include/ufs $mntpoint umount $mntpoint for i in `jot 50`; do ./fuzz -n 50 $D if fsck -f -y /dev/md${mdstart}$part 2>&1 | egrep "^[A-Z]" > /dev/null; then if fsck -f -y /dev/md${mdstart}$part 2>&1 | egrep "^[A-Z]" > /dev/null; then if fsck -f -y /dev/md${mdstart}$part 2>&1 | egrep "^[A-Z]" > /dev/null; then echo "fsck is giving up in loop $i!" break fi fi fi sync;sync;sync if mount /dev/md${mdstart}$part $mntpoint; then ls -l $mntpoint > /dev/null find $mntpoint -exec dd if={} of=/dev/null bs=1m count=3 \; > /dev/null 2>&1 umount $mntpoint else echo "Giving up at loop $i" break fi done mdconfig -d -u ${mdstart} rm -f $D } odir=`pwd` dir=/tmp cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/fuzz.c -cc -o fuzz -Wall fuzz.c +mycc -o fuzz -Wall fuzz.c rm -f fuzz.c for j in `jot 10`; do date '+%T' tst done rm -f fuzz exit EOF #include #include #include #include #include #include void usage(void) { fprintf(stderr, "%s {-n \n", getprogname()); exit(1); } long random_long(long mi, long ma) { return (arc4random() % (ma - mi + 1) + mi); } int main(int argc, char **argv) { int ch, fd, i, times = 1, verbose = 0; long pos; unsigned char bit, buf, mask, old; struct stat sb; while ((ch = getopt(argc, argv, "n:v")) != -1) switch(ch) { case 'n': /* Bits to alter */ if (sscanf(optarg, "%d", ×) != 1) usage(); break; case 'v': /* verbose flag */ verbose += 1; break; default: usage(); } argc -= optind; argv += optind; if (argc == 0) usage(); if ((fd = open(argv[0], O_RDWR)) == -1) err(1, "open(%s)", argv[0]); if (fstat(fd, &sb) == -1) err(1, "stat(%s)", argv[0]); for (i = 0; i < times; i++) { pos = random_long(0, sb.st_size - 1); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "fseek(%d, %ld)", fd, pos); if (read(fd, &buf, 1) != 1) err(1, "read(%d)", fd); bit = random_long(0,7); mask = ~(1 << bit); old = buf; buf = (buf & mask) | (~buf & ~mask); if (verbose > 0) printf("Change %2x to %2x at %4ld by flipping bit %d\n", old, buf, pos, bit); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "fseek(%d, %ld)", fd, pos); if (write(fd, &buf, 1) != 1) err(1, "write(%d)", fd); } close(fd); return (0); } Index: user/pho/stress2/misc/holdcnt0.sh =================================================================== --- user/pho/stress2/misc/holdcnt0.sh (revision 278500) +++ user/pho/stress2/misc/holdcnt0.sh (revision 278501) @@ -1,244 +1,244 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: cluster_wbuild: page 0xc2eebc10 failed shared busing" seen. # "panic: vdrop: holdcnt 0" seen. # "panic: cleaned vnode isn't" seen. # Test scenario suggestion by alc@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 -[ `uname -m` = "i386" ] && exit 0 # Not enough vm . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > holdcnt0.c -cc -o holdcnt0 -Wall -Wextra -g holdcnt0.c || exit 1 +mycc -o holdcnt0 -Wall -Wextra -g holdcnt0.c || exit 1 rm -f holdcnt0.c +[ `uname -m` = "i386" ] && exit 0 # Not enough vm cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 5g -u $mdstart bsdlabel -w md$mdstart auto newfs md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint (cd $mntpoint; /tmp/holdcnt0) & sleep 5 while kill -0 $! 2> /dev/null; do (cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1 done wait while mount | grep -q md${mdstart}$part; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/holdcnt0 exit 0 EOF /* A test that causes the page daemon to generate cached pages within a bunch of files and has some consumer that is trying to allocate new pages to the same files. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define BUFSIZE (1024 * 1024) #define FILES 200 #define RPARALLEL 8 #define WPARALLEL 2 static jmp_buf jbuf; off_t maxsize; int ps; static char *buf; volatile char val; static void hand(int i __unused) { /* handler */ longjmp(jbuf, 1); } void cleanup(void) { int i; char file[80]; for (i = 0; i < FILES; i++) { snprintf(file, sizeof(file), "f%06d", i); unlink(file); } } void init(void) { char file[80]; int fd, i; for (i = 0; i < FILES; i++) { snprintf(file, sizeof(file), "f%06d", i); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "open(%s)", file); if (write(fd, buf, BUFSIZE) != BUFSIZE) err(1, "write"); close(fd); } } void writer(void) { int fd, i; char file[80]; time_t start; struct stat statbuf; setproctitle("writer"); start = time(NULL); while (time(NULL) - start < 600) { for (i = 0; i < FILES; i++) { snprintf(file, sizeof(file), "f%06d", i); if ((fd = open(file, O_RDWR | O_APPEND)) == -1) { if (errno != ENOENT) err(1, "open(%s) append", file); goto err; } if (fstat(fd, &statbuf) < 0) err(1, "fstat error"); if (statbuf.st_size < maxsize) { if (write(fd, buf, ps) != ps) { warn("writer"); goto err; } } close(fd); } } err: cleanup(); _exit(0); } void reader(void) { int fd, i, j, n; void *p; size_t len; char file[80]; struct stat statbuf; setproctitle("reader"); signal(SIGSEGV, hand); fd = 0; for (;;) { (void)setjmp(jbuf); for (i = 0; i < FILES; i++) { snprintf(file, sizeof(file), "f%06d", i); if (fd > 0) close(fd); if ((fd = open(file, O_RDWR)) == -1) { if (errno != ENOENT) warn("reader(%s)", file); _exit(0); } if (fstat(fd, &statbuf) < 0) err(1, "fstat error"); if (statbuf.st_size >= maxsize) { if (ftruncate(fd, ps) == -1) err(1, "ftruncate"); continue; } len = statbuf.st_size; - if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) + if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap()"); close(fd); n = statbuf.st_size / ps; for (j = 0; j < n; j++) { val = *(char *)p; p = p + ps; } #if 0 if (munmap(p, len) == -1) perror("munmap"); #endif } } _exit(0); } int main(void) { int i; maxsize = 2LL * 1024 * 1024 * 1024 / FILES; buf = malloc(BUFSIZE); ps = getpagesize(); init(); for (i = 0; i < WPARALLEL; i++) { if (fork() == 0) writer(); } for (i = 0; i < RPARALLEL; i++) { if (fork() == 0) reader(); } for (i = 0; i < WPARALLEL; i++) wait(NULL); for (i = 0; i < RPARALLEL; i++) wait(NULL); free(buf); return (0); } Index: user/pho/stress2/misc/inversion.sh =================================================================== --- user/pho/stress2/misc/inversion.sh (revision 278500) +++ user/pho/stress2/misc/inversion.sh (revision 278501) @@ -1,90 +1,92 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Provokes a deadlock by lower priority process holding a lock and # never beeing run +. ../default.cfg + dir=/tmp N=5 # Number of CPUs + 1 M=25 # Number of lower priority jobs odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/inversion.c -cc -o inversion -Wall inversion.c +mycc -o inversion -Wall inversion.c rm -f inversion.c for i in `jot $N`; do ./inversion 1800 & done while pgrep inversion > /dev/null; do ( for i in `jot $M`; do nice -n 20 lockf -s -t 0 .lock pwd > /dev/null & done for i in `jot $M`; do wait done ) done for i in `jot $N`; do wait done rm -f inversion exit EOF #include #include #include void handler(int i) { exit(0); } int main(int argc, char **argv) { int t; if (argc == 2) t = atoi(argv[1]); else t = 60; signal(SIGALRM, handler); alarm(t); for (;;) ; return (0); } Index: user/pho/stress2/misc/isofs.sh =================================================================== --- user/pho/stress2/misc/isofs.sh (revision 278500) +++ user/pho/stress2/misc/isofs.sh (revision 278501) @@ -1,64 +1,64 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must not be root!" && exit 1 [ -z "`type mkisofs 2>/dev/null`" ] && echo "mkisofs not found" && exit 1 . ../default.cfg D=`dirname $diskimage`/dir I=`dirname $diskimage`/dir.iso export here=`pwd` cd /tmp -cc -o fstool $here/../tools/fstool.c +mycc -o fstool $here/../tools/fstool.c rm -rf $D $I mkdir $D (cd $D; /tmp/fstool -n 10 -l -f 512) mkisofs -o $I -r $D > /dev/null 2>&1 mdconfig -a -t vnode -f $I -u ${mdstart} mount -t cd9660 /dev/md${mdstart} $mntpoint for i in `jot 64`; do find /$mntpoint -type f > /dev/null 2>&1 & done for i in `jot 64`; do wait done umount ${mntpoint} mdconfig -d -u ${mdstart} rm -rf $D $I fstool Index: user/pho/stress2/misc/jail.sh =================================================================== --- user/pho/stress2/misc/jail.sh (revision 278500) +++ user/pho/stress2/misc/jail.sh (revision 278501) @@ -1,68 +1,68 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for problem found with the syscall.sh test . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > jail.c -cc -o jail -Wall jail.c +mycc -o jail -Wall jail.c rm -f jail.c cd $RUNDIR /tmp/jail rm -f /tmp/jail exit EOF #include #include #include int main() { struct jail j; j.version = 2; j.path = (char *)0xa000000; j.hostname = (char *)1; j.jailname = (char *)0; j.ip4s = 0; j.ip6s = 0; j.ip4 = (struct in_addr *)0x58000000; j.ip6 = (struct in6_addr *)0x33000001; if (jail(&j) == -1) err(1, "jail()"); return (0); } Index: user/pho/stress2/misc/jail2.sh =================================================================== --- user/pho/stress2/misc/jail2.sh (revision 278500) +++ user/pho/stress2/misc/jail2.sh (revision 278501) @@ -1,78 +1,78 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for problem found with the syscall.sh test . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > jail2.c -cc -o jail2 -Wall jail2.c +mycc -o jail2 -Wall jail2.c rm -f jail2.c cd $odir /tmp/jail2 rm -f /tmp/jail2 exit EOF #include #include #include int main() { struct jail j; /* version = 0x2, path = 0x0, hostname = 0x0, jailname = 0x50000000
, ip4s = 0xf7000004, ip6s = 0x1, ip4 = 0x0, ip6 = 0x0 */ j.version = 2; j.path = 0; j.hostname = 0; j.jailname = (char *)0x50000000; j.ip4s = 0xf7000004; j.ip6s = 1; j.ip4 = 0; j.ip6 = 0; if (jail(&j) == -1) err(1, "jail()"); return (0); } Index: user/pho/stress2/misc/jail3.sh =================================================================== --- user/pho/stress2/misc/jail3.sh (revision 278500) +++ user/pho/stress2/misc/jail3.sh (revision 278501) @@ -1,78 +1,78 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for problem found with the syscall.sh test . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > jail3.c -cc -o jail3 -Wall jail3.c +mycc -o jail3 -Wall jail3.c rm -f jail3.c cd $odir /tmp/jail3 rm -f /tmp/jail3 exit EOF #include #include #include int main() { struct jail j; /* version = 0x0, path = 0x2809cd61
, hostname = 0x2809b650
, jailname = 0x0, ip4s = 0x1, ip6s = 0x0, ip4 = 0x0, ip6 = 0x0 */ j.version = 0; j.path = (char *)0x2809cd61; j.hostname = (char *)0x2809b650; j.jailname = 0; j.ip4s = 1; j.ip6s = 0; j.ip4 = 0; j.ip6 = 0; if (jail(&j) == -1) err(1, "jail()"); return (0); } Index: user/pho/stress2/misc/jail4.sh =================================================================== --- user/pho/stress2/misc/jail4.sh (revision 278500) +++ user/pho/stress2/misc/jail4.sh (revision 278501) @@ -1,80 +1,80 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for problem found with the syscall.sh test # "panic: kern_jail: too many iovecs (28)" seen. . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > jail4.c -cc -o jail4 -Wall jail4.c +mycc -o jail4 -Wall jail4.c rm -f jail4.c cd $odir /tmp/jail4 rm -f /tmp/jail4 exit EOF #include #include #include int main() { struct jail j; /* version = 0x2, path = 0x28190cb1
, hostname = 0x28167b90
, jailname = 0x28198700
, ip4s = 0x0, ip6s = 0x0, ip4 = 0x0, ip6 = 0x0} */ j.version = 2; j.path = (char *)0x28190cb1; j.hostname = (char *)0x28167b90; j.jailname = (char *)0x28198700; j.ip4s = 0; j.ip6s = 0; j.ip4 = 0; j.ip6 = 0; if (jail(&j) == -1) err(1, "jail()"); return (0); } Index: user/pho/stress2/misc/kern_umtx_inf_loop.sh =================================================================== --- user/pho/stress2/misc/kern_umtx_inf_loop.sh (revision 278500) +++ user/pho/stress2/misc/kern_umtx_inf_loop.sh (revision 278501) @@ -1,150 +1,150 @@ #!/bin/sh # $FreeBSD$ # The program is a test case by Eric which demonstrates the # bug, unkillable spinning thread, owning a spinlock. # "panic: spin lock held too long" seen. # Fixed in r277970. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > kern_umtx_inf_loop.c -cc -o kern_umtx_inf_loop -Wall -Wextra -O0 -g kern_umtx_inf_loop.c \ +mycc -o kern_umtx_inf_loop -Wall -Wextra -O0 -g kern_umtx_inf_loop.c \ -lpthread || exit 1 rm -f kern_umtx_inf_loop.c /tmp/kern_umtx_inf_loop rm -f /tmp/kern_umtx_inf_loop exit 0 EOF /*- * Copyright (c) 2015 Eric van Gyzen * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_t contender; static void * contender_func(void *arg) { int error; (void) arg; error = pthread_mutex_lock(&the_mutex); if (error) errc(1, error, "pthread_mutex_lock contender"); fprintf(stderr, "contender lock succeeded\n"); error = pthread_mutex_unlock(&the_mutex); if (error) errc(1, error, "pthread_mutex_unlock contender"); fprintf(stderr, "contender unlock succeeded; exiting\n"); return (NULL); } static void * signaler_func(void *arg __unused) { int error; // Wait for the main thread to sleep. usleep(100000); error = pthread_kill(contender, SIGHUP); if (error) errc(1, error, "pthread_kill"); // Wait for the contender to lock umtx_lock // in umtx_repropagate_priority. usleep(100000); error = pthread_mutex_lock(&the_mutex); if (error) errc(1, error, "pthread_mutex_lock signaler"); return (NULL); } int main(void) { int error; pthread_mutexattr_t mattr; error = pthread_mutexattr_init(&mattr); if (error) errc(1, error, "pthread_mutexattr_init"); error = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); if (error) errc(1, error, "pthread_mutexattr_setprotocol"); error = pthread_mutex_init(&the_mutex, &mattr); if (error) errc(1, error, "pthread_mutex_init"); error = pthread_mutexattr_destroy(&mattr); if (error) errc(1, error, "pthread_mutexattr_destroy"); //error = pthread_mutex_lock(&the_mutex); //if (error) errc(1, error, "pthread_mutex_lock"); // Hack lock. *(int *)the_mutex = pthread_getthreadid_np(); error = pthread_create(&contender, NULL, contender_func, NULL); if (error) errc(1, error, "pthread_create"); // Wait for the contender to sleep. usleep(100000); pthread_t signaler; error = pthread_create(&signaler, NULL, signaler_func, NULL); if (error) errc(1, error, "pthread_create"); error = pthread_mutex_lock(&the_mutex); if (error) errc(1, error, "pthread_mutex_lock recurse"); return (0); } Index: user/pho/stress2/misc/kevent.sh =================================================================== --- user/pho/stress2/misc/kevent.sh (revision 278500) +++ user/pho/stress2/misc/kevent.sh (revision 278501) @@ -1,175 +1,175 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # panic: KN_INFLUX set when not suppose to be . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent.c -cc -o kevent -Wall kevent.c -pthread +mycc -o kevent -Wall kevent.c -pthread rm -f kevent.c [ -d "$RUNDIR" ] || mkdir -p $RUNDIR cd $RUNDIR for i in `jot 10`; do for j in `jot 12`; do /tmp/kevent > /dev/null 2>&1 & done for j in `jot 12`; do wait done done rm -f /tmp/kevent exit EOF #include #include #include #include #include #include #include #include pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static int waiting; static int fd1[2]; static int fd2[2]; static int fd3[2]; void * thr1(void *arg) { int n; int kq = -1; struct kevent ev[3]; if ((kq = kqueue()) < 0) err(1, "kqueue(). %s:%d", __FILE__, __LINE__); n = 0; EV_SET(&ev[n], fd1[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; EV_SET(&ev[n], fd2[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; EV_SET(&ev[n], fd3[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; if (kevent(kq, ev, n, NULL, 0, NULL) < 0) err(1, "kevent(). %s:%d", __FILE__, __LINE__); if (pthread_mutex_lock(&mutex) == -1) err(1, "pthread_mutex_lock"); waiting = 0; if (pthread_cond_signal(&cond) == -1) err(1, "pthread_cond_signal"); if (pthread_mutex_unlock(&mutex) == -1) err(1, "pthread_mutex_unlock"); n = 0; EV_SET(&ev[n], fd1[1], EVFILT_WRITE, EV_DELETE, 0, 0, 0); n++; if (kevent(kq, ev, n, NULL, 0, NULL) < 0) warn("kevent(). %s:%d", __FILE__, __LINE__); close(kq); // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); return (0); } void * thr2(void *arg) { if (pthread_mutex_lock(&mutex) == -1) err(1, "pthread_mutex_lock"); while (waiting == 1) { if (pthread_cond_wait(&cond, &mutex) == -1) err(1, "pthread_cond_wait"); } if (pthread_mutex_unlock(&mutex) == -1) err(1, "pthread_mutex_unlock"); // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); close(fd1[0]); close(fd1[1]); close(fd2[0]); close(fd2[1]); close(fd3[0]); close(fd3[1]); return (0); } int main(int argc, char **argv) { pthread_t threads[2]; int r; int i; for (i = 0; i < 10000; i++) { waiting = 1; // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); if (pipe(fd1) == -1) err(1, "pipe()"); if (pipe(fd2) == -1) err(1, "pipe()"); if (pipe(fd3) == -1) err(1, "pipe()"); if (pthread_mutex_init(&mutex, 0) == -1) err(1, "pthread_mutex_init"); if (pthread_cond_init(&cond, NULL) == -1) err(1, "pthread_cond_init"); if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if (pthread_join(threads[0], NULL) != 0) err(1, "pthread_join(%d)", 0); if (pthread_join(threads[1], NULL) != 0) err(1, "pthread_join(%d)", 1); if (pthread_mutex_destroy(&mutex) == -1) err(1, "pthread_mutex_destroy"); if (pthread_cond_destroy(&cond) == -1) err(1, "pthread_condattr_destroy"); } return (0); } Index: user/pho/stress2/misc/kevent2.sh =================================================================== --- user/pho/stress2/misc/kevent2.sh (revision 278500) +++ user/pho/stress2/misc/kevent2.sh (revision 278501) @@ -1,175 +1,176 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # . ../default.cfg odir=`pwd` cd /tmp -sed '1,/^EOF/d' < $odir/$0 > kevent.c -cc -o kevent -Wall kevent.c -pthread -rm -f kevent.c +sed '1,/^EOF/d' < $odir/$0 > kevent2.c +mycc -o kevent2 -Wall kevent2.c -pthread +rm -f kevent2.c cd $RUNDIR for i in `jot 10`; do for j in `jot 12`; do - /tmp/kevent > /dev/null 2>&1 & + /tmp/kevent2 > /dev/null 2>&1 & done for j in `jot 12`; do wait done done +rm -f /tmp/kevent2 exit EOF #include #include #include #include #include #include #include #include #include pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static int waiting; static int fd1[2]; static int fd2[2]; static int fd3[2]; void * thr1(void *arg) { int n; int kq = -1; struct kevent ev[3]; struct timespec ts; if ((kq = kqueue()) < 0) err(1, "kqueue(). %s:%d", __FILE__, __LINE__); n = 0; EV_SET(&ev[n], fd1[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; EV_SET(&ev[n], fd2[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; EV_SET(&ev[n], fd3[1], EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0); n++; if (kevent(kq, ev, n, NULL, 0, NULL) < 0) err(1, "kevent(). %s:%d", __FILE__, __LINE__); if (pthread_mutex_lock(&mutex) == -1) err(1, "pthread_mutex_lock"); waiting = 0; if (pthread_cond_signal(&cond) == -1) err(1, "pthread_cond_signal"); if (pthread_mutex_unlock(&mutex) == -1) err(1, "pthread_mutex_unlock"); n = 0; EV_SET(&ev[n], fd1[1], EVFILT_WRITE, EV_DELETE, 0, 0, 0); n++; ts.tv_sec = 0; ts.tv_nsec = 0; if (kevent(kq, ev, n, NULL, 0, &ts) < 0) err(1, "kevent(). %s:%d", __FILE__, __LINE__); close(kq); // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); close(fd1[1]); close(fd2[1]); close(fd3[1]); return (0); } void * thr2(void *arg) { if (pthread_mutex_lock(&mutex) == -1) err(1, "pthread_mutex_lock"); while (waiting == 1) { if (pthread_cond_wait(&cond, &mutex) == -1) err(1, "pthread_cond_wait"); } if (pthread_mutex_unlock(&mutex) == -1) err(1, "pthread_mutex_unlock"); // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); close(fd1[0]); close(fd2[0]); close(fd3[0]); return (0); } int main(int argc, char **argv) { pthread_t threads[2]; int r; int i; for (i = 0; i < 1000; i++) { waiting = 1; // printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout); if (pipe(fd1) == -1) err(1, "pipe()"); if (pipe(fd2) == -1) err(1, "pipe()"); if (pipe(fd3) == -1) err(1, "pipe()"); if (pthread_mutex_init(&mutex, 0) == -1) err(1, "pthread_mutex_init"); if (pthread_cond_init(&cond, NULL) == -1) err(1, "pthread_cond_init"); if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); if (pthread_join(threads[0], NULL) != 0) err(1, "pthread_join(%d)", 0); if (pthread_join(threads[1], NULL) != 0) err(1, "pthread_join(%d)", 1); if (pthread_mutex_destroy(&mutex) == -1) err(1, "pthread_mutex_destroy"); if (pthread_cond_destroy(&cond) == -1) err(1, "pthread_condattr_destroy"); } - + return (0); } Index: user/pho/stress2/misc/kevent3.sh =================================================================== --- user/pho/stress2/misc/kevent3.sh (revision 278500) +++ user/pho/stress2/misc/kevent3.sh (revision 278501) @@ -1,72 +1,73 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # . ../default.cfg odir=`pwd` cd /tmp -sed '1,/^EOF/d' < $odir/$0 > kevent.c -cc -o kevent -Wall kevent.c -pthread -rm -f kevent.c +sed '1,/^EOF/d' < $odir/$0 > kevent3.c +mycc -o kevent3 -Wall kevent3.c -pthread +rm -f kevent3.c cd $RUNDIR for i in `jot 64`; do for j in `jot 12`; do - /tmp/kevent > /dev/null 2>&1 & + /tmp/kevent3 > /dev/null 2>&1 & done for j in `jot 12`; do wait done done +rm -f /tmp/kevent3 exit EOF /* * Obtained from: * http://projects.info-pull.com/mokb/MOKB-24-11-2006.html */ #include #include #include #include #include int main(void) { struct kevent ke; int kq; kq = kqueue(); EV_SET(&ke, getpid(), EVFILT_PROC, EV_ADD, NOTE_EXIT|NOTE_EXEC|NOTE_TRACK, 0, NULL); kevent(kq, &ke, 1, NULL, 0, NULL); if (fork() != 0) kevent(kq, NULL, 0, &ke, 1, NULL); return (0); } Index: user/pho/stress2/misc/kevent4.sh =================================================================== --- user/pho/stress2/misc/kevent4.sh (revision 278500) +++ user/pho/stress2/misc/kevent4.sh (revision 278501) @@ -1,202 +1,202 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by kib@ . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent4.c -cc -o kevent4 -Wall kevent4.c -pthread +mycc -o kevent4 -Wall kevent4.c -pthread rm -f kevent4.c cd $odir export runRUNTIME=3m (cd ..; ./run.sh > /dev/null 2>&1) & rpid=$! (cd $RUNDIR; /tmp/kevent4 $rpid > /dev/null) & sleep 120 kill $rpid ../tools/killall.sh > /dev/null 2>&1 kill $! rm -f /tmp/kevent4 exit EOF // $FreeBSD$ #include #include #include #include #include #include #include #ifndef true # define true 1 #endif int kq; void err(const char *msg, int err_no) { fprintf(stderr, "%s: %s\n", msg, strerror(err_no)); exit(1); } void init_kq() { kq = kqueue(); if (kq == -1) err("kqueue", errno); } void add_watch(pid_t pid) { struct kevent kev; bzero(&kev, sizeof(kev)); kev.ident = pid; kev.flags = EV_ADD | EV_ENABLE; kev.filter = EVFILT_PROC; kev.fflags = NOTE_EXIT | NOTE_FORK | NOTE_EXEC | NOTE_TRACK; while (true) { int res = kevent(kq, &kev, 1, NULL, 0, NULL); if (res == -1) { if (errno == EINTR) continue; if (errno == ESRCH) break; int err_no = errno; char msg[64]; snprintf(msg, sizeof(msg), "kevent - add watch for pid %u", pid); err(msg, err_no); } else break; } } void del_watch(pid_t pid) { struct kevent kev; bzero(&kev, sizeof(kev)); kev.ident = pid; kev.flags = EV_DELETE; kev.filter = EVFILT_PROC; while (true) { int res = kevent(kq, &kev, 1, NULL, 0, NULL); if (res == -1) { if (errno == EINTR) continue; if (errno == ESRCH) break; int err_no = errno; char msg[64]; snprintf(msg, sizeof(msg), "kevent - del watch for pid %u", pid); err(msg, err_no); } else break; } } void polling() { struct kevent kev[10]; pid_t pid; int i; while (true) { bzero(&kev, sizeof(kev)); int res = kevent(kq, NULL, 0, kev, sizeof(kev) / sizeof(kev[0]), NULL); if (res == -1) { if (errno == EINTR) continue; if (errno == ESRCH) continue; err("kevent", errno); } for (i = 0; i < res; i++) { pid = kev[i].ident; if (kev[i].fflags & NOTE_CHILD) { add_watch(pid); printf("%u - new process, parent %u\n", pid, (unsigned int)kev[i].data); } if (kev[i].fflags & NOTE_FORK) { printf("%u forked\n", pid); } if (kev[i].fflags & NOTE_EXEC) { printf("%u called exec\n", pid); } if (kev[i].fflags & NOTE_EXIT) { printf("%u exited\n", pid); // del_watch(pid); } if (kev[i].fflags & NOTE_TRACK) { printf("%u forked - track\n", pid); } if (kev[i].fflags & NOTE_TRACKERR) { fprintf(stderr, "%u - track error\n", pid); } } } } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "pid ?\n"); return (2); } pid_t parent = atoi(argv[1]); init_kq(); add_watch(parent); polling(); return (0); } Index: user/pho/stress2/misc/kevent5.sh =================================================================== --- user/pho/stress2/misc/kevent5.sh (revision 278500) +++ user/pho/stress2/misc/kevent5.sh (revision 278501) @@ -1,166 +1,166 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test EVFILT_VNODE. Found page fault in knlist_add+0x39 # # Test scenario by kib@ . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent5.c -cc -o kevent5 -Wall -Wextra -O2 -g kevent5.c || exit 1 +mycc -o kevent5 -Wall -Wextra -O2 -g kevent5.c || exit 1 rm -f kevent5.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR /tmp/kevent5 kevent5.xxx kevent5.yyy > /dev/null 2>&1 rm -f /tmp/kevent5 kevent.xxx kevent.yyy exit EOF #include #include #include #include #include #include #include #include #include #include #include #include static char *file1, *file2; #define N 1000 void test(void) { int kq = -1; int n; struct kevent ev[2]; struct timespec ts; int fd; if ((fd = open(file1, O_RDONLY, 0)) == -1) err(1, "open(%s)(2)", file1); if ((kq = kqueue()) < 0) err(1, "kqueue()"); n = 0; EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE, 0, 0); n++; ts.tv_sec = 5; ts.tv_nsec = 0; if (kevent(kq, ev, n, NULL, 0, &ts) < 0) err(1, "kevent()"); memset(&ev, 0, sizeof(ev)); n = kevent(kq, NULL, 0, ev, 1, NULL); // printf("Event 1\n"); close(fd); close(kq); /* Once the rendezvous file is gone create a new kevent */ if ((fd = open(file2, O_RDONLY, 0)) == -1) err(1, "open(%s)(2)", file2); if ((kq = kqueue()) < 0) err(1, "kqueue()"); n = 0; EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE, 0, 0); n++; if (kevent(kq, ev, n, NULL, 0, NULL) < 0) err(1, "kevent()"); memset(&ev, 0, sizeof(ev)); n = kevent(kq, NULL, 0, ev, 1, &ts); // printf("Event 2\n"); close(fd); close(kq); } int main(int argc, char **argv) { int i, j; int fd; int status; if (argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); return (1); } file1 = argv[1]; file2 = argv[2]; for (j = 0; j < 100; j++) { if ((fd = open(file1, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1) err(1, "open(%s)", file1); close(fd); if ((fd = open(file2, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1) err(1, "open(%s)", file2); close(fd); for (i = 0; i < N; i++) { if (fork() == 0) { test(); return (0); } } sleep(1); if (unlink(file1) == -1) err(1, "unlink(%s). %s:%d\n", file1, __FILE__, __LINE__); sleep(1); if (unlink(file2) == -1) err(1, "unlink(%s). %s:%d\n", file2, __FILE__, __LINE__); for (i = 0; i < N; i++) { if (wait(&status) == -1) err(1, "wait(), %s:%d", __FILE__, __LINE__); } } return (0); } Index: user/pho/stress2/misc/kevent6.sh =================================================================== --- user/pho/stress2/misc/kevent6.sh (revision 278500) +++ user/pho/stress2/misc/kevent6.sh (revision 278501) @@ -1,156 +1,156 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "Sleeping thread (tid 101094, pid 13104) owns a non-sleepable lock" seen. # Fixed in r255798. . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent6.c -cc -o kevent6 -Wall -Wextra -O2 -g kevent6.c -lpthread || exit 1 +mycc -o kevent6 -Wall -Wextra -O2 -g kevent6.c -lpthread || exit 1 rm -f kevent6.c cd $odir mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u ${mdstart} bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "(cd $mntpoint; /tmp/kevent6)" while mount | grep -q $mntpoint; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/kevent6 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 8 static char path[80]; int fd; void * spin(void *arg __unused) { int i; for (i= 0;; i++) { snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1, "creat()"); close(fd); usleep(10000); fd = 0; unlink(path); } return (NULL); } void * test(void *arg __unused) { int kq; int i, n; struct kevent ev; struct timespec ts; for (i = 0; i < 500000; i++) { if ((kq = kqueue()) < 0) err(1, "kqueue()"); n = 0; memset(&ev, 0, sizeof(ev)); EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); n++; if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) { close(kq); continue; } memset(&ev, 0, sizeof(ev)); ts.tv_sec = 0; ts.tv_nsec = 1000000; if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) err(1, "kevent()"); close(kq); } return (NULL); } int main(void) { int i; pthread_t cp[PARALLEL], sp; if (pthread_create(&sp, NULL, spin, NULL) != 0) perror("pthread_create"); for (i = 0; i < PARALLEL; i++) { if (pthread_create(&cp[i], NULL, test, NULL) != 0) perror("pthread_create"); } for (i = 0; i < PARALLEL; i++) pthread_join(cp[i], NULL); close(fd); return (0); } Index: user/pho/stress2/misc/kevent7.sh =================================================================== --- user/pho/stress2/misc/kevent7.sh (revision 278500) +++ user/pho/stress2/misc/kevent7.sh (revision 278501) @@ -1,265 +1,265 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Threaded syscall(2) fuzz test inspired by the iknowthis test suite # by Tavis Ormandy # kevent(2) with random arguments. # Spinning threads seen. # Fixed in r255877. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg ulimit -t 200 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent7.c rm -f /tmp/kevent7 -cc -o kevent7 -Wall -Wextra -O2 -g kevent7.c -lpthread || exit 1 +mycc -o kevent7 -Wall -Wextra -O2 -g kevent7.c -lpthread || exit 1 rm -f kevent7.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint for i in `jot 5`; do (cd $mntpoint; /tmp/kevent7 $* < /dev/null) & sleep 60 killall -9 kevent7 done for i in `jot 5`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 10 done if mount | grep -q md${mdstart}$part; then fstat $mntpoint echo "umount $mntpoint failed" exit 1 fi rm -f /tmp/kevent7 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int fd[900], fds[2], socketpr[2]; #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; int syscallno; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions; char *args[5]; int i; ftsoptions = FTS_PHYSICAL; args[0] = "/dev"; args[1] = "/proc"; args[2] = "/usr/compat/linux/proc"; args[3] = "."; args[4] = 0; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) if ((fd[i] = open(p->fts_path, O_RDONLY)) == -1) continue; i++; i = i % 900; } if (fts_close(fts) == -1) if (errno != ENOTDIR) warn("fts_close()"); if (pipe(fds) == -1) err(1, "pipe()"); if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, socketpr) == -1) err(1, "socketpair()"); sleep(1); close(socketpr[0]); close(socketpr[1]); close(fds[0]); close(fds[1]); } return(0); } void * calls(void *arg __unused) { int i, kq, num; unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; if ((kq = kqueue()) < 0) err(1, "kqueue()"); for (i = 0;; i++) { if (i == 0) usleep(1000); num = syscallno; arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); #if 0 fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); #endif alarm(1); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); num = 0; } close(kq); return (0); } int main(void) { struct passwd *pw; time_t start; pthread_t rp, cp[50]; int j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); syscallno = SYS_kevent; start = time(NULL); while (time(NULL) - start < 120) { if (fork() == 0) { arc4random_stir(); if (pthread_create(&rp, NULL, test, NULL) != 0) perror("pthread_create"); usleep(1000); for (j = 0; j < 50; j++) if (pthread_create(&cp[j], NULL, calls, NULL) != 0) perror("pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } Index: user/pho/stress2/misc/kevent8.sh =================================================================== --- user/pho/stress2/misc/kevent8.sh (revision 278500) +++ user/pho/stress2/misc/kevent8.sh (revision 278501) @@ -1,161 +1,161 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # Out of VM seen due to missing close of kqueue handle. # Fixed in 256849 . ../default.cfg ulimit -k 10000 || { echo FAIL; exit 1; } odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent8.c -cc -o kevent8 -Wall -Wextra -O2 -g kevent8.c -lpthread || exit 1 +mycc -o kevent8 -Wall -Wextra -O2 -g kevent8.c -lpthread || exit 1 rm -f kevent8.c cd $odir mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u ${mdstart} bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "(cd $mntpoint; /tmp/kevent8)" & sleep 99 umount -f $mntpoint pkill kevent8 wait while mount | grep -q $mntpoint; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/kevent8 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 64 static char path[80]; int fd; void * spin(void *arg __unused) { int i; setproctitle("spin"); for (i= 0;; i++) { snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1, "creat()"); close(fd); fd = 0; unlink(path); } return (NULL); } void * test(void *arg __unused) { int kq; int i, n; struct kevent ev; struct timespec ts; for (i = 0; i < 500000; i++) { if ((kq = kqueue()) < 0) if (errno != ENOMEM) err(1, "kqueue()"); n = 0; memset(&ev, 0, sizeof(ev)); EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); n++; if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) continue; /* Note: missing close(kq)! */ memset(&ev, 0, sizeof(ev)); ts.tv_sec = 0; ts.tv_nsec = 1000000; if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) err(1, "kevent()"); close(kq); } return (NULL); } int main(void) { int i; pthread_t cp[PARALLEL], sp; if (pthread_create(&sp, NULL, spin, NULL) != 0) perror("pthread_create"); for (i = 0; i < PARALLEL; i++) { if (pthread_create(&cp[i], NULL, test, NULL) != 0) perror("pthread_create"); } for (i = 0; i < PARALLEL; i++) pthread_join(cp[i], NULL); close(fd); return (0); } Index: user/pho/stress2/misc/killpg.sh =================================================================== --- user/pho/stress2/misc/killpg.sh (revision 278500) +++ user/pho/stress2/misc/killpg.sh (revision 278501) @@ -1,161 +1,163 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # -# Regression test for r241859: +# Regression test for r241859: # Return EPERM if processes were found but they were unable to be signaled. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > killpg.c -cc -o killpg -Wall -Wextra killpg.c +mycc -o killpg -Wall -Wextra killpg.c rm -f killpg.c /tmp/killpg rm -f /tmp/killpg exit 0 EOF #include #include #include #include #include #include #include #include #include #include pid_t gid, pid; #define LOOPS 100 static void hand(int i __unused) { /* handler */ _exit(0); } void nlooper(void) { int i; setproctitle("nlooper"); setpgrp(0, getpid()); for (i = 0; i < LOOPS; i++) { if ((pid = fork()) == 0) { signal(SIGINFO, hand); if (arc4random() % 100 < 10) usleep(arc4random() % 100); _exit(0); } wait(NULL); } _exit(0); } void looper(void) { int i; setproctitle("looper"); setpgrp(0, getpid()); for (i = 0; i < LOOPS; i++) { if ((pid = fork()) == 0) { signal(SIGINFO, hand); if (arc4random() % 100 < 10) usleep(arc4random() % 100); _exit(0); } wait(NULL); } unlink("cont"); _exit(0); } void killer(void) { struct passwd *pw; int i; setproctitle("killer"); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((gid = fork()) == 0) nlooper(); /* nobody looper */ usleep(200); i = 0; for (;;) { if (i++ > 1000) { if (access("cont", R_OK) == -1) break; i = 0; } if (killpg(gid, SIGINFO) == -1) { if (errno == EPERM) continue; warn("FAIL killpg"); } } _exit(0); } int main(void) { int fd; if ((fd = open("cont", O_RDWR | O_CREAT, 0666)) == -1) err(1, "creat"); close(fd); signal(SIGINFO, SIG_IGN); if ((gid = fork()) == 0) looper(); if (fork() == 0) killer(); wait(NULL); wait(NULL); return (0); } Index: user/pho/stress2/misc/kinfo.sh =================================================================== --- user/pho/stress2/misc/kinfo.sh (revision 278500) +++ user/pho/stress2/misc/kinfo.sh (revision 278501) @@ -1,164 +1,164 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by marcus@freebsd.org [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kinfo.c -cc -o kinfo -Wall kinfo.c -lutil || exit 1 +mycc -o kinfo -Wall kinfo.c -lutil || exit 1 rm -f kinfo.c mount | grep -q procfs || mount -t procfs procfs /proc for i in `jot 30`; do for j in `jot 5`; do /tmp/kinfo & done for j in `jot 5`; do wait done done rm -f /tmp/kinfo exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include char buf[8096]; void handler(int i) { exit(0); } /* Stir /dev/proc */ int churning(void) { pid_t r; int fd, status; for (;;) { r = fork(); if (r == 0) { if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) err(1, "open(/proc/curproc/mem)"); bzero(buf, sizeof(buf)); exit(0); } if (r < 0) { perror("fork"); exit(2); } wait(&status); } } /* Get files for each proc */ void list(void) { struct kinfo_file *freep; struct kinfo_vmentry *freep_vm; long i; int cnt, name[4]; struct kinfo_proc *kipp; size_t len; name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_PROC; len = 0; if (sysctl(name, 3, NULL, &len, NULL, 0) < 0) err(-1, "sysctl: kern.proc.all"); kipp = malloc(len); if (kipp == NULL) err(1, "malloc"); if (sysctl(name, 3, kipp, &len, NULL, 0) < 0) { free(kipp); // warn("sysctl: kern.proc.all"); return; } for (i = 0; i < len / sizeof(*kipp); i++) { /* The test starts here */ freep = kinfo_getfile(kipp[i].ki_pid, &cnt); free(freep); freep_vm = kinfo_getvmmap(kipp[i].ki_pid, &cnt); free(freep_vm); /* End test */ } free(kipp); } int main(int argc, char **argv) { pid_t r; signal(SIGALRM, handler); alarm(60); if ((r = fork()) == 0) { alarm(60); for (;;) churning(); } if (r < 0) { perror("fork"); exit(2); } for (;;) list(); return (0); } Index: user/pho/stress2/misc/kinfo2.sh =================================================================== --- user/pho/stress2/misc/kinfo2.sh (revision 278500) +++ user/pho/stress2/misc/kinfo2.sh (revision 278501) @@ -1,176 +1,176 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by marcus@freebsd.org [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kinfo2.c -cc -o kinfo2 -Wall kinfo2.c -lutil +mycc -o kinfo2 -Wall kinfo2.c -lutil rm -f kinfo2.c mount | grep -q procfs || mount -t procfs procfs /procfs for i in `jot 30`; do for j in `jot 5`; do /tmp/kinfo2 & done for j in `jot 5`; do wait done done rm -f /tmp/kinfo2 exit EOF #include #include #include #include #include #include #include #include #include #include #include char buf[8096]; void handler(int i) { exit(0); } /* Stir /dev/proc */ int churning(void) { pid_t r; int fd, status; for (;;) { r = fork(); if (r == 0) { if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) err(1, "open(/proc/curproc/mem)"); bzero(buf, sizeof(buf)); exit(0); } if (r < 0) { perror("fork"); exit(2); } wait(&status); } } /* Get files for each proc */ void list(void) { int cnt, fd, n; int space = sizeof(buf); long base; struct dirent *dp; struct kinfo_file *freep; struct kinfo_vmentry *freep_vm; char *bp = buf; pid_t pid; long l; char *dummy; if ((fd = open("/proc", O_RDONLY)) == -1) err(1, "open(%s)", "/proc"); do { if ((n = getdirentries(fd, bp, space, &base)) == -1) err(1, "getdirentries"); space = space - n; bp = bp + n; } while (n != 0); close(fd); bp = buf; dp = (struct dirent *)bp; for (;;) { #if 0 printf("name: %-10s, inode %7d, type %2d, namelen %d, d_reclen %d\n", dp->d_name, dp->d_fileno, dp->d_type, dp->d_namlen, dp->d_reclen); fflush(stdout); #endif if (dp->d_type == DT_DIR && (dp->d_name[0] >= '0' && dp->d_name[0] <= '9')) { l = strtol(dp->d_name, &dummy, 10); pid = l; /* The tests start here */ freep = kinfo_getfile(pid, &cnt); free(freep); freep_vm = kinfo_getvmmap(pid, &cnt); free(freep_vm); /* End test */ } bp = bp + dp->d_reclen; dp = (struct dirent *)bp; if (dp->d_reclen <= 0) break; } } int main(int argc, char **argv) { pid_t r; signal(SIGALRM, handler); alarm(60); if ((r = fork()) == 0) { alarm(60); for (;;) churning(); } if (r < 0) { perror("fork"); exit(2); } for (;;) list(); return (0); } Index: user/pho/stress2/misc/kinfo3.sh =================================================================== --- user/pho/stress2/misc/kinfo3.sh (revision 278500) +++ user/pho/stress2/misc/kinfo3.sh (revision 278501) @@ -1,194 +1,194 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by marcus@freebsd.org and kib@freebsd.org [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kinfo3.c -cc -o kinfo3 -Wall kinfo3.c -lutil -pthread +mycc -o kinfo3 -Wall kinfo3.c -lutil -pthread rm -f kinfo3.c mount | grep -q procfs || mount -t procfs procfs /procfs for i in `jot 30`; do for j in `jot 5`; do /tmp/kinfo3 & done for j in `jot 5`; do wait done done rm -f /tmp/kinfo3 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include char buf[8096]; static volatile sig_atomic_t more; void handler(int i) { more = 0; } void * thr(void *arg) { int fd; if ((fd = open("/proc/curproc/mem", O_RDONLY)) == -1) err(1, "open(/proc/curproc/mem)"); close(fd); return (0); } /* Stir /dev/proc */ int churning(void) { int i; pid_t r; int status; pthread_t threads[5]; while(more) { r = fork(); if (r == 0) { for (i = 0; i < 5; i++) { if ((r = pthread_create(&threads[i], NULL, thr, 0)) != 0) err(1, "pthread_create(): %s\n", strerror(r)); } for (i = 0; i < 5; i++) { if (pthread_join(threads[i], NULL) != 0) err(1, "pthread_join(%d)", 0); } bzero(buf, sizeof(buf)); exit(0); } if (r < 0) { perror("fork"); exit(2); } wait(&status); } exit(0); } /* Get files for each proc */ void list(void) { struct kinfo_file *freep, *kif; struct kinfo_vmentry *freep_vm; long i, j; int cnt, name[4]; struct kinfo_proc *kipp; size_t len; name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_PROC; len = 0; if (sysctl(name, 3, NULL, &len, NULL, 0) < 0) err(-1, "sysctl: kern.proc.all"); kipp = malloc(len); if (kipp == NULL) err(1, "malloc"); if (sysctl(name, 3, kipp, &len, NULL, 0) < 0) { free(kipp); // warn("sysctl: kern.proc.all"); return; } for (i = 0; i < len / sizeof(*kipp); i++) { /* The test starts here */ freep = kinfo_getfile(kipp[i].ki_pid, &cnt); for (j = 0; j < cnt && freep; j++) { kif = &freep[j]; // printf("%d : %s\n", kif->kf_fd, kif->kf_path); } free(freep); freep_vm = kinfo_getvmmap(kipp[i].ki_pid, &cnt); free(freep_vm); /* End test */ } free(kipp); } int main(int argc, char **argv) { pid_t r; signal(SIGALRM, handler); alarm(30); more = 1; if ((r = fork()) == 0) { alarm(30); while(more) churning(); } if (r < 0) { perror("fork"); exit(2); } while(more) list(); return (0); } Index: user/pho/stress2/misc/ldt.sh =================================================================== --- user/pho/stress2/misc/ldt.sh (revision 278500) +++ user/pho/stress2/misc/ldt.sh (revision 278501) @@ -1,369 +1,371 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test the amd64 implementation of: # 1. Per-process private ldt and corresponding i386 arch syscalls. # 2. Per-process private io permission bitmap and corresponding # i386 arch syscalls. # 3. Sigcontext # The tests must be compiled on i386 and run on amd64 # All tests by kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + cd /tmp if [ "`uname -p`" = "i386" ]; then cat > ldt.c < #include #include #include #include #include #include #include #include #include #include char stack[64 * 1024]; char a[1]; int s2ds(int sel) { return (LSEL(sel, SEL_UPL)); } unsigned char readbyte(int sel, int offset) { unsigned char res; __asm__ volatile( "\tpushl %%es\n" "\tmovl %1,%%es\n" "\tmovb %%es:(%2),%0\n" "\tpopl %%es\n" : "=r"(res) : "r"(s2ds(sel)), "r"(offset)); return (res); } void writebyte(int sel, int offset, unsigned char val) { __asm__ volatile( "\tpushl %%es\n" "\tmovl %0,%%es\n" "\tmovb %2,%%es:(%1)\n" "\tpopl %%es\n" : : "r"(s2ds(sel)), "r"(offset), "r"(val) : "memory"); } int alloc_sel(char *base, size_t len, int type, int p) { int sel; union descriptor descs[1], descsk[1]; uintptr_t pb; memset(descs, 0, sizeof(descs)); if (len > PAGE_SIZE) { len = roundup(len, PAGE_SIZE); len /= PAGE_SIZE; descs[0].sd.sd_lolimit = len & 0xffff; descs[0].sd.sd_hilimit = (len >> 16) & 0xf; descs[0].sd.sd_gran = 1; } else { descs[0].sd.sd_lolimit = len; descs[0].sd.sd_hilimit = 0; descs[0].sd.sd_gran = 0; } pb = (uintptr_t)base; descs[0].sd.sd_lobase = pb & 0xffffff; descs[0].sd.sd_hibase = (pb >> 24) & 0xff; descs[0].sd.sd_type = type; descs[0].sd.sd_dpl = SEL_UPL; descs[0].sd.sd_p = p; descs[0].sd.sd_def32 = 1; if ((sel = i386_set_ldt(LDT_AUTO_ALLOC, descs, 1)) == -1) fprintf(stderr, "i386_set_ldt: %s\n", strerror(errno)); else if (i386_get_ldt(sel, descsk, 1) == -1) { fprintf(stderr, "i386_get_ldt: %s\n", strerror(errno)); sel = -1; } else if (memcmp(descs, descsk, sizeof(descs)) != 0) { fprintf(stderr, "descs != descsk\n"); sel = -1; } else fprintf(stderr, "selector %d\n", sel); return (sel); } int test1(int tnum, int sel) { unsigned char ar; writebyte(sel, 0, '1'); ar = readbyte(sel, 0); if (ar == '1') fprintf(stderr, "test %d.1 ok\n", tnum); else fprintf(stderr, "test%d.1 failed, ar %x\n", tnum, ar); writebyte(sel, 0, '2'); ar = readbyte(sel, 0); if (ar == '2') fprintf(stderr, "test %d.2 ok\n", tnum); else fprintf(stderr, "test%d.2 failed, ar %x\n", tnum, ar); return (sel); } int test2_func(void *arg) { int *sel; sel = arg; test1(2, *sel); rfork(0); test1(3, *sel); return (0); } void test2(int sel) { pid_t r; int status; r = rfork_thread(RFPROC | RFMEM, stack + sizeof(stack), test2_func, &sel); if (r == -1) { fprintf(stderr, "rfork(RFPROC): %s\n", strerror(errno)); return; } else { waitpid(r, &status, 0); if (WIFSIGNALED(status)) { fprintf(stderr, "test2: child terminated by %s\n", strsignal(WTERMSIG(status))); } } } int main(int argc, char *argv[]) { int sel; sel = alloc_sel(a, 1, SDT_MEMRWA, 1); if (sel == -1) return (1); test1(1, sel); test2(sel); return (0); } EOF cc -o ldt_static_i386 -Wall -static ldt.c rm ldt.c cat > ioperm.c < #include #include #include #include #include static const unsigned int port_num = 0x130; unsigned char inb(unsigned int port) { unsigned char data; __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); return (data); } void sigbus_handler(int signo) { fprintf(stderr, "Got SIGBUS\n"); exit(0); } int main(int argc, char *argv[]) { struct sigaction sa; unsigned int length1; int enable1; if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { fprintf(stderr, "get 1: %s\n", strerror(errno)); return (1); } if (length1 != 0 && enable1 != 0) { fprintf(stderr, "enable1: enabled\n"); return (1); } if (i386_set_ioperm(port_num, 1, 1) == -1) { fprintf(stderr, "set 1: %s\n", strerror(errno)); return (1); } inb(port_num); if (i386_set_ioperm(port_num, 1, 0) == -1) { fprintf(stderr, "set 2: %s\n", strerror(errno)); return (1); } if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { fprintf(stderr, "get 1: %s\n", strerror(errno)); return (1); } if (enable1 != 0) { fprintf(stderr, "enable2: enabled\n"); return (1); } fprintf(stderr, "And now we should get SIGBUS\n"); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigbus_handler; if (sigaction(SIGBUS, &sa, NULL) == -1) { fprintf(stderr, "sigaction(SIGBUS): %s\n", strerror(errno)); return (1); } inb(port_num); return (0); } EOF cc -o ioperm_static_i386 -Wall -static ioperm.c rm ioperm.c cat > fault.c < #include #include #include #include #include #include #include extern char *fault_instr; int run; void sigsegv_sigaction(int signo, siginfo_t *si, void *c) { ucontext_t *uc; mcontext_t *mc; uc = c; mc = &uc->uc_mcontext; printf("SIGSEGV run %d err %x ds %x ss %x es %x fs %x gs %x\n", run, mc->mc_err, mc->mc_ds, mc->mc_ss, mc->mc_es, mc->mc_fs, mc->mc_gs); switch (run) { case 0: mc->mc_ds = 0x1111; break; case 1: mc->mc_es = 0x1111; break; case 2: mc->mc_fs = 0x1111; break; case 3: mc->mc_gs = 0x1111; break; case 4: mc->mc_ss = 0x1111; break; case 5: _exit(11); } run++; } void fault(void) { __asm__ volatile(".globl\tfault_instr;fault_instr:\ttestl\t\$0,0\n"); } int main(int argc, char *argv[]) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = sigsegv_sigaction; sa.sa_flags = SA_SIGINFO; if (sigaction(SIGSEGV, &sa, NULL) == -1) { fprintf(stderr, "sigaction: %s\n", strerror(errno)); return (1); } if (sigaction(SIGBUS, &sa, NULL) == -1) { fprintf(stderr, "sigaction: %s\n", strerror(errno)); return (1); } fault(); return (0); } EOF cc -o fault_static_i386 -Wall -static fault.c rm fault.c fi if [ "`uname -p`" = "amd64" ]; then [ -x ldt_static_i386 ] && ./ldt_static_i386 [ -x ioperm_static_i386 ] && ./ioperm_static_i386 [ -x fault_static_i386 ] && ./fault_static_i386 fi Index: user/pho/stress2/misc/linger.sh =================================================================== --- user/pho/stress2/misc/linger.sh (revision 278500) +++ user/pho/stress2/misc/linger.sh (revision 278501) @@ -1,163 +1,163 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Demonstrate premature "out of inodes" problem with SU . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > linger.c -cc -o linger -Wall -O2 linger.c +mycc -o linger -Wall -O2 linger.c rm -f linger.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto [ $# -eq 1 ] && opt="$1" [ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag echo "newfs $opt md${mdstart}$part" newfs $opt md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint if ! su ${testuser} -c "cd $mntpoint; /tmp/linger $size"; then min=2 [ -r $mntpoint/.sujournal ] && min=3 r=`df -hi $mntpoint | head -1` echo " $r" for i in `jot 10`; do r=`df -hi $mntpoint | tail -1` echo "`date '+%T'` $r" [ `echo $r | awk '{print $6}'` = $min ] && break sleep 10 done ls -lR $mntpoint fi while mount | grep "$mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/linger exit EOF #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 static int size = 6552; /* 10 free inodes */ int test(void) { int fd, i, j; pid_t pid; char file[128]; for (;;) { if (access("rendezvous", R_OK) == 0) break; sched_yield(); } pid = getpid(); for (j = 0; j < size; j++) { sprintf(file,"p%05d.%05d", pid, j); if ((fd = creat(file, 0660)) == -1) { if (errno != EINTR) { warn("creat(%s). %s:%d", file, __FILE__, __LINE__); unlink("continue"); break; } } if (fd != -1 && close(fd) == -1) err(2, "close(%d)", j); } sleep(3); for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) warn("unlink(%s)", file); } return (0); } int main(void) { int error = 0, fd, i, j, status; umask(0); if ((fd = open("continue", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < 100; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) { test(); exit(0); } } if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (j = 0; j < PARALLEL; j++) { wait(&status); error += status; } unlink("rendezvous"); if (access("continue", R_OK) == -1) { fprintf(stderr, "Loop #%d\n", i + 1); break; } } unlink("continue"); return (error != 0); } Index: user/pho/stress2/misc/linger2.sh =================================================================== --- user/pho/stress2/misc/linger2.sh (revision 278500) +++ user/pho/stress2/misc/linger2.sh (revision 278501) @@ -1,174 +1,174 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Variation of linger.sh, with emphasis on blocks. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > linger2.c -cc -o linger2 -Wall -O2 linger2.c +mycc -o linger2 -Wall -O2 linger2.c rm -f linger2.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto [ $# -eq 1 ] && opt="$1" [ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag newfs $opt -n md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint set `df -i $mntpoint | tail -1 | awk '{print $3, $6}'` min=24 [ -r $mntpoint/.sujournal ] && { size=88; min=8232; } if ! su ${testuser} -c "cd $mntpoint; /tmp/linger2 $size 2>/dev/null"; then r=`df -i $mntpoint | head -1` echo " $r" for i in `jot 12`; do r=`df -ik $mntpoint | tail -1` [ "$r" != "$old" ] && echo "`date '+%T'` $r" old=$r [ `echo $r | awk '{print $3}'` -le $min ] && break sleep 10 done fi while mount | grep "$mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/linger2 exit EOF #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 static int size = 89; int test(void) { int error = 0, fd, i, j; pid_t pid; char file[128]; char *buf; for (;;) { if (access("rendezvous", R_OK) == 0) break; sched_yield(); } pid = getpid(); buf = malloc(1024 * 1024); for (j = 0; j < size; j++) { sprintf(file,"p%05d.%05d", pid, j); if ((fd = creat(file, 0660)) == -1) { if (errno != EINTR) { warn("creat(%s). %s:%d", file, __FILE__, __LINE__); unlink("continue"); error = 1; break; } } if (write(fd, buf, 1024 * 1024) != 1024 * 1024) { warn("write()"); unlink("continue"); error = 1; break; } if (fd != -1 && close(fd) == -1) err(2, "close(%d)", j); } sleep(3); if (error == 0) j--; for (i = j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) warn("unlink(%s)", file); } return (error); } int main(int argc, char **argv) { int error = 0, fd, i, j, status; if (argc == 2) size = atoi(argv[1]); umask(0); if ((fd = open("continue", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < 200; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) exit(test()); } if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (j = 0; j < PARALLEL; j++) { wait(&status); error += status; } unlink("rendezvous"); if (access("continue", R_OK) == -1) { break; } } unlink("continue"); return (error != 0); } Index: user/pho/stress2/misc/linger3.sh =================================================================== --- user/pho/stress2/misc/linger3.sh (revision 278500) +++ user/pho/stress2/misc/linger3.sh (revision 278501) @@ -1,136 +1,136 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test for SU problem with false EMLINK [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > linger3.c -cc -o linger3 -Wall -Wextra -O2 linger3.c +mycc -o linger3 -Wall -Wextra -O2 linger3.c rm -f linger3.c mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto [ $# -eq 1 ] && opt="$1" [ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag echo "newfs $opt md${mdstart}$part" newfs $opt md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint chmod 777 $mntpoint su $testuser -c "/tmp/linger3" cd $here while mount | grep -q $mntpoint; do umount ${mntpoint} 2> /dev/null || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/linger3 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define PARALLEL 4 #define ND ((32767 / PARALLEL) - 2) static pid_t p; void setup(int loop) { int d; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%06d.%03d", p, d); if (mkdir(name, 00700) == -1) err(1, "mkdir(%s) @ loop #%d", name, loop); } } void prune(int loop) { int d; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%06d.%03d", p, d); if (rmdir(name) == -1) err(1, "rmdir(%s) @ loop #%d", name, loop); } } int main() { int i, j; int linger = 0; if (getenv("LINGER")) linger = atoi(getenv("LINGER")); for (i = 0; i < PARALLEL; i++) { if (fork() == 0) { p = getpid(); for (j = 0; j < 10; j++) { setup(j); prune(j); if (linger != 0) sleep(linger); } _exit(0); } } for (i = 0; i < PARALLEL; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/linger4.sh =================================================================== --- user/pho/stress2/misc/linger4.sh (revision 278500) +++ user/pho/stress2/misc/linger4.sh (revision 278501) @@ -1,150 +1,150 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test for SU problem with "out of inodes" for CREAT [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > linger4.c -cc -o linger4 -Wall -Wextra -O2 linger4.c +mycc -o linger4 -Wall -Wextra -O2 linger4.c rm -f linger4.c mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto [ $# -eq 1 ] && opt="$1" [ $# -eq 0 ] && opt=$newfs_flags # No argument == default flag echo "newfs $opt md${mdstart}$part" newfs $opt md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint chmod 777 $mntpoint su $testuser -c "/tmp/linger4" || { ls -la $mntpoint; df -i $mntpoint; } cd $here while mount | grep -q $mntpoint; do umount ${mntpoint} 2> /dev/null || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/linger4 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 4 #define NUMBER 80000 / PARALLEL /* Number of files to use. Max is 131068 */ void Creat(int loopno) { int e, fd, i, j; char file[128]; char path[128]; pid_t pid; e = 0; pid = getpid(); sprintf(path, "f%06d", pid); if (mkdir(path, 0770) == -1) warn("mkdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); chdir(path); for (j = 0; j < NUMBER; j++) { sprintf(file,"p%05d.%05d", pid, j); if ((fd = creat(file, 0660)) == -1) { if (errno != EINTR) { warn("creat(%s). %s:%d, loop #%d", file, __FILE__, __LINE__, loopno); e = 1; break; } } if (fd != -1 && close(fd) == -1) err(2, "close(%d)", j); } for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) err(3, "unlink(%s)", file); } chdir (".."); if (rmdir(path) == -1) err(1, "rmdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); _exit(e); } int main() { int e, i, j, status; e = 0; for (j = 0; j < 300; j++) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) Creat(j); } for (i = 0; i < PARALLEL; i++) { wait(&status); e += WEXITSTATUS(status); } if (e != 0) break; // sleep(60); /* No problems if this is included */ } return (e); } Index: user/pho/stress2/misc/link.sh =================================================================== --- user/pho/stress2/misc/link.sh (revision 278500) +++ user/pho/stress2/misc/link.sh (revision 278501) @@ -1,194 +1,194 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Deadlock seen for file systems which suspend writes on unmount, such as # UFS and tmpfs. # http://people.freebsd.org/~pho/stress/log/link.txt # Fixed by r272130 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > link.c -cc -o link -Wall -Wextra -O2 -g link.c || exit 1 +mycc -o link -Wall -Wextra -O2 -g link.c || exit 1 rm -f link.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs -U md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint daemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ > /dev/null 2>&1 /tmp/link $mntpoint > /dev/null 2>&1 & for i in `jot 100`; do umount -f $mntpoint && mount /dev/md${mdstart}$part $mntpoint sleep .1 done pkill -9 link wait while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart # tmpfs mount -t tmpfs tmpfs $mntpoint /tmp/link $mntpoint > /dev/null 2>&1 & for i in `jot 100`; do umount -f $mntpoint && mount -t tmpfs tmpfs $mntpoint sleep .1 done pkill -9 link swap wait while pkill -9 swap; do : done > /dev/null 2>&1 while mount | grep $mntpoint | grep -q tmpfs; do umount $mntpoint || sleep 1 done rm -f /tmp/link exit 0 EOF #include #include #include #include #include #include #include #include #include #define PARALLEL 16 #define RUNTIME 300 time_t start; char *dir; void trename(void) { int fd; char name1[MAXPATHLEN + 1]; char name2[MAXPATHLEN + 1]; setproctitle(__func__); snprintf(name1, sizeof(name1), "%s/r1.%05d", dir, getpid()); snprintf(name2, sizeof(name2), "%s/r2.%05d", dir, getpid()); if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) err(1, "open(%s)", name1); close(fd); while (time(NULL) - start < RUNTIME) { if (rename(name1, name2) == -1) { if (errno == ENOENT) { if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) err(1, "open(%s)", name1); close(fd); continue; } else warn("link(%s, %s)", name1, name2); } if (rename(name2, name1) == -1) warn("link(%s, %s)", name2, name1); } unlink(name1); unlink(name2); _exit(0); } void tlink(void) { int fd; char name1[MAXPATHLEN + 1]; char name2[MAXPATHLEN + 1]; setproctitle(__func__); snprintf(name1, sizeof(name1), "%s/f1.%05d", dir, getpid()); snprintf(name2, sizeof(name2), "%s/f2.%05d", dir, getpid()); if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) err(1, "open(%s)", name1); close(fd); while (time(NULL) - start < RUNTIME) { unlink(name2); if (link(name1, name2) == -1) { if (errno == ENOENT) { if ((fd = open(name1, O_RDWR | O_CREAT, 0644)) == -1) err(1, "open(%s)", name1); close(fd); continue; } else warn("link(%s, %s)", name1, name2); } } unlink(name1); unlink(name2); _exit(0); } int main(int argc, char **argv) { int i, type; if (argc != 2) errx(1, "Usage: %s ", argv[0]); dir = argv[1]; type = arc4random() % 2; /* test either link() or rename() */ start = time(NULL); for (i = 0; i < PARALLEL; i++) { if (type == 0 && fork() == 0) tlink(); if (type == 1 && fork() == 0) trename(); } for (i = 0; i < PARALLEL; i++) wait(NULL); return(0); } Index: user/pho/stress2/misc/mlockall.sh =================================================================== --- user/pho/stress2/misc/mlockall.sh (revision 278500) +++ user/pho/stress2/misc/mlockall.sh (revision 278501) @@ -1,81 +1,81 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: swap_reserved < decr" seen. Fixed in r195329 . ../default.cfg [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > mlockall.c -cc -o mlockall -Wall mlockall.c +mycc -o mlockall -Wall mlockall.c rm -f mlockall.c for i in `jot 10`; do /tmp/mlockall & sleep 1 ps | grep /tmp/mlockall | grep -v grep | awk '{print $1}' | while read pid; do kill -2 $pid kill -9 $pid done done rm -f /tmp/mlockall exit EOF #include #include #include #include #include #include void child(void) { if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) err(1, "mlockall(MCL_CURRENT | MCL_FUTURE)"); fork(); sleep(60); } int main(int argc, char **argv) { int status; if (fork() == 0) child(); wait(&status); return (0); } Index: user/pho/stress2/misc/mlockall2.sh =================================================================== --- user/pho/stress2/misc/mlockall2.sh (revision 278500) +++ user/pho/stress2/misc/mlockall2.sh (revision 278501) @@ -1,148 +1,150 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + # core dumps seen in watchdogd after mlockall() was added. # This scenario demonstrates the problem. Fixed in r242012. mem=`sysctl hw.usermem | awk '{print $NF}'` here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mlockall2.c -cc -o mlockall2 -Wall -Wextra -O2 -g mlockall2.c +mycc -o mlockall2 -Wall -Wextra -O2 -g mlockall2.c rm -f mlockall2.c cd $here rm -f mlockall2.core /tmp/mlockall2 $mem & while kill -0 $! 2>/dev/null; do [ -r mlockall2.core ] && kill $! && break sleep 10 done [ -r mlockall2.core ] && echo "FAIL" killall mlockall2 rm -f /tmp/mlockall2 exit 0 EOF #include #include #include #include #include #include #include #define LOAD 40 #define N 90000 #define PARALLEL 5 long size; void swap(void) { char *c; int page; long i; setproctitle("swap"); c = malloc(size); while (c == NULL) { size -= 1024 * 1024; c = malloc(size); } page = getpagesize(); for (;;) { i = 0; while (i < size) { c[i] = 0; i += page; } } } void test(void) { pid_t p; int i, status; setproctitle("test"); for (i = 0; i < N; i++) { if ((p = fork()) == 0) { _exit(0); } if (p > 0) wait(&status); if (status != 0) break; } _exit(0); } int main(int argc __unused, char **argv) { struct rtprio rtp; int i, j; size = atol(argv[1]) / LOAD * 1.5; for (i = 0; i < LOAD; i++) if (fork() == 0) swap(); sleep(10); rtp.type = RTP_PRIO_REALTIME; rtp.prio = 0; if (rtprio(RTP_SET, 0, &rtp) == -1) err(1, "rtprio"); if (madvise(0, 0, MADV_PROTECT) != 0) err(1, "madvise failed"); if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) err(1, "mlockall failed"); alarm(600); for (j = 0; j < 10; j++) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) wait(NULL); if (access("mlockall2.core", R_OK) == 0) break; } return (0); } Index: user/pho/stress2/misc/mlockall3.sh =================================================================== --- user/pho/stress2/misc/mlockall3.sh (revision 278500) +++ user/pho/stress2/misc/mlockall3.sh (revision 278501) @@ -1,168 +1,170 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # mlockall(2) test scenario. # "panic: vm_page_unwire: page xxx's wire count is zero" seen. # http://people.freebsd.org/~pho/stress/log/mlockall.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall3.c -cc -o mlockall3 -Wall -Wextra mlockall3.c -lpthread || exit 1 +mycc -o mlockall3 -Wall -Wextra mlockall3.c -lpthread || exit 1 rm -f mlockall3.c cd $odir /tmp/mlockall3 killall mlockall3 > /dev/null 2>&1 rm -f /tmp/mlockall3 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * calls(void *arg __unused) { int i; unsigned long arg1, arg2, arg3; usleep(1000); for (i = 0; i < 500; i++) { arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); alarm(1); syscall(SYS_mlockall, arg1, arg2, arg3); } return (0); } int main(void) { struct passwd *pw; pid_t pid; pthread_t cp[50]; int i, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); alarm(180); for (i = 0; i < 8000; i++) { if ((pid = fork()) == 0) { arc4random_stir(); for (j = 0; j < N; j++) r[j] = arc4random(); for (j = 0; j < 50; j++) if (pthread_create(&cp[j], NULL, calls, NULL) != 0) perror("pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } if (pid == -1) err(1, "fork()"); wait(NULL); } return (0); } Index: user/pho/stress2/misc/mlockall4.sh =================================================================== --- user/pho/stress2/misc/mlockall4.sh (revision 278500) +++ user/pho/stress2/misc/mlockall4.sh (revision 278501) @@ -1,67 +1,67 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # mlockall(2) / nullfs(5) scenario causes: # http://people.freebsd.org/~pho/stress/log/kostik619.txt # kern/182661, fixed in r256211. . ../default.cfg [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > mlockall4.c -cc -o mlockall4 -Wall -Wextra mlockall4.c || exit 1 +mycc -o mlockall4 -Wall -Wextra mlockall4.c || exit 1 rm -f mlockall4.c mount | grep -q "on $mntpoint " && umount -f $mntpoint mount -t nullfs /tmp $mntpoint /mnt/mlockall4 & sleep 2 umount -f $mntpoint rm -f /tmp/mlockall4 exit EOF #include #include #include #include int main(void) { if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) err(1, "mlockall(MCL_CURRENT | MCL_FUTURE)"); sleep(5); return (0); } Index: user/pho/stress2/misc/mmap.sh =================================================================== --- user/pho/stress2/misc/mmap.sh (revision 278500) +++ user/pho/stress2/misc/mmap.sh (revision 278501) @@ -1,67 +1,67 @@ #!/bin/sh # # $FreeBSD$ # # Test scenario by Michiel Boland # panic: pmap_remove_all: page 0xc491f000 is fictitious [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > mmap.c -cc -o mmap -Wall mmap.c +mycc -o mmap -Wall mmap.c rm -f mmap.c ./mmap rm -f ./mmap exit EOF #include #include #include #include #include static const off_t map_address = 0xa0000; static const size_t map_size = 0x1000; static int testit(int fd) { void *p; int rv; p = mmap(NULL, 2 * map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, map_address); if (p == MAP_FAILED) { perror("mmap"); return -1; } rv = *(char *) p; if (munmap(p, map_size) == -1) { perror("munmap"); return -1; } return rv; } int main(void) { int fd, rv; fd = open("/dev/mem", O_RDWR); if (fd == -1) { perror("open"); return 1; } rv = testit(fd); close(fd); return rv; } Index: user/pho/stress2/misc/mmap10.sh =================================================================== --- user/pho/stress2/misc/mmap10.sh (revision 278500) +++ user/pho/stress2/misc/mmap10.sh (revision 278501) @@ -1,268 +1,270 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vm_page_dirty: page is invalid!" seen. # http://people.freebsd.org/~pho/stress/log/mmap10.txt # No problems seen after r271681. +. ../default.cfg + [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mmap10.c -cc -o mmap10 -Wall -Wextra -O2 -g mmap10.c -lpthread || exit 1 +mycc -o mmap10 -Wall -Wextra -O2 -g mmap10.c -lpthread || exit 1 rm -f mmap10.c daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` sleep $((rnd % 10)) for i in `jot 2`; do /tmp/mmap10 done killall -q swap rm -f /tmp/mmap10 /tmp/mmap10.core exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOOPS 2 #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define PARALLEL 50 void *p; u_int32_t r[N]; unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * makeptr(void) { unsigned long val; if (p != MAP_FAILED && p != NULL) val = (unsigned long)p + arc4random(); else val = makearg(); val = trunc_page(val); return ((void *)val); } void * tmmap(void *arg __unused) { size_t len; int i, fd; pthread_set_name_np(pthread_self(), __func__); len = 1LL * 1024 * 1024 * 1024; for (i = 0; i < 100; i++) { if ((fd = open("/dev/zero", O_RDWR)) == -1) err(1,"open()"); if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } close(fd); } return (NULL); } void * tmlock(void *arg __unused) { size_t len; int i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { len = trunc_page(makearg()); if (mlock(makeptr(), len) == 0) n++; len = trunc_page(makearg()); if (arc4random() % 100 < 50) if (munlock(makeptr(), len) == 0) n++; } if (n < 10) fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", n); return (NULL); } void * tmprotect(void *arg __unused) { size_t len; const void *addr; int i, n, prot; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { addr = makeptr(); len = trunc_page(makearg()); prot = makearg(); if (mprotect(addr, len, prot) == 0) n++; usleep(1000); } if (n < 10) fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", n); return (NULL); } void * tmlockall(void *arg __unused) { int flags, i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { flags = makearg(); if (mlockall(flags) == 0) n++; usleep(100); munlockall(); usleep(1000); } if (n < 10) fprintf(stderr, "Note: tmlockall() only succeeded %d times.\n", n); return (NULL); } void test(void) { pthread_t tid[4]; int i, rc; if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) errc(1, rc, "tmmap()"); if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) errc(1, rc, "tmlock()"); if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) errc(1, rc, "tmprotect()"); if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) errc(1, rc, "tmlockall()"); for (i = 0; i < 100; i++) { if (fork() == 0) { usleep(10000); _exit(0); } wait(NULL); } for (i = 0; i < 4; i++) if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); _exit(0); } int main(void) { int i, j; for (i = 0; i < N; i++) r[i] = arc4random(); alarm(1200); for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap11.sh =================================================================== --- user/pho/stress2/misc/mmap11.sh (revision 278500) +++ user/pho/stress2/misc/mmap11.sh (revision 278501) @@ -1,295 +1,297 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Copy of mmap10.sh with msync() added. # "panic: vm_map_protect: inaccessible wired map entry" seen: # http://people.freebsd.org/~pho/stress/log/mmap11.txt # No problems seen after r271681. # http://people.freebsd.org/~pho/stress/log/kostik730.txt, Fixed in r273784 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mmap11.c -cc -o mmap11 -Wall -Wextra -O2 -g mmap11.c -lpthread || exit 1 +mycc -o mmap11 -Wall -Wextra -O2 -g mmap11.c -lpthread || exit 1 rm -f mmap11.c daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` sleep $((rnd % 10)) for i in `jot 2`; do /tmp/mmap11 done killall -q swap rm -f /tmp/mmap11 /tmp/mmap11.core exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOOPS 2 #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define PARALLEL 50 void *p; u_int32_t r[N]; unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * makeptr(void) { unsigned long val; if (p != MAP_FAILED && p != NULL) val = (unsigned long)p + arc4random(); else val = makearg(); val = trunc_page(val); return ((void *)val); } void * tmmap(void *arg __unused) { size_t len; int i, fd; pthread_set_name_np(pthread_self(), __func__); len = 1LL * 1024 * 1024 * 1024; for (i = 0; i < 100; i++) { if ((fd = open("/dev/zero", O_RDWR)) == -1) err(1,"open()"); if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } close(fd); } return (NULL); } void * tmlock(void *arg __unused) { size_t len; int i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { len = trunc_page(makearg()); if (mlock(makeptr(), len) == 0) n++; len = trunc_page(makearg()); if (arc4random() % 100 < 50) if (munlock(makeptr(), len) == 0) n++; } if (n < 10) fprintf(stderr, "Note: tmlock() only succeeded %d times.\n", n); return (NULL); } void * tmprotect(void *arg __unused) { size_t len; const void *addr; int i, n, prot; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { addr = makeptr(); len = trunc_page(makearg()); prot = makearg(); if (mprotect(addr, len, prot) == 0) n++; usleep(1000); } if (n < 10) fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", n); return (NULL); } void * tmlockall(void *arg __unused) { int flags, i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { flags = makearg(); if (mlockall(flags) == 0) n++; usleep(100); munlockall(); usleep(1000); } if (n < 10) fprintf(stderr, "Note: tmlockall() only succeeded %d times.\n", n); return (NULL); } void * tmsync(void *arg __unused) { size_t len; void *addr; int flags, i, n; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { addr = makeptr(); len = trunc_page(makearg()); flags = makearg(); if (msync(addr, len, flags) == 0) n++; usleep(2000); } if (n < 10) fprintf(stderr, "Note: tmsync() only succeeded %d times.\n", n); return (NULL); } void test(void) { pthread_t tid[5]; int i, rc; if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) errc(1, rc, "tmmap()"); if ((rc = pthread_create(&tid[1], NULL, tmlock, NULL)) != 0) errc(1, rc, "tmlock()"); if ((rc = pthread_create(&tid[2], NULL, tmprotect, NULL)) != 0) errc(1, rc, "tmprotect()"); if ((rc = pthread_create(&tid[3], NULL, tmlockall, NULL)) != 0) errc(1, rc, "tmlockall()"); if ((rc = pthread_create(&tid[4], NULL, tmsync, NULL)) != 0) errc(1, rc, "tmlockall()"); for (i = 0; i < 100; i++) { if (fork() == 0) { usleep(10000); _exit(0); } wait(NULL); } for (i = 0; i < 5; i++) if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); _exit(0); } int main(void) { int i, j; for (i = 0; i < N; i++) r[i] = arc4random(); for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap12.sh =================================================================== --- user/pho/stress2/misc/mmap12.sh (revision 278500) +++ user/pho/stress2/misc/mmap12.sh (revision 278501) @@ -1,81 +1,83 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vm_map_protect: inaccessible wired map entry" seen: # http://people.freebsd.org/~pho/stress/log/mmap11.txt # Fixed in r266780. # Test scenario by: Mark Johnston markj@ +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mmap12.c -cc -o mmap12 -O2 -Wall -Wextra mmap12.c || exit 1 +mycc -o mmap12 -O2 -Wall -Wextra mmap12.c || exit 1 rm -f mmap12.c cd $odir /tmp/mmap12 rm -f /tmp/mmap12 exit EOF #include #include #include #include int main(void) { void *addr; size_t sz = 1; /* * This is the minimum amount of C code ot takes to panic the kernel. * This is as submitted and thus not a complete and correct test program. */ addr = mmap(NULL, sz, PROT_READ, MAP_ANON, -1, 0); if (addr == NULL) err(1, "mmap"); if (mlock(addr, sz) != 0) err(1, "mlock"); if (mprotect(addr, sz, PROT_NONE) != 0) err(1, "mprotect 1"); if (mprotect(addr, sz, PROT_WRITE) != 0) err(1, "mprotect 2"); if (munmap(addr, sz) != 0) err(1, "munmap"); return (0); } Index: user/pho/stress2/misc/mmap13.sh =================================================================== --- user/pho/stress2/misc/mmap13.sh (revision 278500) +++ user/pho/stress2/misc/mmap13.sh (revision 278501) @@ -1,80 +1,82 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Leak of "vm.stats.vm.v_wire_count" seen. # Test scenario by: Mark Johnston markj@ # Fixed in r269134. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mmap13.c -cc -o mmap13 -O2 -Wall -Wextra mmap13.c || exit 1 +mycc -o mmap13 -O2 -Wall -Wextra mmap13.c || exit 1 rm -f mmap13.c cd $odir # Both the 5000 and 500 are empirical values. # Combined they demonstrate the leak in a consistent way. v1=`sysctl -n vm.stats.vm.v_wire_count` for i in `jot 5000`; do /tmp/mmap13 done v2=`sysctl -n vm.stats.vm.v_wire_count` [ $v2 -gt $((v1 + 500)) ] && echo "FAIL vm.stats.vm.v_wire_count changed from $v1 to $v2." rm -f /tmp/mmap13 exit EOF #include #include #include #include int main(void) { void *addr; size_t sz; sz = getpagesize(); addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (addr == NULL) err(1, "mmap"); if (mlock(addr, sz) != 0) err(1, "mlock"); if (mprotect(addr, sz, PROT_NONE) != 0) err(1, "mprotect"); return (0); } Index: user/pho/stress2/misc/mmap19.sh =================================================================== --- user/pho/stress2/misc/mmap19.sh (revision 278500) +++ user/pho/stress2/misc/mmap19.sh (revision 278501) @@ -1,225 +1,227 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # panic: pmap active 0xfffff801d22cdae8" seen. # Variation of mmap18.sh. # http://people.freebsd.org/~pho/stress/log/kostik712.txt # Fixed by r271000. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mmap19.c -cc -o mmap19 -Wall -Wextra -O2 mmap19.c -lpthread || exit 1 +mycc -o mmap19 -Wall -Wextra -O2 mmap19.c -lpthread || exit 1 rm -f mmap19.c daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" rnd=`od -An -N1 -t u1 /dev/random | sed 's/ //g'` sleep $((rnd % 10)) for i in `jot 2`; do /tmp/mmap19 done killall -q swap rm -f /tmp/mmap19 /tmp/mmap19.core exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOOPS 50 #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define PARALLEL 50 u_int32_t r[N]; void *p; unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * makeptr(void) { unsigned long val; if (p != MAP_FAILED && p != NULL) val = (unsigned long)p + arc4random(); else val = makearg(); val = trunc_page(val); return ((void *)val); } void * tmmap(void *arg __unused) { size_t len; int i, fd; pthread_set_name_np(pthread_self(), __func__); len = 1LL * 1024 * 1024 * 1024; for (i = 0; i < 100; i++) { if ((fd = open("/dev/zero", O_RDWR)) == -1) err(1,"open()"); if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } close(fd); } return (NULL); } void * tmprotect(void *arg __unused) { const void *addr; size_t len; int i, n, prot; pthread_set_name_np(pthread_self(), __func__); n = 0; for (i = 0; i < 200; i++) { addr = makeptr(); len = trunc_page(makearg()); prot = makearg(); if (mprotect(addr, len, prot) == 0) n++; usleep(1000); } if (n < 10) fprintf(stderr, "Note: tmprotect() only succeeded %d times.\n", n); return (NULL); } void test(void) { pthread_t tid[2]; int i, rc; if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) errc(1, rc, "tmmap()"); if ((rc = pthread_create(&tid[1], NULL, tmprotect, NULL)) != 0) errc(1, rc, "tmprotect()"); for (i = 0; i < 100; i++) { if (fork() == 0) { usleep(10000); _exit(0); } wait(NULL); } for (i = 0; i < 2; i++) if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); _exit(0); } int main(void) { struct rlimit rl; int i, j; rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); for (i = 0; i < N; i++) r[i] = arc4random(); for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap2.sh =================================================================== --- user/pho/stress2/misc/mmap2.sh (revision 278500) +++ user/pho/stress2/misc/mmap2.sh (revision 278501) @@ -1,176 +1,178 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Stress mmap by having at most 100 threads mapping random areas within # a 100 Mb range. # Test scenario by kib@ +. ../default.cfg + odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > mmap2.c -cc -o mmap2 -Wall -g mmap2.c -lpthread +mycc -o mmap2 -Wall -g mmap2.c -lpthread rm -f mmap2.c for i in `jot 10`; do ./mmap2 done rm -f ./mmap2 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #define THREADS 100 #define STARTADDR 0x50000000U #define ADRSPACE 0x06400000U /* 100 Mb */ static void work(int nr) { int fd, m; void *p; size_t left, len; char path[128]; p = (void *)STARTADDR + trunc_page(arc4random() % ADRSPACE); left = ADRSPACE - (size_t)p + STARTADDR; len = trunc_page(arc4random() % left) + PAGE_SIZE; fd = -1; if (arc4random() % 100 < 90) sprintf(path, "/tmp/mmap.%06d.%04d", getpid(), nr); else sprintf(path, "/dev/zero"); if (arc4random() % 2 == 0) { if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1,"open()"); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if (arc4random() % 2 == 0) { if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) return; err(1, "mmap()"); } } else { if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) return; err(1, "mmap()"); } } if (fd > 0 && strcmp(path, "/dev/zero")) if (unlink(path) == -1) err(1, "unlink(%s)", path); } else { if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) == MAP_FAILED) { if (errno == ENOMEM) return; err(1, "mmap()"); } strcpy(path, "anon"); } #if 0 printf("nr = %d, %-14s, start = %p, end = %p, len = 0x%08x, (%5d pages)\n", nr, path, p, p + len, len, len>>PAGE_SHIFT); #endif *(int *)p = 1; if (arc4random() % 2 == 0) { m = arc4random() % 10; if (madvise(p, len, m) == -1) warn("madvise(%p, %zd, %d)", p, len, m); } if (arc4random() %2 == 0) if (mprotect(p, trunc_page(arc4random() % len), PROT_READ) == -1 ) err(1, "mprotect failed with error:"); if (arc4random() % 2 == 0) { if (arc4random() %2 == 0) { if (msync(p, 0, MS_SYNC) == -1) err(1, "msync(%p)", p); } else { if (msync(p, 0, MS_INVALIDATE) == -1) err(1, "msync(%p)", p); } } if (munmap(p, len) == -1) err(1, "munmap(%p)", p); close(fd); } void * thr(void *arg) { int i; for (i = 0; i < 512; i++) { work(*(int *)arg); } return (0); } int main(int argc, char **argv) { pthread_t threads[THREADS]; int nr[THREADS]; int i, n, r; // printf("Address start 0x%x, address end 0x%x, pages %d\n", // STARTADDR, STARTADDR + ADRSPACE, ADRSPACE>>PAGE_SHIFT); n = arc4random() % THREADS + 1; for (i = 0; i < n; i++) { nr[i] = i; if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0) err(1, "pthread_create(): %s\n", strerror(r)); } for (i = 0; i < n; i++) { if (pthread_join(threads[i], NULL) != 0) err(1, "pthread_join(%d)", i); } return (0); } Index: user/pho/stress2/misc/mmap3.sh =================================================================== --- user/pho/stress2/misc/mmap3.sh (revision 278500) +++ user/pho/stress2/misc/mmap3.sh (revision 278501) @@ -1,166 +1,168 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Variation of mmap2.sh with focus on random arguments for mprotect() +. ../default.cfg + odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > mmap3.c -cc -o mmap3 -Wall mmap3.c -lpthread || exit 1 +mycc -o mmap3 -Wall mmap3.c -lpthread || exit 1 rm -f mmap3.c start=`date '+%s'` while [ `date '+%s'` -lt $((start + 5 * 60)) ]; do ./mmap3 done echo "Expect Segmentation faults" start=`date '+%s'` while [ `date '+%s'` -lt $((start + 5 * 60)) ]; do ./mmap3 random done rm -f mmap3 mmap3.core /tmp/mmap.0* exit EOF /* Stress mmap by having max 18 threads mapping random areas within a 100 Mb range. */ #include #include #include #include #include #include #include #include #include #include #include #include #define THREADS 100 #define STARTADDR 0x50000000U #define ADRSPACE 0x06400000U /* 100 Mb */ static int ra; void trash(void *p) { unsigned long v; mprotect(p, 0x570e3d38, 0x2c8fd54f); if (ra) { v = arc4random(); #if defined(__LP64__) v = v << 32 | arc4random(); #endif madvise((void *)v, arc4random(), arc4random()); mprotect((void *)v, arc4random(), arc4random()); msync((void *)v, arc4random(), arc4random()); } } void work(int nr) { int fd, m; void *p; size_t len; char path[128]; p = (void *)STARTADDR; len = ADRSPACE; sprintf(path, "/tmp/mmap.%06d.%04d", getpid(), nr); if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1,"open()"); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) return; err(1, "mmap()"); } if (unlink(path) == -1) err(1, "unlink(%s)", path); trash(p); m = arc4random() % 10; if (madvise(p, len, m) == -1) warn("madvise(%p, %zd, %d)", p, len, m); if (mprotect(p, trunc_page(arc4random() % len), PROT_READ) == -1 ) err(1, "mprotect failed with error:"); if (msync(p, 0, MS_SYNC) == -1) err(1, "msync(%p)", p); if (munmap(p, len) == -1) err(1, "munmap(%p)", p); close(fd); } void * thr(void *arg) { int i; for (i = 0; i < 512; i++) { work(*(int *)arg); } return (0); } int main(int argc, char **argv) { pthread_t threads[THREADS]; int nr[THREADS]; int i, n, r; n = arc4random() % 14 + 5; ra = argc != 1; // printf("Address start 0x%x, address end 0x%x, pages %d, n %d\n", // STARTADDR, STARTADDR + ADRSPACE, ADRSPACE>>PAGE_SHIFT, n); for (i = 0; i < n; i++) { nr[i] = i; if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0) err(1, "pthread_create(): %s\n", strerror(r)); } for (i = 0; i < n; i++) { if (pthread_join(threads[i], NULL) != 0) err(1, "pthread_join(%d)", i); } return (0); } Index: user/pho/stress2/misc/mmap4.sh =================================================================== --- user/pho/stress2/misc/mmap4.sh (revision 278500) +++ user/pho/stress2/misc/mmap4.sh (revision 278501) @@ -1,117 +1,117 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test overcommit of the file system capacity # Causes panic: 1 vncache entries remaining # Fixed in r202529 # Scenario by kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mmap4.c -cc -o mmap4 -Wall -O2 mmap4.c +mycc -o mmap4 -Wall -O2 mmap4.c rm -f mmap4.c mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 40m -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint /tmp/mmap4 /$mntpoint/file cd $here rm -f /tmp/mmap4 while mount | grep -q $mntpoint; do sync;sync;sync sleep 1 umount $mntpoint done mdconfig -d -u $mdstart exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #define STARTADDR 0x0U #define ADRSPACE 0x06400000U /* 100 Mb */ int main(int argc, char **argv) { int fd, ps; void *p; size_t len; char *c, *path; p = (void *)STARTADDR; len = ADRSPACE; path = argv[1]; if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1,"open()"); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) return (1); err(1, "mmap(1)"); } c = p; ps = getpagesize(); for (c = p; (void *)c < p + len; c += ps) { *c = 1; } close(fd); return (0); } Index: user/pho/stress2/misc/mmap5.sh =================================================================== --- user/pho/stress2/misc/mmap5.sh (revision 278500) +++ user/pho/stress2/misc/mmap5.sh (revision 278501) @@ -1,129 +1,131 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario inspired by alc@ # "panic: vm_page_dirty: page is invalid!" seen. # Fixed in r255396. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c -cc -o mmap5 -Wall -Wextra wire_no_page.c || exit 1 +mycc -o mmap5 -Wall -Wextra wire_no_page.c || exit 1 rm -f wire_no_page.c cd $odir cp /tmp/mmap5 /tmp/mmap5.inputfile (cd ../testcases/swap; ./swap -t 1m -i 2) & cp /tmp/mmap5 /tmp/mmap5.inputfile /tmp/mmap5 /tmp/mmap5.inputfile while killall -9 swap; do sleep .1 done > /dev/null 2>&1 wait rm -f /tmp/mmap5 /tmp/mmap5.inputfile exit EOF #include #include #include #include #include #include #include #include #include #include const char *file; void test2(void) { struct stat st; char *p; size_t len; int error, fd; if ((fd = open(file, O_RDWR)) == -1) err(1, "open %s", file); if ((error = fstat(fd, &st)) == -1) err(1, "stat(%s)", file); len = round_page(st.st_size); if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); p[arc4random() % len] = 1; if (arc4random() % 100 < 50) if ((error = mlock(p, len)) == -1) err(1, "mlock"); p[arc4random() % len] = 1; if (arc4random() % 100 < 50) if ((error = msync(p, len, MS_SYNC | MS_INVALIDATE)) == -1) if (errno != EBUSY) err(1, "msync"); if (munmap(p, len) == -1) err(1, "unmap()"); close(fd); _exit(0); } void test(void) { int i; for (i = 0; i < 3; i++) if (fork() == 0) test2(); for (i = 0; i < 3; i++) wait(NULL); _exit(0); } int main(int argc, char *argv[]) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); file = argv[1]; for (i = 0; i < 30000; i++) { if (fork() == 0) test(); wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap6.sh =================================================================== --- user/pho/stress2/misc/mmap6.sh (revision 278500) +++ user/pho/stress2/misc/mmap6.sh (revision 278501) @@ -1,173 +1,175 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario inspired by alc@ # "panic: vm_page_dirty: page is invalid!" seen. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c -cc -o mmap6 -Wall -Wextra wire_no_page.c || exit 1 +mycc -o mmap6 -Wall -Wextra wire_no_page.c || exit 1 rm -f wire_no_page.c cd $odir cp /tmp/mmap6 /tmp/mmap6.inputfile (cd ../testcases/swap; ./swap -t 1m -i 2) & cp /tmp/mmap6 /tmp/mmap6.inputfile /tmp/mmap6 /tmp/mmap6.inputfile while killall -9 swap; do sleep .1 done > /dev/null 2>&1 wait rm -f /tmp/mmap6 /tmp/mmap6.inputfile exit EOF #include #include #include #include #include #include #include #include #include #include const char *file; char c; void rd(void) { struct stat st; char *p1, *p2; size_t len; int error, fd; if ((fd = open(file, O_RDONLY)) == -1) err(1, "open %s", file); if ((error = fstat(fd, &st)) == -1) err(1, "stat(%s)", file); len = round_page(st.st_size); if ((p1 = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); if ((p2 = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); c = p1[arc4random() % len]; c = p2[arc4random() % len]; if (arc4random() % 100 < 50) if ((error = mlock(p1, len)) == -1) err(1, "mlock"); c = p1[arc4random() % len]; if (munmap(p2, len) == -1) err(1, "unmap()"); if (munmap(p1, len) == -1) err(1, "unmap()"); close(fd); } void wr(void) { struct stat st; char *p1, *p2; size_t len; int error, fd; if ((fd = open(file, O_RDWR)) == -1) err(1, "open %s", file); if ((error = fstat(fd, &st)) == -1) err(1, "stat(%s)", file); len = round_page(st.st_size); if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); if ((p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); p1[arc4random() % len] = 1; p2[arc4random() % len] = 1; if (arc4random() % 100 < 50) if ((error = mlock(p1, len)) == -1) err(1, "mlock"); p1[arc4random() % len] = 1; if (arc4random() % 100 < 50) if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) if (errno != EBUSY) err(1, "msync"); if (munmap(p2, len) == -1) err(1, "unmap()"); if (munmap(p1, len) == -1) err(1, "unmap()"); close(fd); } void test2(void) { if (arc4random() % 100 < 30) rd(); else wr(); _exit(0); } void test(void) { int i; for (i = 0; i < 3; i++) if (fork() == 0) test2(); for (i = 0; i < 3; i++) wait(NULL); _exit(0); } int main(int argc, char *argv[]) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); file = argv[1]; for (i = 0; i < 30000; i++) { if (fork() == 0) test(); wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap7.sh =================================================================== --- user/pho/stress2/misc/mmap7.sh (revision 278500) +++ user/pho/stress2/misc/mmap7.sh (revision 278501) @@ -1,147 +1,149 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario inspired by alc@ # Threaded version in order to "use the same pmap", as pointed out by kib@ +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c -cc -o mmap7 -Wall -Wextra wire_no_page.c -lpthread || exit 1 +mycc -o mmap7 -Wall -Wextra wire_no_page.c -lpthread || exit 1 rm -f wire_no_page.c cd $odir cp /tmp/mmap7 /tmp/mmap7.inputfile (cd ../testcases/swap; ./swap -t 1m -i 2) & cp /tmp/mmap7 /tmp/mmap7.inputfile /tmp/mmap7 /tmp/mmap7.inputfile while ps | grep -v grep | grep -qw swap; do killall -9 swap 2>/dev/null sleep .1 done wait rm -f /tmp/mmap7 /tmp/mmap7.inputfile exit EOF #include #include #include #include #include #include #include #include #include #include #include #include char *p1, *p2, *p3; char c; const char *file; int fd; size_t len; struct stat st; void * test2(void *arg __unused) { int error, i; p1[arc4random() % len] = 1; p2[arc4random() % len] = 1; if (arc4random() % 100 < 30) i = p3[arc4random() % len]; if (arc4random() % 100 < 50) if ((error = mlock(p1, len)) == -1) err(1, "mlock"); if (arc4random() % 100 < 50) if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) if (errno != EBUSY) err(1, "msync"); return (0); } void test(void) { int error, i; pthread_t cp[3]; if ((fd = open(file, O_RDWR)) == -1) err(1, "open %s", file); if ((error = fstat(fd, &st)) == -1) err(1, "stat(%s)", file); len = round_page(st.st_size); if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); if ((p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); if ((p3 = mmap(NULL, len, PROT_READ , MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); for (i = 0; i < 3; i++) if (pthread_create(&cp[i], NULL, test2, NULL) != 0) perror("pthread_create"); for (i = 0; i < 3; i++) pthread_join(cp[i], NULL); if (munmap(p3, len) == -1) err(1, "unmap()"); if (munmap(p2, len) == -1) err(1, "unmap()"); if (munmap(p1, len) == -1) err(1, "unmap()"); close(fd); _exit(0); } int main(int argc, char *argv[]) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); file = argv[1]; for (i = 0; i < 30000; i++) { if (fork() == 0) test(); wait(NULL); } return (0); } Index: user/pho/stress2/misc/mmap8.sh =================================================================== --- user/pho/stress2/misc/mmap8.sh (revision 278500) +++ user/pho/stress2/misc/mmap8.sh (revision 278501) @@ -1,89 +1,91 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vm_fault_copy_wired: page missing" seen: # http://people.freebsd.org/~pho/stress/log/mmap8.txt # Fixed in r265002. # Test scenario by: Mark Johnston markj@ +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mmap8.c # At one point during the fix development, only the thread version would panic -cc -o mmap8 -Wall -Wextra mmap8.c || exit 1 -cc -o mmap8p -Wall -Wextra mmap8.c -pthread || exit 1 +mycc -o mmap8 -Wall -Wextra mmap8.c || exit 1 +mycc -o mmap8p -Wall -Wextra mmap8.c -pthread || exit 1 rm -f mmap8.c cd $odir /tmp/mmap8p /tmp/mmap8 rm -f /tmp/mmap8 /tmp/mmap8p exit EOF #include #include #include #include #include int main(void) { size_t sz = 1; char *addr; /* * This is the minimum amount of C code it takes to panic the kernel. * This is as submitted and thus not a complete and correct test program. */ addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (addr == NULL) err(1, "mmap"); memset(addr, 0, sz); if (fork() != 0) { if (mprotect(addr, sz, PROT_READ)) err(1, "mprotect"); if (mlock(addr, sz)) err(1, "mlock"); if (mprotect(addr, sz, PROT_WRITE | PROT_READ)) err(1, "mprotect"); if (munmap(addr, sz)) err(1, "munmap"); } else sleep(1); return (0); } Index: user/pho/stress2/misc/mmap9.sh =================================================================== --- user/pho/stress2/misc/mmap9.sh (revision 278500) +++ user/pho/stress2/misc/mmap9.sh (revision 278501) @@ -1,95 +1,97 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vm_map_protect: object 0xca6869c0 overcharged" seen: # http://people.freebsd.org/~pho/stress/log/mmap9.txt # Fixed in r265843 # Test scenario by: Mark Johnston markj@ +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mmap9.c # At one point during the fix development, only the thread version would panic -cc -o mmap9 -O2 -Wall -Wextra mmap9.c || exit 1 -cc -o mmap9p -O2 -Wall -Wextra mmap9.c -lpthread || exit 1 +mycc -o mmap9 -O2 -Wall -Wextra mmap9.c || exit 1 +mycc -o mmap9p -O2 -Wall -Wextra mmap9.c -lpthread || exit 1 rm -f mmap9.c cd $odir /tmp/mmap9 /tmp/mmap9p rm -f /tmp/mmap9 /tmp/mmap9p exit EOF #include #include #include #include #include int main(void) { size_t sz = 1; char *addr; /* * This is the minimum amount of C code it takes to panic the kernel. * This is as submitted and thus not a complete and correct test program. */ addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (addr == NULL) err(1, "mmap"); memset(addr, 0, sz); if (fork() != 0) { if (mlock(addr, sz)) err(1, "mlock"); if (mprotect(addr, sz, PROT_READ)) err(1, "mprotect"); if (mprotect(addr, sz, PROT_READ | PROT_WRITE)) err(1, "mprotect"); if (mprotect(addr, sz, PROT_READ)) err(1, "mprotect"); if (mprotect(addr, sz, PROT_READ | PROT_WRITE)) err(1, "mprotect"); } else /* * Ensure that shadow objects aren't collapsed by process exit. */ sleep(1); return (0); } Index: user/pho/stress2/misc/mountu.sh =================================================================== --- user/pho/stress2/misc/mountu.sh (revision 278500) +++ user/pho/stress2/misc/mountu.sh (revision 278501) @@ -1,166 +1,166 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Change mount point from rw to ro with a file mapped rw # Currently fails for NFS [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mountu.c -cc -o mountu -Wall -Wextra -O2 mountu.c +mycc -o mountu -Wall -Wextra -O2 mountu.c rm -f mountu.c pstat() { pid=`ps a | grep -v grep | grep /tmp/mountu | awk '{print $1}'` [ -n "$pid" ] && procstat -v $pid } mount | grep -q "$mntpoint " && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 100m -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}${part} > /dev/null mount /dev/md${mdstart}${part} $mntpoint chmod 777 $mntpoint /tmp/mountu $mntpoint/file & sleep 1 if ! mount -u -o ro $mntpoint 2>&1 | grep -q "Device busy"; then echo "UFS FAILED" pstat fi wait while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw $nfs_export \ $mntpoint rm -f /tmp/file /tmp/mountu $mntpoint/file & sleep 1 if ! mount -u -o ro $mntpoint 2>&1 | grep -q "Device busy"; then echo "NFS FAILED" fi wait umount $mntpoint fi if [ -x /sbin/mount_msdosfs ]; then mdconfig -a -t swap -s 100m -u $mdstart bsdlabel -w md${mdstart} auto newfs_msdos -F 16 -b 8192 /dev/md${mdstart}$part > /dev/null 2>&1 mount_msdosfs -m 777 /dev/md${mdstart}$part $mntpoint /tmp/mountu $mntpoint/file & sleep 1 if ! mount -u -o ro $mntpoint 2>&1 | grep -q "Device busy"; then echo "MSDOS FAILED" fi wait while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done fi rm -f /tmp/mountu /tmp/file exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #define STARTADDR 0x0U #define ADRSPACE 0x0640000U int main(int argc __unused, char **argv) { int fd, ps; void *p; size_t len; struct passwd *pw; char *c, *path; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); p = (void *)STARTADDR; len = ADRSPACE; path = argv[1]; if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1,"open(%s)", path); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) { warn("mmap()"); return (1); } err(1, "mmap(1)"); } c = p; ps = getpagesize(); for (c = p; (void *)c < p + len; c += ps) { *c = 1; } close(fd); sleep(5); return (0); } Index: user/pho/stress2/misc/msdos5.sh =================================================================== --- user/pho/stress2/misc/msdos5.sh (revision 278500) +++ user/pho/stress2/misc/msdos5.sh (revision 278501) @@ -1,61 +1,61 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: Freeing unused sector 79510 22 ff800000" seen. # http://people.freebsd.org/~pho/stress/log/msdos5.txt # FS corruption seen: http://people.freebsd.org/~pho/stress/log/msdos5-2.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 [ -x /sbin/mount_msdosfs ] || exit . ../default.cfg -cc -o /tmp/fstool -Wall -Wextra -O2 ../tools/fstool.c || exit 1 +mycc -o /tmp/fstool -Wall -Wextra -O2 ../tools/fstool.c || exit 1 cd /tmp mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 3g -u $mdstart bsdlabel -w md$mdstart auto newfs_msdos -F 32 -b 8192 /dev/md${mdstart}$part > /dev/null 2>&1 mount_msdosfs -m 777 /dev/md${mdstart}$part $mntpoint for i in `jot 5`; do (mkdir $mntpoint/test$i; cd $mntpoint/test$i; /tmp/fstool -l -f 400 -n 200 -s ${i}k) done sleep 1 rm -rf $mntpoint/* || echo FAIL while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done rm -f /tmp/fstool Index: user/pho/stress2/misc/msync.sh =================================================================== --- user/pho/stress2/misc/msync.sh (revision 278500) +++ user/pho/stress2/misc/msync.sh (revision 278501) @@ -1,201 +1,203 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # msync(2) / mlockall(2) test scenario. # "panic: vm_fault_copy_wired: page missing" seen. # http://people.freebsd.org/~pho/stress/log/msync.txt # Fixed in r253189. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/msync.c -cc -o msync -Wall -Wextra msync.c -lpthread || exit 1 +mycc -o msync -Wall -Wextra msync.c -lpthread || exit 1 rm -f msync.c cd $odir /tmp/msync killall msync > /dev/null 2>&1 rm -f /tmp/msync exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int syscallno = SYS_msync; #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * calls(void *arg __unused) { int i, num; unsigned long arg1, arg2, arg3; usleep(1000); num = syscallno; for (i = 0; i < 500; i++) { arg1 = makearg(); arg2 = makearg(); #if 0 arg3 = makearg(); arg3 = arg3 & ~MS_INVALIDATE; /* No problem seen */ #else arg3 = MS_INVALIDATE; /* panic */ #endif #if 0 fprintf(stderr, "%2d : syscall(%3d, 0x%lx, 0x%lx, 0x%lx)\n", i, num, arg1, arg2, arg3); usleep(50000); #endif alarm(1); syscall(num, arg1, arg2, arg3); num = 0; } return (0); } void wd(void) { int i; if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) err(1, "mlockall failed"); for (i = 0; i < 800; i++) { if (fork() == 0) { usleep(20000); _exit(0); } wait(NULL); usleep(100000); } _exit(0); } int main(void) { struct passwd *pw; pthread_t cp[50]; int i, j; if (fork() == 0) wd(); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); alarm(180); for (i = 0; i < 8000; i++) { if (fork() == 0) { arc4random_stir(); for (j = 0; j < N; j++) r[j] = arc4random(); for (j = 0; j < 50; j++) if (pthread_create(&cp[j], NULL, calls, NULL) != 0) perror("pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } Index: user/pho/stress2/misc/msync2.sh =================================================================== --- user/pho/stress2/misc/msync2.sh (revision 278500) +++ user/pho/stress2/misc/msync2.sh (revision 278501) @@ -1,126 +1,128 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: vm_pageout_flush: partially invalid page xx index 0/1" seen. # Fixed in r255566. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/msync2.c -cc -o msync2 -Wall -Wextra msync2.c || exit 1 +mycc -o msync2 -Wall -Wextra msync2.c || exit 1 rm -f msync2.c cd $odir dd if=/dev/zero bs=$((4096 + 1)) of=/tmp/msync2.inputfile count=1 2>&1 | egrep -v "records|transferred" /tmp/msync2 /tmp/msync2.inputfile rm -f /tmp/msync2 /tmp/msync2.inputfile exit EOF #include #include #include #include #include #include #include #include #include #include const char *file; char c; void wr(void) { struct stat st; char *p1; size_t len; int error, fd; if ((fd = open(file, O_RDWR)) == -1) err(1, "open %s", file); if ((error = fstat(fd, &st)) == -1) err(1, "stat(%s)", file); len = round_page(st.st_size); if ((p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap"); // p1[len - 1] = 1; /* No panic with this */ p1[arc4random() % len] = 1; /* Need this for the panic */ if ((error = msync(p1, len, MS_SYNC | MS_INVALIDATE)) == -1) if (errno != EBUSY) err(1, "msync"); if (munmap(p1, len) == -1) err(1, "unmap()"); close(fd); _exit(0); } void test(void) { #if 1 int i; for (i = 0; i < 3; i++) if (fork() == 0) wr(); for (i = 0; i < 3; i++) wait(NULL); #else wr(); /* No problem here */ #endif _exit(0); } int main(int argc, char *argv[]) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); file = argv[1]; for (i = 0; i < 30000; i++) { if (fork() == 0) test(); wait(NULL); } return (0); } Index: user/pho/stress2/misc/namecache.sh =================================================================== --- user/pho/stress2/misc/namecache.sh (revision 278500) +++ user/pho/stress2/misc/namecache.sh (revision 278501) @@ -1,218 +1,218 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test case for vfs.lookup_shared=1 that shows possible name cache # inconsistency: # $ ls -l /tmp/file.05015? # ls: /tmp/file.050150: No such file or directory # $ fsdb -r /dev/ad4s1e # ** /dev/ad4s1e (NO WRITE) # Examining file system `/dev/ad4s1e' # Last Mounted on /tmp # current inode: directory # I=2 MODE=41777 SIZE=5120 # BTIME=May 7 05:54:47 2006 [0 nsec] # MTIME=Apr 2 11:27:36 2009 [0 nsec] # CTIME=Apr 2 11:27:36 2009 [0 nsec] # ATIME=Apr 2 12:00:30 2009 [0 nsec] # OWNER=root GRP=wheel LINKCNT=35 FLAGS=0 BLKCNT=c GEN=65f71df4 # fsdb (inum: 2)> lookup file.050150 # component `file.050150': current inode: regular file # I=198 MODE=100600 SIZE=0 # BTIME=Apr 2 11:24:33 2009 [0 nsec] # MTIME=Apr 2 11:24:33 2009 [0 nsec] # CTIME=Apr 2 11:24:33 2009 [0 nsec] # ATIME=Apr 2 11:24:33 2009 [0 nsec] # OWNER=pho GRP=wheel LINKCNT=1 FLAGS=0 BLKCNT=0 GEN=1deaab3a # fsdb (inum: 198)> quit # $ # Consistency is restored by a umount + mount of the FS # Observations: # No problems seen with vfs.lookup_shared=0. # Does not fail in a "private" subdirectory . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > namecache.c -cc -o namecache -Wall namecache.c +mycc -o namecache -Wall namecache.c rm -f namecache.c #dir=/tmp/namecache.dir # No problems seen dir=/tmp [ -d $dir ] || mkdir -p $dir cd $dir start=`date '+%s'` for i in `jot 30`; do for j in `jot 10`; do /tmp/namecache & done for j in `jot 10`; do wait done [ $((`date '+%s'` - start)) -gt 1800 ] && break done if ls -l ${dir}/file.0* 2>&1 | egrep "file.0[0-9]" | grep -q "No such file"; then echo FAIL echo "ls -l ${dir}/file.0*" ls -l ${dir}/file.0* fi rm -f /tmp/namecache # /${dir}/file.0* exit EOF /* Test scenario for possible name cache problem */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include static char path[MAXPATHLEN+1]; static char buf[64 * 1024]; void pm(void) { int fd, n; int space = sizeof(buf); struct stat statb; long base; struct dirent *dp; char *bp = buf; if ((fd = open(".", O_RDONLY)) == -1) err(1, "open(%s)", "."); do { if ((n = getdirentries(fd, bp, space, &base)) == -1) err(1, "getdirentries"); space = space - n; bp = bp + n; } while (n != 0); close(fd); bp = buf; dp = (struct dirent *)bp; for (;;) { if (strcmp(path, dp->d_name) == 0) { if (stat(dp->d_name, &statb) == -1) { warn("stat(%s)", dp->d_name); printf("name: %-10s, inode %7d, type %2d, namelen %d, d_reclen %d\n", dp->d_name, dp->d_fileno, dp->d_type, dp->d_namlen, dp->d_reclen); fflush(stdout); } else { printf("stat(%s) succeeded!\n", path); fflush(stdout); } } bp = bp + dp->d_reclen; dp = (struct dirent *)bp; if (dp->d_reclen <= 0) break; } } static void reader(void) { int fd; if ((fd = open(path, O_RDWR, 0600)) < 0) { warn("open(%s). %s:%d", path, __FILE__, __LINE__); pm(); exit(1); } close(fd); return; } static void writer(void) { int fd; if ((fd = open(path, O_RDWR, 0600)) < 0) { warn("open(%s). %s:%d", path, __FILE__, __LINE__); pm(); exit(1); } close(fd); return; } int main(int argc, char **argv) { pid_t pid; int fd, i, status; for (i = 0; i < 10000; i++) { if (sprintf(path, "file.0%d", getpid()) < 0) err(1, "sprintf()"); if ((fd = open(path, O_CREAT | O_RDWR, 0600)) == -1) err(1, "open(%s)", path); close(fd); if ((pid = fork()) == 0) { writer(); exit(EXIT_SUCCESS); } else if (pid > 0) { reader(); if (waitpid(pid, &status, 0) == -1) warn("waitpid(%d)", pid); } else err(1, "fork(), %s:%d", __FILE__, __LINE__); if (unlink(path) == -1) err(1, "unlink(%s). %s:%d", path, __FILE__, __LINE__); } return (0); } Index: user/pho/stress2/misc/namecache2.sh =================================================================== --- user/pho/stress2/misc/namecache2.sh (revision 278500) +++ user/pho/stress2/misc/namecache2.sh (revision 278501) @@ -1,194 +1,194 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # UFS cache inconsistancy for rename(2) demonstrated # Fails with: # ls -ali /mnt # ls: tfa1022: No such file or directory # Fixed by r248422 # Test scenario obtained from Rick Miller [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # This threaded test is designed for MP. [ `sysctl hw.ncpu | sed 's/.* //'` -eq 1 ] && exit 0 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > namecache2.c rm -f /tmp/namecache2 -cc -o namecache2 -Wall -Wextra -g -O2 namecache2.c -lpthread || exit 1 +mycc -o namecache2 -Wall -Wextra -g -O2 namecache2.c -lpthread || exit 1 rm -f namecache2.c cd $odir mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint (cd $mntpoint; /tmp/namecache2) f=`(cd $mntpoint; echo *)` if [ "$f" != '*' ]; then echo FAIL echo "echo $mntpoint/*" echo $mntpoint/* echo "" echo "ls -ali $mntpoint" ls -ali $mntpoint echo "" echo "fsdb -r /dev/md${mdstart}$part" fsdb -r /dev/md${mdstart}$part <<-EF ls quit EF fi while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/namecache2 exit 0 EOF /* * NOTE: This must be run with the current working directory on a local UFS * disk partition, to demonstrate a FreeBSD namecache bug. I have never seen * this bug happen with an NFS partition. */ #include #include #include #include #include #include #include #include #include #include #include int stopping = false; char *pFilename = 0; static void * statThread(void *arg __unused) { struct stat statData; int rc; for (;;) { while (pFilename == 0) { if (stopping) return 0; } rc = stat(pFilename, &statData); if (rc < 0 && errno != ENOENT) { printf(" statThread stat() on %s failed with errno %d\n", pFilename, errno); return 0; } } return 0; } int main(void) { char filename1 [20], filename2[20], filename3[20]; pthread_t threadId; struct stat statData; int result, fd; unsigned int number; struct timespec period; time_t start; sprintf(filename1, "tfa0"); fd = open(filename1, O_CREAT, S_IRWXU); if (fd < 0) { printf("open(O_CREAT) on %s failed with errno %d\n", filename1, errno); return 0; } if (close(fd) < 0) { printf("close() on %s failed with errno %d\n", filename1, errno); return 0; } result = pthread_create(&threadId, NULL, statThread, NULL); if (result < 0) err(1, "pthread_create(): %s\n", strerror(result)); start = time(NULL); for (number = 0; number < 0x001FFFFF; number += 2) { sprintf(filename1, "tfa%u", number); sprintf(filename2, "tfa%u", number + 1); sprintf(filename3, "tfa%u", number + 2); if (rename(filename1, filename2) < 0) { printf(" rename1() from %s to %s failed with errno %d\n", filename1, filename2, errno); return 0; } pFilename = filename3; if (rename(filename2, filename3) < 0) { printf(" rename2() from %s to %s failed with errno %d\n", filename2, filename3, errno); return 0; } pFilename = 0; period.tv_sec = 0; period.tv_nsec = 500; nanosleep(&period, 0); if (stat(filename3, &statData) < 0) { printf("stat(%s) failed with errno %d\n", filename3, errno); stopping = true; period.tv_sec = 0; period.tv_nsec = 500; nanosleep(&period, 0); return 0; } if (time(NULL) - start > 600) { fprintf(stderr, "Test timed out.\n"); break; } } unlink(filename3); return 0; } Index: user/pho/stress2/misc/nanosleep.sh =================================================================== --- user/pho/stress2/misc/nanosleep.sh (revision 278500) +++ user/pho/stress2/misc/nanosleep.sh (revision 278501) @@ -1,96 +1,98 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # -# A simplistic regression test for r200510: +# A simplistic regression test for r200510: [ `sysctl kern.hz | sed 's/.* //'` -ne 1000 ] && exit 1 +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > nanosleep.c -cc -o nanosleep -Wall -Wextra nanosleep.c || exit 1 +mycc -o nanosleep -Wall -Wextra nanosleep.c || exit 1 rm -f nanosleep.c /tmp/nanosleep || exit rm -f /tmp/nanosleep exit 0 EOF #include #include #include #include #include #include #define timespecsub(vvp, uvp) \ do { \ (vvp)->tv_sec -= (uvp)->tv_sec; \ (vvp)->tv_nsec -= (uvp)->tv_nsec; \ if ((vvp)->tv_nsec < 0) { \ (vvp)->tv_sec--; \ (vvp)->tv_nsec += 1000000000; \ } \ } while (0) #define N 20000 int main(void) { struct timespec rqt, rmt; struct timespec start, finish; long m; int i; m = LONG_MAX; for (i = 0; i < 100; i++) { rqt.tv_sec = 0; rqt.tv_nsec = N; clock_gettime(CLOCK_REALTIME_PRECISE, &start); if (nanosleep(&rqt, &rmt) == -1) err(1, "nanosleep"); clock_gettime(CLOCK_REALTIME_PRECISE, &finish); timespecsub(&finish, &start); if (finish.tv_nsec < N) errx(1, "Short sleep: %ld", finish.tv_nsec); // fprintf(stderr, "asked for %f, got %f\n", (double)N / 1e9, // (double)finish.tv_nsec / 1e9); if (m > finish.tv_nsec) m = finish.tv_nsec; } if (m > 2 * N) { fprintf(stderr, "nanosleep(%fs). Best value is %fs.\n", (double)N / 1e9, (double)m / 1e9); errx(1, "FAIL"); } return (0); } Index: user/pho/stress2/misc/nbufkv.sh =================================================================== --- user/pho/stress2/misc/nbufkv.sh (revision 278500) +++ user/pho/stress2/misc/nbufkv.sh (revision 278501) @@ -1,138 +1,138 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario with a 20G files on two UFS2 FSs with 64k/64k # Test program will hang (deadlock) in "nbufkv" # Test scenario by John-Mark Gurney [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > nbufkv.c -cc -o nbufkv -Wall nbufkv.c +mycc -o nbufkv -Wall nbufkv.c rm -f nbufkv.c cd $odir u1=$mdstart u2=$((u1 + 1)) d1=/tmp/diskimage1 d2=/tmp/diskimage2 mp1=$mntpoint mp2=${mntpoint}2 [ -d $mp1 ] || mkdir $mp1 [ -d $mp2 ] || mkdir $mp2 truncate -s 20g $d1 truncate -s 20g $d2 mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part mdconfig -l | grep -q md${u2} && mdconfig -d -u $u2 mdconfig -l | grep -q md${u1} && mdconfig -d -u $u1 mdconfig -a -t vnode -f $d1 -u $u1 bsdlabel -w md$u1 auto newfs -b 65536 -f 65536 -O2 md${u1}$part > /dev/null mdconfig -a -t vnode -f $d2 -u $u2 bsdlabel -w md$u2 auto newfs -b 65536 -f 65536 -O2 md${u2}$part > /dev/null mount /dev/md${u1}$part $mp1 mount /dev/md${u2}$part $mp2 /tmp/nbufkv /$mp1 & /tmp/nbufkv /$mp2 & wait;wait umount /dev/md${u2}$part umount /dev/md${u1}$part mount | grep -q /dev/md${u2}$part && umount -f /dev/md${u2}$part mount | grep -q /dev/md${u1}$part && umount -f /dev/md${u1}$part mdconfig -d -u $u2 mdconfig -d -u $u1 rm -rf $d1 $d2 /tmp/nbufkv exit EOF #include #include #include #include #include #include #include void work(int fd, size_t n) { int i; for (i = 0; i < 128 * 1024; i++) { n = n - PAGE_SIZE; if (lseek(fd, n , SEEK_SET) == -1) err(1, "lseek()"); if (write(fd, "1", 1) != 1) err(1, "write()"); } } int main(int argc, char **argv) { int fd; off_t len; char path[128]; len = 20; len = len * 1024 * 1024 * 1024; sprintf(path, "%s/nbufkv.%06d", argv[1], getpid()); if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0640)) == -1) err(1,"open(%s)", path); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); work(fd, len); close(fd); if (unlink(path) == -1) err(1, "unlink(%s)", path); return (0); } Index: user/pho/stress2/misc/newfs4.sh =================================================================== --- user/pho/stress2/misc/newfs4.sh (revision 278500) +++ user/pho/stress2/misc/newfs4.sh (revision 278501) @@ -1,126 +1,126 @@ #!/bin/sh # # Copyright (c) 2008-2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg # Deadlock problems. Test scenario by Lev Serebryakov # newfs -O2 -U -b 65536 # The io programs will get stuck in nbufkv wait state. odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > newfs4.c -cc -o newfs4 -Wall -Wextra newfs4.c +mycc -o newfs4 -Wall -Wextra newfs4.c rm -f newfs4.c cd $odir mount | grep "$mntpoint" | grep -q md${mdstart}$part && umount $mntpoint mdconfig -l | grep md$mdstart > /dev/null && mdconfig -d -u $mdstart size=9 # Gb [ `df -k $(dirname $diskimage) | tail -1 | \ awk '{print $4'}` -lt $((size * 1024 * 1024)) ] && \ echo "Not enough disk space on `dirname $diskimage`." && exit 1 truncate -s ${size}G $diskimage blocksize="-b 65536" opt="-O2 -U" mdconfig -a -t vnode -f $diskimage -u $mdstart bsdlabel -w md$mdstart auto newfs $blocksize $opt md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint truncate -s 2g f1 truncate -s 2g f2 truncate -s 2g f3 truncate -s 2g f4 /tmp/newfs4 f1 & /tmp/newfs4 f2 & /tmp/newfs4 f3 & /tmp/newfs4 f4 & wait while mount | grep "$mntpoint" | grep -q md${mdstart}$part; do umount -f $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f $diskimage rm -f /tmp/newfs4 exit EOF #include #include #include #include #include #include #include /* Perform random IO operations on a file */ int main(int argc, char **argv) { struct stat sb; char buf[256]; off_t bp, maxb; int fd; long i; if (argc != 2) { fprintf(stderr, "Usage %s: file\n", argv[0]); return (1); } if ((fd = open(argv[1], O_RDWR)) == -1) err(1, "open(%s)", argv[1]); if (fstat(fd, &sb) == -1) err(1, "fstatf(stdin)"); maxb = sb.st_size - sizeof(buf); for (i = 0; i < 10000; i++) { bp = arc4random(); bp = (bp << 31 | arc4random()) % maxb; // printf("%jd\n", bp); if (lseek(fd, bp, 0) == -1) err(1, "lseek()"); if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write()"); } close(fd); return (0); } Index: user/pho/stress2/misc/nfs12.sh =================================================================== --- user/pho/stress2/misc/nfs12.sh (revision 278500) +++ user/pho/stress2/misc/nfs12.sh (revision 278501) @@ -1,159 +1,159 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "umount -f" test scenario (distill of nfs4.sh) # "panic: vputx: missed vn_close" seen. # Fixed in r248815 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg [ -z "$nfs_export" ] && exit 0 ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || exit 0 here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > nfs12.c -cc -o nfs12 -Wall -Wextra -O2 -g nfs12.c +mycc -o nfs12 -Wall -Wextra -O2 -g nfs12.c rm -f nfs12.c cd $here mount | grep "on $mntpoint " | grep nfs > /dev/null && umount $mntpoint version="-o nfsv3" # The default [ $# -eq 1 ] && [ "$1" -eq 4 ] && version="-o nfsv4" for i in `jot 10`; do mount -t nfs $version -o tcp -o retrycnt=3 -o intr -o soft -o rw \ $nfs_export $mntpoint sleep 2 (cd $mntpoint; /tmp/nfs12 > /dev/null 2>&1) & sleep 2 while mount | grep "on $mntpoint " | grep -q nfs; do umount -f $mntpoint done kill -9 $! > /dev/null 2>/dev/null && kill $! wait done rm -f /tmp/nfs12 exit EOF #include #include #include #include #include #include #include #include #include #include #include #define INPUTFILE "/bin/date" #define PARALLEL 5 int tmmap(void) { int i; pid_t pid; char file[128]; int fdin, fdout; char *src, *dst; struct stat statbuf; pid = getpid(); setproctitle("mmap"); for (i = 0; i < 50000; i++) { sprintf(file,"p%05d.%05d", pid, i); if ((fdin = open(INPUTFILE, O_RDONLY)) < 0) err(1, INPUTFILE); if ((fdout = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "%s", file); if (fstat(fdin, &statbuf) < 0) err(1, "fstat error"); if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) == -1) err(1, "lseek error"); /* write a dummy byte at the last location */ if (write(fdout, "", 1) != 1) err(1, "write error"); if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) == (caddr_t) - 1) err(1, "mmap error for input"); if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdout, 0)) == (caddr_t) - 1) err(1, "mmap error for output"); memcpy(dst, src, statbuf.st_size); if (munmap(src, statbuf.st_size) == -1) err(1, "munmap"); close(fdin); if (munmap(dst, statbuf.st_size) == -1) err(1, "munmap"); close(fdout); if (unlink(file) == -1) err(3, "unlink(%s)", file); } _exit(0); } int main(void) { int i; for (i = 0; i < PARALLEL; i++) { if (fork() == 0) tmmap(); } for (i = 0; i < PARALLEL; i++) { wait(NULL); } return (0); } Index: user/pho/stress2/misc/nfsrename.sh =================================================================== --- user/pho/stress2/misc/nfsrename.sh (revision 278500) +++ user/pho/stress2/misc/nfsrename.sh (revision 278501) @@ -1,214 +1,214 @@ #!/bin/sh # # Copyright (c) 2008-2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg # Test scenario by jhb@ [ -z "$nfs_export" ] && exit 0 ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 || exit 0 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > nfsrename.c -cc -o nfsrename -Wall nfsrename.c +mycc -o nfsrename -Wall nfsrename.c rm -f nfsrename.c cd $odir mount | grep "$mntpoint" | grep nfs > /dev/null && umount $mntpoint mount -t nfs -o tcp -o retrycnt=3 -o intr -o soft -o rw $nfs_export $mntpoint for i in `jot 10`; do /tmp/nfsrename $mntpoint/nfsrename.$i & done for i in `jot 10`; do wait done killall nfsrename rm -f $mntpoint/nfsrename.* umount $mntpoint > /dev/null 2>&1 while mount | grep "$mntpoint" | grep -q nfs; do umount -f $mntpoint > /dev/null 2>&1 done rm -f /tmp/nfsrename exit EOF /* * Try to expose races with doing renames over NFS that require silly * renames. This results in 2 different RENAME RPCs leaving a race * window where the file may not exist. It also appears that FreeBSD * with shared lookups in NFS can get confused and possibly reference * the sillyrenamed file in lookup but the file is deleted by the time * open gets to it. */ #include #include #include #include #include #include const char *filename; const char *dir; static void usage(void) { fprintf(stderr, "nfsrename: [-n children] file\n"); exit(1); } static void read_file(void) { FILE *fp; char buffer[4096]; fp = fopen(filename, "r"); if (fp == NULL) { warn("fopen"); return; } while (!feof(fp)) { if (fread(buffer, sizeof(buffer), 1, fp) < sizeof(buffer)) break; } if (ferror(fp)) warnx("fread encountered an error"); fclose(fp); } static void write_file(void) { FILE *fp; char path[1024]; int fd; snprintf(path, sizeof(path), "%s/nfsrename.XXXXXX", dir); fd = mkstemp(path); if (fd < 0) { warn("mkstemp"); return; } fp = fdopen(fd, "w"); if (fp == NULL) { warn("fopen:writer"); close(fd); unlink(path); } fprintf(fp, "blah blah blah garbage %ld\n", random()); fclose(fp); if (rename(path, filename) < 0) { warn("rename"); unlink(path); } } static void random_sleep(int base, int slop) { long val; val = random() % slop; usleep(base + val); } static void child(void) { for (;;) { random_sleep(500, 50); read_file(); } exit(0); } int main(int ac, char **av) { long i, nchild; char *cp; int ch; nchild = 1; while ((ch = getopt(ac, av, "n:")) != -1) { switch (ch) { case 'n': nchild = strtol(optarg, &cp, 0); if (*cp != '\0') errx(1, "Invalid count %s", optarg); break; case '?': default: usage(); } } ac -= optind; av += optind; if (ac == 0) errx(1, "Missing filename"); else if (ac > 1) errx(1, "Extra arguments"); filename = av[0]; dir = dirname(filename); srandomdev(); write_file(); for (i = 0; i < nchild; i++) { switch (fork()) { case 0: child(); case -1: err(1, "fork"); } } for (i = 0; i < 10000; i++) { random_sleep(1500, 1000); write_file(); } return (0); } Index: user/pho/stress2/misc/nullfs11.sh =================================================================== --- user/pho/stress2/misc/nullfs11.sh (revision 278500) +++ user/pho/stress2/misc/nullfs11.sh (revision 278501) @@ -1,97 +1,97 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # nullfs cache / nocache benchmark [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 if [ -r ../default.cfg ]; then . ../default.cfg else mntpoint=/mnt mdstart=5 part=a fi export LANG=C CACHE=nullfs11-cache.log NOCACHE=nullfs11-nocache.log mp1=/mnt mp2=/mnt2 [ -d $mp2 ] || mkdir $mp2 rm -f $CACHE $NOCACHE -cc -o /tmp/fstool ../tools/fstool.c +mycc -o /tmp/fstool ../tools/fstool.c test() { opt=$1 mount | grep -wq $mp2 && umount $mp2 mount | grep -wq $mp1 && umount $mp1 mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mp1 mount -t nullfs $opt $mp1 $mp2 i=1 (mkdir $mp2/test$i; cd $mp2/test$i; /tmp/fstool -l -f 50 -n 500 -s 4k) rm -rf $mp2/test$i sync sleep 5 parallel=4 for j in `jot 5`; do s=`date '+%s'` for i in `jot $parallel`; do (mkdir $mp2/test$i; cd $mp2/test$i; \ /tmp/fstool -l -f 50 -n 500 -s $((i * 4))k) & done for i in `jot $parallel`; do wait done rm -rf $mp2/* echo $((`date '+%s'` - $s)) done while mount | grep -wq $mp2; do umount $mp2 || sleep 1 done while mount | grep $mp1 | grep -q /dev/md; do umount $mp1 || sleep 1 done mdconfig -d -u $mdstart } test "-o nocache" > $NOCACHE test "-o cache" > $CACHE ministat -s -w 60 $NOCACHE $CACHE rm -f /tmp/fstool $CACHE $NOCACHE Index: user/pho/stress2/misc/nullfs5.sh =================================================================== --- user/pho/stress2/misc/nullfs5.sh (revision 278500) +++ user/pho/stress2/misc/nullfs5.sh (revision 278501) @@ -1,73 +1,73 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Composit test: nullfs2.sh + kinfo.sh # Kernel page fault with the following non-sleepable locks held from # nullfs/null_vnops.c:531 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d;s/60/600/' < $odir/kinfo.sh > kinfo.c -cc -o kinfo -Wall -g kinfo.c -lutil +mycc -o kinfo -Wall -g kinfo.c -lutil rm -f kinfo.c cd $odir mount | grep -q procfs || mount -t procfs procfs /procfs for j in `jot 5`; do /tmp/kinfo & done [ -d mp1 ] || mkdir mp1 mp=`pwd`/mp1 mount | grep -q $mp && umount -f $mp mount -t nullfs `dirname $RUNDIR` $mp export RUNDIR=`pwd`/mp1/stressX export runRUNTIME=10m (cd ..; ./run.sh marcus.cfg) umount $mp 2>&1 | grep -v busy mount | grep -q $mp && umount -f $mp rm -rf mp1 for j in `jot 5`; do wait done rm -f /tmp/kinfo Index: user/pho/stress2/misc/pcatch.sh =================================================================== --- user/pho/stress2/misc/pcatch.sh (revision 278500) +++ user/pho/stress2/misc/pcatch.sh (revision 278501) @@ -1,149 +1,149 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # The issue makes it possible for applications to get wrong EINTR # or ERESTART (the later is not directly visible) when doing write # to the file on suspended UFS volume. I.e. the thread is sleeping # when fs is suspended, and process is signaled. # Test scenario mostly by kib. # Fixed in r275744. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pcatch.c -cc -o pcatch -Wall -Wextra -O0 -g pcatch.c || exit 1 +mycc -o pcatch -Wall -Wextra -O0 -g pcatch.c || exit 1 rm -f pcatch.c cd $here mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint /tmp/pcatch $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/pcatch exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include void hand_sigaction(int signo __unused, siginfo_t *si __unused, void *c __unused) { } void suspend(char *path) { struct statfs s; int fd, error; if (fork() == 0) { if ((error = statfs(path, &s)) != 0) err(1, "statfs %s", path); fd = open("/dev/ufssuspend", O_RDWR); if ((error = ioctl(fd, UFSSUSPEND, &s.f_fsid)) != 0) err(1, "UFSSUSPEND"); sleep(1); if ((error = ioctl(fd, UFSRESUME, &s.f_fsid)) != 0) err(1, "UFSRESUME"); _exit(0); } } void test(char *mp) { pid_t pid; struct sigaction sa; int fd; char buf[80], file[80]; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = hand_sigaction; if (sigaction(SIGUSR1, &sa, NULL) == -1) err(1, "sigaction"); snprintf(file, sizeof(file), "%s/file", mp); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s). %s:%d", file, __FILE__, __LINE__); suspend(mp); if ((pid = fork()) == 0) { if (write(fd, buf, sizeof(buf)) == -1) warn("FAIL: write"); _exit(0); } usleep(10000); if (kill(pid, SIGUSR1) == -1) err(1, "kill"); wait(NULL); wait(NULL); close(fd); } int main(int argc, char *argv[]) { if (argc != 2) errx(1, "Usage: %s ", argv[0]); test(argv[1]); return (0); } Index: user/pho/stress2/misc/pfl.sh =================================================================== --- user/pho/stress2/misc/pfl.sh (revision 278500) +++ user/pho/stress2/misc/pfl.sh (revision 278501) @@ -1,167 +1,167 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Test scenario for the change of a global SU lock to a per filesystem lock. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pfl.c -cc -o pfl -Wall -Wextra pfl.c || exit 1 +mycc -o pfl -Wall -Wextra pfl.c || exit 1 rm -f pfl.c cd $here mp1=$mntpoint mp2=${mntpoint}2 [ -d $mp2 ] || mkdir -p $mp2 md1=$mdstart md2=$((mdstart + 1)) opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-j" || echo "-U") mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 mdconfig -l | grep -q md$md1 && mdconfig -d -u $md1 mdconfig -a -t swap -s 2g -u $md1 bsdlabel -w md$md1 auto newfs $opt md${md1}$part > /dev/null mount /dev/md${md1}$part $mp1 chmod 777 $mp1 mount | grep "on $mp2 " | grep -q /dev/md && umount -f $mp2 mdconfig -l | grep -q md$md2 && mdconfig -d -u $md2 mdconfig -a -t swap -s 2g -u $md2 bsdlabel -w md$md2 auto newfs $opt md${md2}$part > /dev/null mount /dev/md${md2}$part $mp2 chmod 777 $mp2 su ${testuser} -c "cd $mp1; /tmp/pfl" & su ${testuser} -c "cd $mp2; /tmp/pfl" & wait; wait while mount | grep "$mp2 " | grep -q /dev/md; do umount $mp2 || sleep 1 done mdconfig -d -u $md2 while mount | grep "$mp1 " | grep -q /dev/md; do umount $mp1 || sleep 1 done mdconfig -d -u $md1 exit EOF #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 static int size = 10000; void test(void) { int fd, i, j; pid_t pid; char file[128]; pid = getpid(); sprintf(file,"d%05d", pid); if (mkdir(file, 0740) == -1) err(1, "mkdir(%s)", file); chdir(file); for (j = 0; j < size; j++) { sprintf(file,"p%05d.%05d", pid, j); if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) { if (errno != EINTR) { warn("mkdir(%s). %s:%d", file, __FILE__, __LINE__); unlink("continue"); break; } } if (arc4random() % 100 < 10) if (write(fd, "1", 1) != 1) err(1, "write()"); close(fd); } sleep(3); for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) err(3, "unlink(%s)", file); } chdir(".."); sprintf(file,"d%05d", pid); if (rmdir(file) == -1) err(3, "unlink(%s)", file); } int main(void) { int fd, i, j, k; umask(0); if ((fd = open("continue", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < 1; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) { for (k = 0; k < 50; k++) test(); exit(0); } } for (j = 0; j < PARALLEL; j++) wait(NULL); if (access("continue", R_OK) == -1) { fprintf(stderr, "Loop #%d\n", i + 1); fflush(stderr); break; } } unlink("continue"); return (0); } Index: user/pho/stress2/misc/posix_fadvise.sh =================================================================== --- user/pho/stress2/misc/posix_fadvise.sh (revision 278500) +++ user/pho/stress2/misc/posix_fadvise.sh (revision 278501) @@ -1,75 +1,75 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Memory leak. Fixed in r232702. . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > posix_fadvise.c -cc -o posix_fadvise -Wall -Wextra -O2 -g posix_fadvise.c +mycc -o posix_fadvise -Wall -Wextra -O2 -g posix_fadvise.c n1=`vmstat -m | grep fadvise | awk '{print $2 + 0}'` /tmp/posix_fadvise n2=`vmstat -m | grep fadvise | awk '{print $2 + 0}'` if [ $((n2 - n1)) -gt 10 ]; then echo FAIL vmstat -m | sed -n '1p;/fadvise/p' fi rm -f /tmp/posix_fadvise posix_fadvise.c exit EOF #include #include #include #include #include int main(void) { off_t len, offset; int advise, fd, i; for (i = 0; i < 500; i++) { if ((fd = open("posix_fadvise.c", O_RDONLY)) == -1) err(1, "open()"); offset = arc4random(); len = arc4random(); advise = arc4random() % 6; if (posix_fadvise(fd, offset, len, advise) == -1) warn("posix_fadvise"); close(fd); } return (0); } Index: user/pho/stress2/misc/pread.sh =================================================================== --- user/pho/stress2/misc/pread.sh (revision 278500) +++ user/pho/stress2/misc/pread.sh (revision 278501) @@ -1,190 +1,190 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # pread(2) fuzzing inspired by the iknowthis test suite # by Tavis Ormandy # Fixed in r227527. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pread.c -cc -o pread -Wall -Wextra pread.c +mycc -o pread -Wall -Wextra pread.c rm -f pread.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mount -t tmpfs tmpfs $mntpoint cp -a /usr/include $mntpoint echo "Testing tmpfs(5)" /tmp/pread $mntpoint umount $mntpoint echo "Testing fdescfs(5)" mount -t fdescfs null /dev/fd for i in `jot 100`; do /tmp/pread /dev/fd done while mount | grep -q "on /dev/fd "; do umount /dev/fd || sleep 1 done echo "Testing procfs(5)" mount -t procfs procfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cp -a /usr/include $mntpoint echo "Testing FFS" /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mount -t nullfs /bin $mntpoint echo "Testing nullfs(5)" /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done echo "Testing procfs(5)" mount -t procfs procfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done echo "Testing devfs(8)" mount -t devfs devfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done rm -f /tmp/pread exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void hand(int i __unused) { /* handler */ _exit(1); } int test(char *path) { FTS *fts; FTSENT *p; int ftsoptions; char *args[2]; int buf[64], fd; signal(SIGSEGV, hand); signal(SIGABRT, hand); ftsoptions = FTS_PHYSICAL; args[0] = path; args[1] = 0; if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { if ((fd = open(p->fts_path, O_RDONLY)) == -1) { if (errno != EACCES && errno != ENXIO) warn("open(%s)", p->fts_path); continue; } alarm(1); pread(fd, (void *)0xdeadc0de, 0x7ffffff, 0xffffffff); pread(fd, buf, 0x7ffffff, 0xffffffff); pread(fd, buf, sizeof(buf), 0xffffffff); pread(fd, buf, sizeof(buf), 0); close(fd); } fts_close(fts); exit(0); } int main(int argc __unused, char **argv) { int i; struct passwd *pw; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if (daemon(0, 0) == -1) err(1, "daemon()"); for (i = 0; i < 10; i++) { if (fork() == 0) test(argv[1]); wait(NULL); } return (0); } Index: user/pho/stress2/misc/procfs3.sh =================================================================== --- user/pho/stress2/misc/procfs3.sh (revision 278500) +++ user/pho/stress2/misc/procfs3.sh (revision 278501) @@ -1,152 +1,152 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # procfs(5) test scenario. # "panic: wchan 0xc10a4f68 has no wmesg" seen [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > procfs3.c -cc -o procfs3 -Wall -Wextra -O2 procfs3.c || exit 1 +mycc -o procfs3 -Wall -Wextra -O2 procfs3.c || exit 1 rm -f procfs3.c cd $here su $testuser -c /tmp/procfs3 rm -f /tmp/procfs3 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 void handler(int i __unused) { } int test(void) { FTS *fts; FTSENT *p; int ftsoptions; char *args[2]; int fd, i; char buf[1629]; ftsoptions = FTS_PHYSICAL; args[0] = "/proc"; args[1] = 0; if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { switch (p->fts_info) { case FTS_F: /* Ignore. */ break; case FTS_D: /* Ignore. */ continue; case FTS_DP: continue; case FTS_DC: /* Ignore. */ continue; case FTS_SL: /* Ignore. */ continue; case FTS_DNR: /* Warn, continue. */ case FTS_ERR: case FTS_NS: case FTS_DEFAULT: warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); break; default: printf("%s: default, %d\n", getprogname(), p->fts_info); break; } if ((fd = open(p->fts_path, O_RDONLY)) == -1) continue; signal(SIGALRM, handler); alarm(1); for (i = 0; i < 2; i++) { read(fd, buf, 1629); } close(fd); } if (errno != 0 && errno != ENOENT) err(1, "fts_read"); if (fts_close(fts) == -1) err(1, "fts_close()"); return (0); } int main(void) { int i, j; for (i = 0; i < PARALLEL; i++) { if (fork() == 0) { for (j = 0; j < 50; j++) { test(); } _exit(0); } } for (i = 0; i < PARALLEL; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/procfs4.sh =================================================================== --- user/pho/stress2/misc/procfs4.sh (revision 278500) +++ user/pho/stress2/misc/procfs4.sh (revision 278501) @@ -1,146 +1,146 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario idea by kib@ # "panic: double fault" seen due to recurtion [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q procfs || mount -t procfs procfs /proc here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > procfs4.c -cc -o procfs4 -Wall -Wextra -O2 procfs4.c +mycc -o procfs4 -Wall -Wextra -O2 procfs4.c rm -f procfs4.c cd $here su $testuser -c /tmp/procfs4 rm -f /tmp/procfs4 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 #define LOOPS 1000 char *files[] = { "cmdline", "ctl", "dbregs", "etype", "file", "fpregs", "map", "mem", "note", "notepg", "osrel", "regs", "rlimit", "status" }; void test(void) { pid_t p; int fd, i, j, n, opens; char path[128]; for (i = 0; i < 64; i++) { if ((p = fork()) == 0) { setproctitle("Sleeper"); usleep(20000); usleep(arc4random() % 200); for (j = 0; j < 10000; j++) getpid(); _exit(0); } opens = 0; setproctitle("load"); for (j = 0; j < 14; j++) { snprintf(path, sizeof(path), "/proc/%d/%s", p, files[j]); if ((fd = open(path, O_RDWR)) == -1) if ((fd = open(path, O_RDONLY)) == -1) continue; ioctl(fd, FIONREAD, &n); if (ioctl(fd, FIONBIO, &n) != -1) opens++; close(fd); } kill(p, SIGHUP); #if 0 if (opens < 1) fprintf(stderr, "Warn %d open(s) for pid %d\n", opens, getpid()); #endif } for (i = 0; i < 64; i++) wait(NULL); _exit(0); } int main(void) { int i, j; for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); usleep(10000); } return (0); } Index: user/pho/stress2/misc/procfs5.sh =================================================================== --- user/pho/stress2/misc/procfs5.sh (revision 278500) +++ user/pho/stress2/misc/procfs5.sh (revision 278501) @@ -1,84 +1,86 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Issue involving signed overflow. # Test scenario based on panic seen in # http://people.freebsd.org/~pho/stress/log/kostik640.txt # Fixed in r258365, r258397. # Scenario by kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + mount | grep -q "/proc " || mount -t procfs procfs /proc here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > procfs_lr.c -cc -o procfs_lr -Wall -Wextra -O2 procfs_lr.c || exit 1 +mycc -o procfs_lr -Wall -Wextra -O2 procfs_lr.c || exit 1 rm -f procfs_lr.c /tmp/procfs_lr 2>/dev/null rm -f /tmp/procfs_lr exit 0 EOF /* $Id: procfs_lr.c,v 1.1 2013/11/16 07:06:46 kostik Exp kostik $ */ #include #include #include #include #include #include #include int main(void) { static const char name[] = "/proc/curproc/map"; const off_t uio_offset = 0x6f51f3a1185bced9; #if defined(__LP64__) const size_t uio_resid = 0x4c330b10965a61af; #else const size_t uio_resid = 0x965a61af; #endif char buf[1]; int error, fd; fd = open(name, O_RDONLY); if (fd == -1) err(1, "open"); error = pread(fd, buf, uio_resid, uio_offset); if (error == -1) fprintf(stderr, "pread: %s\n", strerror(errno)); return (0); } Index: user/pho/stress2/misc/pthread.sh =================================================================== --- user/pho/stress2/misc/pthread.sh (revision 278500) +++ user/pho/stress2/misc/pthread.sh (revision 278501) @@ -1,139 +1,139 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # panic: spin lock held too long # Test program and scenario by Peter Wemm . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > pth.c -cc -o pth -Wall pth.c -pthread +mycc -o pth -Wall pth.c -pthread rm -f pth.c cd $odir for i in `jot 2000`; do /tmp/pth 2>/dev/null done rm -f /tmp/pth exit EOF #include #include #include #include #include #include static pthread_t worker1_thr; static pthread_t worker2_thr; static pthread_mutex_t worker_mtx; static pthread_cond_t worker_go; static pthread_cond_t worker_done; struct workitem { struct workitem *next; int a, b; }; struct workitem *head; static void * worker(void *arg) { struct workitem *w; pthread_detach(pthread_self()); fprintf(stderr, "WORKER: started %p\n", arg); fflush(stderr); for (;;) { pthread_mutex_lock(&worker_mtx); while (head == NULL) { pthread_cond_wait(&worker_go, &worker_mtx); } w = head; head = w->next; pthread_mutex_unlock(&worker_mtx); fprintf(stderr, "WORKER(%p): got work a=%d b=%d\n", arg, w->a, w->b); fflush(stderr); free(w); pthread_cond_signal(&worker_done); } } void work_add(int a, int b) { struct workitem *w; int dowake = 0; w = calloc(sizeof(*w), 1); w->a = a; w->b = b; pthread_mutex_lock(&worker_mtx); if (head == 0) dowake = 1; w->next = head; head = w; pthread_mutex_unlock(&worker_mtx); if (dowake) pthread_cond_signal(&worker_go); } int main() { pthread_mutex_init(&worker_mtx, NULL); pthread_cond_init(&worker_go, NULL); pthread_cond_init(&worker_done, NULL); fprintf(stderr, "pthread create\n"); fflush(stderr); pthread_create(&worker1_thr, NULL, worker, (void *)1); pthread_create(&worker2_thr, NULL, worker, (void *)2); work_add(10, 15); work_add(11, 22); work_add(314, 159); pthread_mutex_lock(&worker_mtx); while (head != NULL) { pthread_cond_wait(&worker_done, &worker_mtx); } pthread_mutex_unlock(&worker_mtx); fprintf(stderr, "job complete\n"); fflush(stderr); exit(0); } Index: user/pho/stress2/misc/pthread2.sh =================================================================== --- user/pho/stress2/misc/pthread2.sh (revision 278500) +++ user/pho/stress2/misc/pthread2.sh (revision 278501) @@ -1,297 +1,299 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Threaded producer-consumer test. +. ../default.cfg + export LANG=C here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pthread2.c -cc -o pthread2 -Wall -Wextra -O2 -g pthread2.c -lpthread || exit 1 +mycc -o pthread2 -Wall -Wextra -O2 -g pthread2.c -lpthread || exit 1 rm -f pthread2.c /tmp/pthread2.core log=/tmp/pthread2.`date '+%Y%m%d-%H%M'` for i in `jot 5`; do [ $i -eq 1 ] && echo "# `uname -v`" time sh -c ' for i in `jot 8`; do /tmp/pthread2 & done for i in `jot 8`; do wait done ' done > $log 2>&1 rm -f /tmp/pthread2 if [ -n "$bench" ]; then pair=`ls /tmp/pthread2* | egrep "pthread2\.[0-9]{8}-" | sort | tail -2 | tr '\n' ' '` ministat -w 72 $pair else rm -f $log fi # __thr_umutex_lock() may call abort(3) under VM pressure. [ -r /tmp/pthread2.core ] && echo FAIL exit 0 EOF /* * Threaded producer-consumer test. * Loosly based on work by * Andrey Zonov (c) 2012 */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #define __NP__ #endif #include #include #include #include #include #include #include #define LOCK(x) plock(&x.mtx) #define UNLOCK(x) punlock(&x.mtx) #define SIGNAL(x) psig(&x.wait) #define WAIT(x) pwait(&x.wait, &x.mtx) long ncreate, nrename, nunlink; int bench, max; char *dirname1; char *dirname2; struct file { char *name; STAILQ_ENTRY(file) next; }; struct files { pthread_mutex_t mtx; pthread_cond_t wait; STAILQ_HEAD(, file) list; }; static struct files newfiles; static struct files renamedfiles; static void hand(int i __unused) { /* handler */ fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", max, ncreate, nrename, nunlink); } static void ahand(int i __unused) { /* handler */ fprintf(stderr, "FAIL\n"); hand(0); _exit(0); } void plock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_lock(l)) != 0) errc(1, rc, "pthread_mutex_lock"); } void punlock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_unlock(l)) != 0) errc(1, rc, "pthread_mutex_unlock"); } void psig(pthread_cond_t *c) { int rc; if ((rc = pthread_cond_signal(c)) != 0) errc(1, rc, "pthread_cond_signal"); } void pwait(pthread_cond_t *c, pthread_mutex_t *l) { int rc; if ((rc = pthread_cond_wait(c, l)) != 0) errc(1, rc, "pthread_cond_wait"); } void * loop_create(void *arg __unused) { int i, j; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for (i = 0; i < max; i++) { file = malloc(sizeof(*file)); asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); LOCK(newfiles); STAILQ_INSERT_TAIL(&newfiles.list, file, next); ncreate++; UNLOCK(newfiles); SIGNAL(newfiles); if ((bench == 0) && (i > 0) && (i % 100000 == 0)) for (j = 0; j < 10 && ncreate != nrename; j++) usleep(400); } return (NULL); } void * loop_rename(void *arg __unused) { char *filename, *newname; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nrename < max) { LOCK(newfiles); while (STAILQ_EMPTY(&newfiles.list)) { WAIT(newfiles); } file = STAILQ_FIRST(&newfiles.list); STAILQ_REMOVE_HEAD(&newfiles.list, next); UNLOCK(newfiles); filename = strrchr(file->name, '/'); asprintf(&newname, "%s/%s", dirname2, filename); nrename++; free(file->name); file->name = newname; LOCK(renamedfiles); STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); UNLOCK(renamedfiles); SIGNAL(renamedfiles); } return (NULL); } void * loop_unlink(void *arg __unused) { struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nunlink < max) { LOCK(renamedfiles); while (STAILQ_EMPTY(&renamedfiles.list)) { WAIT(renamedfiles); } file = STAILQ_FIRST(&renamedfiles.list); STAILQ_REMOVE_HEAD(&renamedfiles.list, next); nunlink++; UNLOCK(renamedfiles); free(file->name); free(file); } return (NULL); } int main(void) { int i; int rc; pthread_t tid[3]; bench = getenv("bench") != NULL; asprintf(&dirname1, "%s.1", "f1"); asprintf(&dirname2, "%s.2", "f2"); max = 15000000; STAILQ_INIT(&newfiles.list); STAILQ_INIT(&renamedfiles.list); if ((rc = pthread_mutex_init(&newfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); signal(SIGINFO, hand); signal(SIGALRM, ahand); alarm(300); if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) errc(1, rc, "pthread_create()"); for (i = 0; i < 3; i++) { if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); } if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(newfiles)"); if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(newfiles)"); if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(renamedfiles)"); free(dirname1); free(dirname2); return (0); } Index: user/pho/stress2/misc/pthread3.sh =================================================================== --- user/pho/stress2/misc/pthread3.sh (revision 278500) +++ user/pho/stress2/misc/pthread3.sh (revision 278501) @@ -1,299 +1,301 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # _exit(2) test scenario with focus on shared channel tear down. +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pthread3.c -cc -o pthread3 -Wall -Wextra -O2 -g -gdwarf-2 pthread3.c -lpthread || exit 1 +mycc -o pthread3 -Wall -Wextra -O2 -g -gdwarf-2 pthread3.c -lpthread || exit 1 rm -f pthread3.c for i in `jot 8`; do /tmp/pthread3 & done for i in `jot 8`; do wait done rm -f /tmp/pthread3 exit 0 EOF /* * Threaded producer-consumer test. * Loosly based on work by * Andrey Zonov (c) 2012 */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #define __NP__ #endif #include #include #include #include #include #include #include #include #define LOCK(x) plock(&x.mtx) #define UNLOCK(x) punlock(&x.mtx) #define SIGNAL(x) psig(&x.wait) #define WAIT(x) pwait(&x.wait, &x.mtx) long ncreate, nrename, nunlink; int max; char *dirname1; char *dirname2; struct file { char *name; STAILQ_ENTRY(file) next; }; struct files { pthread_mutex_t mtx; pthread_cond_t wait; STAILQ_HEAD(, file) list; }; static struct files newfiles; static struct files renamedfiles; static void hand(int i __unused) { /* handler */ fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", max, ncreate, nrename, nunlink); } static void ahand(int i __unused) { /* handler */ fprintf(stderr, "FAIL\n"); hand(0); _exit(0); } void plock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_lock(l)) != 0) errc(1, rc, "pthread_mutex_lock"); } void punlock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_unlock(l)) != 0) errc(1, rc, "pthread_mutex_unlock"); } void psig(pthread_cond_t *c) { int rc; if ((rc = pthread_cond_signal(c)) != 0) errc(1, rc, "pthread_cond_signal"); } void pwait(pthread_cond_t *c, pthread_mutex_t *l) { int rc; if ((rc = pthread_cond_wait(c, l)) != 0) errc(1, rc, "pthread_cond_wait"); } void * loop_create(void *arg __unused) { int i, j; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for (i = 0; i < max; i++) { file = malloc(sizeof(*file)); asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); LOCK(newfiles); STAILQ_INSERT_TAIL(&newfiles.list, file, next); ncreate++; UNLOCK(newfiles); SIGNAL(newfiles); if ((i > 0) && (i % 100000 == 0)) for (j = 0; j < 10 && ncreate != nrename; j++) usleep(400); } return (NULL); } void * loop_rename(void *arg __unused) { char *filename, *newname; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nrename < max) { LOCK(newfiles); while (STAILQ_EMPTY(&newfiles.list)) { WAIT(newfiles); } file = STAILQ_FIRST(&newfiles.list); STAILQ_REMOVE_HEAD(&newfiles.list, next); UNLOCK(newfiles); filename = strrchr(file->name, '/'); asprintf(&newname, "%s/%s", dirname2, filename); nrename++; free(file->name); file->name = newname; LOCK(renamedfiles); STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); UNLOCK(renamedfiles); SIGNAL(renamedfiles); } return (NULL); } void * loop_unlink(void *arg __unused) { struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nunlink < max) { LOCK(renamedfiles); while (STAILQ_EMPTY(&renamedfiles.list)) { WAIT(renamedfiles); } file = STAILQ_FIRST(&renamedfiles.list); STAILQ_REMOVE_HEAD(&renamedfiles.list, next); nunlink++; UNLOCK(renamedfiles); free(file->name); free(file); if (arc4random() % 100 == 1) if (arc4random() % 100 == 1) if (arc4random() % 100 < 10) _exit(0); } return (NULL); } void test(void) { int i; int rc; pthread_t tid[3]; asprintf(&dirname1, "%s.1", "f1"); asprintf(&dirname2, "%s.2", "f2"); max = 15000000; STAILQ_INIT(&newfiles.list); STAILQ_INIT(&renamedfiles.list); if ((rc = pthread_mutex_init(&newfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); signal(SIGINFO, hand); signal(SIGALRM, ahand); alarm(300); if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) errc(1, rc, "pthread_create()"); for (i = 0; i < 3; i++) { if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); } if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(newfiles)"); if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(newfiles)"); if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(renamedfiles)"); free(dirname1); free(dirname2); _exit(0); } int main(void) { int i; for (i = 0; i < 1000; i++) { if (fork() == 0) test(); wait(NULL); } return (0); } Index: user/pho/stress2/misc/pthread4.sh =================================================================== --- user/pho/stress2/misc/pthread4.sh (revision 278500) +++ user/pho/stress2/misc/pthread4.sh (revision 278501) @@ -1,299 +1,301 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP version of pthread2.sh +. ../default.cfg + export LANG=C here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pthread4.c -cc -o pthread4 -Wall -Wextra -O2 -g -gdwarf-2 pthread4.c -lpthread || exit 1 +mycc -o pthread4 -Wall -Wextra -O2 -g -gdwarf-2 pthread4.c -lpthread || exit 1 rm -f pthread4.c /tmp/pthread4.core log=/tmp/pthread4.`date '+%Y%m%d-%H%M'` for i in `jot 5`; do [ $i -eq 1 ] && echo "# `uname -v`" time sh -c ' for i in `jot 8`; do /tmp/pthread4 & done for i in `jot 8`; do wait done ' done > $log 2>&1 rm -f /tmp/pthread4 if [ -n "$bench" ]; then pair=`ls /tmp/pthread4* | egrep "pthread4\.[0-9]{8}-" | sort | tail -2 | tr '\n' ' '` ministat -w 72 $pair else rm -f $log fi exit 0 EOF /* * Threaded producer-consumer test. * Loosly based on work by * Andrey Zonov (c) 2012 */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #define __NP__ #endif #include #include #include #include #include #include #include #define LOCK(x) plock(&x.mtx) #define UNLOCK(x) punlock(&x.mtx) #define SIGNAL(x) psig(&x.wait) #define WAIT(x) pwait(&x.wait, &x.mtx) long ncreate, nrename, nunlink; int bench, max; char *dirname1; char *dirname2; struct file { char *name; STAILQ_ENTRY(file) next; }; struct files { pthread_mutex_t mtx; pthread_cond_t wait; STAILQ_HEAD(, file) list; }; static struct files newfiles; static struct files renamedfiles; static void hand(int i __unused) { /* handler */ fprintf(stderr, "max = %d, ncreate = %ld, nrename = %ld, nunlink = %ld\n", max, ncreate, nrename, nunlink); } static void ahand(int i __unused) { /* handler */ fprintf(stderr, "FAIL\n"); hand(0); _exit(0); } void plock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_lock(l)) != 0) errc(1, rc, "pthread_mutex_lock"); } void punlock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_unlock(l)) != 0) errc(1, rc, "pthread_mutex_unlock"); } void psig(pthread_cond_t *c) { int rc; if ((rc = pthread_cond_signal(c)) != 0) errc(1, rc, "pthread_cond_signal"); } void pwait(pthread_cond_t *c, pthread_mutex_t *l) { int rc; if ((rc = pthread_cond_wait(c, l)) != 0) errc(1, rc, "pthread_cond_wait"); } void * loop_create(void *arg __unused) { int i, j; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for (i = 0; i < max; i++) { file = malloc(sizeof(*file)); asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); LOCK(newfiles); STAILQ_INSERT_TAIL(&newfiles.list, file, next); ncreate++; UNLOCK(newfiles); SIGNAL(newfiles); if ((bench == 0) && (i > 0) && (i % 100000 == 0)) for (j = 0; j < 10 && ncreate != nrename; j++) usleep(400); } return (NULL); } void * loop_rename(void *arg __unused) { char *filename, *newname; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nrename < max) { LOCK(newfiles); while (STAILQ_EMPTY(&newfiles.list)) { WAIT(newfiles); } file = STAILQ_FIRST(&newfiles.list); STAILQ_REMOVE_HEAD(&newfiles.list, next); UNLOCK(newfiles); filename = strrchr(file->name, '/'); asprintf(&newname, "%s/%s", dirname2, filename); nrename++; free(file->name); file->name = newname; LOCK(renamedfiles); STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); UNLOCK(renamedfiles); SIGNAL(renamedfiles); } return (NULL); } void * loop_unlink(void *arg __unused) { struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nunlink < max) { LOCK(renamedfiles); while (STAILQ_EMPTY(&renamedfiles.list)) { WAIT(renamedfiles); } file = STAILQ_FIRST(&renamedfiles.list); STAILQ_REMOVE_HEAD(&renamedfiles.list, next); nunlink++; UNLOCK(renamedfiles); free(file->name); free(file); } return (NULL); } int main(void) { int i; int rc; pthread_t tid[3]; pthread_mutexattr_t attr, *pattr = NULL; bench = getenv("bench") != NULL; asprintf(&dirname1, "%s.1", "f1"); asprintf(&dirname2, "%s.2", "f2"); max = 15000000; STAILQ_INIT(&newfiles.list); STAILQ_INIT(&renamedfiles.list); pthread_mutexattr_init (&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); pattr = &attr; if ((rc = pthread_mutex_init(&newfiles.mtx, pattr)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); signal(SIGINFO, hand); signal(SIGALRM, ahand); alarm(300); if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) errc(1, rc, "pthread_create()"); for (i = 0; i < 3; i++) { if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); } if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(newfiles)"); if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(newfiles)"); if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(renamedfiles)"); free(dirname1); free(dirname2); return (0); } Index: user/pho/stress2/misc/pthread5.sh =================================================================== --- user/pho/stress2/misc/pthread5.sh (revision 278500) +++ user/pho/stress2/misc/pthread5.sh (revision 278501) @@ -1,120 +1,122 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Stress shchan allocations. +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pthread5.c -cc -o pthread5 -Wall -Wextra -O2 pthread5.c -lpthread || exit 1 +mycc -o pthread5 -Wall -Wextra -O2 pthread5.c -lpthread || exit 1 rm -f pthread5.c /tmp/pthread5 rm -f /tmp/pthread5 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define ITER 2 #define PARALLEL 1000 #define THREADS 100 pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void * nicethreads(void *data __unused) { struct timespec ts; struct timeval tp; pthread_mutex_lock(&mutex); gettimeofday(&tp, NULL); ts.tv_sec = tp.tv_sec; ts.tv_nsec = tp.tv_usec * 1000; ts.tv_sec += 30; pthread_cond_timedwait(&cond, &mutex, &ts); pthread_mutex_unlock(&mutex); return (NULL); } int test(void) { int num_thread = THREADS; pthread_t tid[num_thread]; int i, iter, rc; for (iter = 0; iter < ITER; iter++) { for (i = 0; i < num_thread; i++) { if ((rc = pthread_create(&tid[i], NULL, nicethreads, NULL)) == -1) errc(1, rc, "pthread_create"); } usleep(20000); for (i = 0; i < num_thread; i++) { rc = pthread_mutex_lock(&mutex); rc = pthread_cond_signal(&cond); rc = pthread_mutex_unlock(&mutex); } for (i = 0; i < num_thread; i++) if ((rc = pthread_join(tid[i], NULL)) == -1) errc(1, rc, "pthread_join"); } _exit(0); } int main(void) { int i; for (i = 0; i < PARALLEL; i++) if (fork() == 0) test(); for (i = 0; i < PARALLEL; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/pthread6.sh =================================================================== --- user/pho/stress2/misc/pthread6.sh (revision 278500) +++ user/pho/stress2/misc/pthread6.sh (revision 278501) @@ -1,306 +1,308 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: pmap active 0xfffff80128cd84b8" seen: # http://people.freebsd.org/~pho/stress/log/attilio101.txt +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pthread6.c -cc -o pthread6 -Wall -Wextra -O2 -g -gdwarf-2 pthread6.c -lpthread || exit 1 +mycc -o pthread6 -Wall -Wextra -O2 -g -gdwarf-2 pthread6.c -lpthread || exit 1 rm -f pthread6.c /tmp/pthread6.core rm -f /tmp/pthread6.core daemon sh -c "(cd $here/../testcases/swap; ./swap -t 2m -i 20 -k)" sleep `jot -r 1 1 9` for i in `jot 50`; do /tmp/pthread6 done killall -q swap rm -f /tmp/pthread6 /tmp/pthread6.core exit 0 EOF /* * Threaded producer-consumer test. * Loosly based on work by * Andrey Zonov (c) 2012 */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #define __NP__ #endif #include #include #include #include #include #include #include #include #define LOCK(x) plock(&x.mtx) #define UNLOCK(x) punlock(&x.mtx) #define SIGNAL(x) psig(&x.wait) #define WAIT(x) pwait(&x.wait, &x.mtx) #define PARALLEL 4 #define LOOPS 2 long ncreate, nrename, nunlink; int bench, max; char *dirname1; char *dirname2; struct file { char *name; STAILQ_ENTRY(file) next; }; struct files { pthread_mutex_t mtx; pthread_cond_t wait; STAILQ_HEAD(, file) list; }; static struct files newfiles; static struct files renamedfiles; static void hand(int i __unused) { /* handler */ } static void ahand(int i __unused) { /* handler */ abort(); } void plock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_lock(l)) != 0) errc(1, rc, "pthread_mutex_lock"); } void punlock(pthread_mutex_t *l) { int rc; if ((rc = pthread_mutex_unlock(l)) != 0) errc(1, rc, "pthread_mutex_unlock"); } void psig(pthread_cond_t *c) { int rc; if ((rc = pthread_cond_signal(c)) != 0) errc(1, rc, "pthread_cond_signal"); } void pwait(pthread_cond_t *c, pthread_mutex_t *l) { int rc; if ((rc = pthread_cond_wait(c, l)) != 0) errc(1, rc, "pthread_cond_wait"); } void * loop_create(void *arg __unused) { int i, j; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for (i = 0; i < max; i++) { file = malloc(sizeof(*file)); asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); LOCK(newfiles); STAILQ_INSERT_TAIL(&newfiles.list, file, next); ncreate++; UNLOCK(newfiles); SIGNAL(newfiles); if ((bench == 0) && (i > 0) && (i % 100000 == 0)) for (j = 0; j < 10 && ncreate != nrename; j++) usleep(400); } return (NULL); } void * loop_rename(void *arg __unused) { char *filename, *newname; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nrename < max) { LOCK(newfiles); while (STAILQ_EMPTY(&newfiles.list)) { WAIT(newfiles); } file = STAILQ_FIRST(&newfiles.list); STAILQ_REMOVE_HEAD(&newfiles.list, next); UNLOCK(newfiles); filename = strrchr(file->name, '/'); asprintf(&newname, "%s/%s", dirname2, filename); nrename++; free(file->name); file->name = newname; LOCK(renamedfiles); STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); UNLOCK(renamedfiles); SIGNAL(renamedfiles); } return (NULL); } void * loop_unlink(void *arg __unused) { struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif while (nunlink < max) { LOCK(renamedfiles); while (STAILQ_EMPTY(&renamedfiles.list)) { WAIT(renamedfiles); } file = STAILQ_FIRST(&renamedfiles.list); STAILQ_REMOVE_HEAD(&renamedfiles.list, next); nunlink++; UNLOCK(renamedfiles); free(file->name); free(file); } return (NULL); } void test(void) { int i; int rc; pthread_t tid[3]; pthread_mutexattr_t attr, *pattr = NULL; bench = getenv("bench") != NULL; bench = 1; asprintf(&dirname1, "%s.1", "f1"); asprintf(&dirname2, "%s.2", "f2"); max = 15000000; STAILQ_INIT(&newfiles.list); STAILQ_INIT(&renamedfiles.list); pthread_mutexattr_init (&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); pattr = &attr; if ((rc = pthread_mutex_init(&newfiles.mtx, pattr)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&newfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); if ((rc = pthread_mutex_init(&renamedfiles.mtx, NULL)) != 0) errc(1, rc, "pthread_mutex_init()"); if ((rc = pthread_cond_init(&renamedfiles.wait, NULL)) != 0) errc(1, rc, "pthread_cond_init()"); signal(SIGINFO, hand); signal(SIGALRM, ahand); if ((rc = pthread_create(&tid[0], NULL, loop_create, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[1], NULL, loop_rename, NULL)) != 0) errc(1, rc, "pthread_create()"); if ((rc = pthread_create(&tid[2], NULL, loop_unlink, NULL)) != 0) errc(1, rc, "pthread_create()"); usleep(1000); ualarm(arc4random() % 100000, 0); for (i = 0; i < 3; i++) { if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join(%d)", i); } if ((rc = pthread_mutex_destroy(&newfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(newfiles)"); if ((rc = pthread_cond_destroy(&newfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(newfiles)"); if ((rc = pthread_mutex_destroy(&renamedfiles.mtx)) != 0) errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); if ((rc = pthread_cond_destroy(&renamedfiles.wait)) != 0) errc(1, rc, "pthread_cond_destroy(renamedfiles)"); free(dirname1); free(dirname2); _exit(0); } int main(void) { int i, j; for (i = 0; i < LOOPS; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) test(); } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/ptrace.sh =================================================================== --- user/pho/stress2/misc/ptrace.sh (revision 278500) +++ user/pho/stress2/misc/ptrace.sh (revision 278501) @@ -1,106 +1,108 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # wait4(2) / ptrace(2) regression test. +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > ptrace.c -cc -o ptrace -Wall -Wextra -g ptrace.c || exit 1 +mycc -o ptrace -Wall -Wextra -g ptrace.c || exit 1 rm -f ptrace.c cd $here /tmp/ptrace rm -f /tmp/ptrace exit EOF #include #include #include #include #include #include #include #include #include #include #include void test(void) { pid_t pid, rpid; struct rusage ru; int status; if ((pid = fork()) == 0) { usleep(2000); _exit(64); } if (pid == -1) err(1, "fork()"); if (ptrace(PT_ATTACH, pid, NULL, 0) == -1) err(1, "ptrace(%d) attach", pid); if (wait(NULL) == -1) err(1, "wait"); bzero(&ru, sizeof(ru)); usleep(2000); if ((rpid = wait4(-1, &status, WNOHANG, &ru)) == -1) { if (errno == ECHILD) warn("FAIL"); else err(1, "wait4"); } if (rpid == 0) { // fprintf(stderr, "No rusage info.\n"); if (ptrace(PT_DETACH, pid, NULL, 0) == -1) err(1, "ptrace(%d) detach", pid); if (wait(&status) == -1) err(1, "wait"); } else { fprintf(stderr, "FAIL Got unexpected rusage.\n"); if (ru.ru_utime.tv_sec != 0) fprintf(stderr, "FAIL tv_sec\n"); } if (status != 0x4000) fprintf(stderr, "FAIL Child exit status 0x%x\n", status); _exit(0); } int main(void) { test(); return (0); } Index: user/pho/stress2/misc/ptrace2.sh =================================================================== --- user/pho/stress2/misc/ptrace2.sh (revision 278500) +++ user/pho/stress2/misc/ptrace2.sh (revision 278501) @@ -1,143 +1,145 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for kern/142757, race condition in traced process signal # handling. Fixed in r202692. # Test scenario by Tijl Coosemans, tijl@ +. ../default.cfg + cd /tmp cat > race1.c < #include #include #include #include #include int main(void) { pid_t pid; int i, status; alarm(120); /* fork dummy child process */ pid = fork(); if (pid == 0) { /* child does nothing */ for (;;) { sleep(1); } } else { /* parent */ sleep(1); for (i = 0; i < 100000; i++) { /* loop: attach, wait, detach */ printf("attach "); fflush(stdout); ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); printf("wait "); fflush(stdout); wait4(pid, &status, 0, NULL); printf("detach "); fflush(stdout); ptrace(PT_DETACH, pid, (caddr_t) 1, 0); printf("ok\n"); fflush(stdout); } } kill(pid, SIGINT); return (0); } EOF cat > race2.c < #include #include #include #include #include int main(void) { pid_t pid; int i, status; alarm(120); /* fork dummy child process */ pid = fork(); if (pid == 0) { /* child does nothing */ for (;;) { sleep(1); } } else { /* parent */ sleep(1); ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); wait4(pid, &status, 0, NULL); for (i = 0; i < 100000; i++) { /* loop: continue, kill, wait */ printf("continue "); fflush(stdout); ptrace(PT_CONTINUE, pid, (caddr_t) 1, 0); printf("kill "); fflush(stdout); kill(pid, SIGINT); printf("wait "); fflush(stdout); wait4(pid, &status, 0, NULL); printf("ok\n"); fflush(stdout); } } return (0); } EOF -cc -o race1 -Wall -Wextra race1.c -cc -o race2 -Wall -Wextra race2.c +mycc -o race1 -Wall -Wextra race1.c +mycc -o race2 -Wall -Wextra race2.c ./race1 > /dev/null || echo "FAIL #1" ./race2 > /dev/null || echo "FAIL #2" rm -f race1.c race1 race2.c race2 Index: user/pho/stress2/misc/ptrace3.sh =================================================================== --- user/pho/stress2/misc/ptrace3.sh (revision 278500) +++ user/pho/stress2/misc/ptrace3.sh (revision 278501) @@ -1,130 +1,132 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # A regression test for a bug introduced in r269656. # Page fault in proc_realparent+0x70 seen. # Fixed in r270024. # Test scenario by Mark Johnston markj@ +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > ptrace3.c -cc -o ptrace3 -Wall -Wextra -g ptrace3.c || exit 1 +mycc -o ptrace3 -Wall -Wextra -g ptrace3.c || exit 1 rm -f ptrace3.c cd $here /tmp/ptrace3 rm -f /tmp/ptrace3 exit EOF #include #include #include #include #include #include /* * A regression test for a bug introduced in r269656. The test process p creates * child processes c1 and c2 which do nothing but sleep; a third child process * (c3) uses ptrace(2) to reparent c1 and c2 from p to c3. Then c3 detaches from * c1 and c2, causing a crash when c1 and c2 are removed from p's now-corrupt * orphan list. */ pid_t sleeper() { pid_t p; p = fork(); if (p == -1) err(1, "fork"); else if (p == 0) while (1) sleep(1000000); return (p); } void attach(pid_t p) { int status; if (ptrace(PT_ATTACH, p, 0, 0) == -1) err(1, "ptrace"); if (waitpid(p, &status, 0) == -1) err(1, "waitpid"); else if (!WIFSTOPPED(status)) errx(1, "failed to stop child"); } void detach(pid_t p) { if (ptrace(PT_DETACH, p, 0, 0) == -1) err(1, "ptrace"); } int main(void) { int status; pid_t c1, c2, p; c1 = sleeper(); c2 = sleeper(); p = fork(); if (p == -1) { err(1, "fork"); } else if (p == 0) { attach(c1); attach(c2); detach(c1); detach(c2); } else { if (waitpid(p, &status, 0) == -1) err(1, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) errx(1, "child exited abnormally"); } /* Clean up. */ (void)kill(c1, SIGKILL); (void)kill(c2, SIGKILL); return (0); } Index: user/pho/stress2/misc/pts.sh =================================================================== --- user/pho/stress2/misc/pts.sh (revision 278500) +++ user/pho/stress2/misc/pts.sh (revision 278501) @@ -1,140 +1,142 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Page fault in ttydev_open+0x2d seen. Fixed in r237219. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pts.c -cc -o pts -Wall -Wextra -O2 pts.c -lutil +mycc -o pts -Wall -Wextra -O2 pts.c -lutil rm -f pts.c /tmp/pts & while kill -0 $! 2>/dev/null; do $here/../testcases/swap/swap -t 2m -i 20 done wait rm -f /tmp/pts exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void churn(char *path) { FTS *fts; FTSENT *p; int fd, ftsoptions, i; char *args[2]; ftsoptions = FTS_PHYSICAL; args[0] = path; args[1] = 0; setproctitle("churn"); for (i = 0; i < 5000; i++) { if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { if (p->fts_info == FTS_D || p->fts_info == FTS_DP) continue; if ((fd = open(p->fts_path, O_RDONLY)) > 0) close(fd); } if (errno != 0 && errno != ENOENT) err(1, "fts_read"); if (fts_close(fts) == -1) err(1, "fts_close()"); } _exit(0); } void pty(void) { int i, master, slave; char slname[1025]; setproctitle("pty"); for (i = 0; i < 20000; i++) { if (openpty(&master, &slave, slname, NULL, NULL) == -1) err(1, "openpty"); if (close(master) == -1) err(1, "close(master)"); if (close(slave) == -1) err(1, "close(%s)", slname); } _exit(0); } int main(void) { int i, j; for (j = 0; j < 10; j++) { for (i = 0; i < 2; i++) { if (fork() == 0) pty(); } for (i = 0; i < 2; i++) { if (fork() == 0) churn("/dev/pts"); } for (i = 0; i < 4; i++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/rdwr.sh =================================================================== --- user/pho/stress2/misc/rdwr.sh (revision 278500) +++ user/pho/stress2/misc/rdwr.sh (revision 278501) @@ -1,122 +1,122 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test with read/write length of INT_MAX (i386) or INT_MAX+1 (amd64) . ../default.cfg [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > rdwr.c -cc -o rdwr -Wall rdwr.c || exit +mycc -o rdwr -Wall rdwr.c || exit rm -f rdwr.c oldclamp=`sysctl debug.devfs_iosize_max_clamp 2>/dev/null | awk '{print $NF}'` if [ `uname -m` = amd64 ]; then [ "$oldclamp" = "1" ] && sysctl debug.devfs_iosize_max_clamp=0 fi for j in `jot 10`; do /tmp/rdwr || { echo FAIL; break; } done if [ `uname -m` = amd64 ]; then [ "$oldclamp" = "1" ] && sysctl debug.devfs_iosize_max_clamp=1 fi rm -f /tmp/rdwr exit EOF #include #include #include #include #include #include #include int main(int argc, char **argv) { int fd1, fd2; size_t len; void *p; struct iovec iov; alarm(120); if ((fd1 = open("/dev/null", O_RDWR, 0)) == -1) err(1, "open /dev/null"); if ((fd2 = open("/dev/zero", O_RDONLY)) == -1) err(1, "open /dev/zero"); if (sizeof(size_t) == sizeof(int32_t)) len = (size_t)INT_MAX; /* i386 */ else len = (size_t)INT_MAX + 1; /* amd64 */ if ((p = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd2, 0)) == MAP_FAILED) err(1, "mmap"); if (read(fd2, p, len) != len) err(1, "read"); if (write(fd1, p, len) != len) err(1, "write"); if (pread(fd2, p, len, 0) != len) err(1, "pread"); if (pwrite(fd1, p, len, 0) != len) err(1, "pwrite"); iov.iov_base = p; iov.iov_len = len; if (readv(fd2, &iov, 1) != len) err(1, "readv"); if (writev(fd1, &iov, 1) != len) err(1, "writev"); if (preadv(fd2, &iov, 1, 0) != len) err(1, "preadv"); if (pwritev(fd1, &iov, 1, 0) != len) err(1, "pwritev"); close(fd1); close(fd2); return (0); } Index: user/pho/stress2/misc/readdir.sh =================================================================== --- user/pho/stress2/misc/readdir.sh (revision 278500) +++ user/pho/stress2/misc/readdir.sh (revision 278501) @@ -1,175 +1,175 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # readdir(3) fuzzing inspired by the iknowthis test suite # by Tavis Ormandy # "panic: kmem_malloc(1328054272): kmem_map too small" seen [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > readdir.c -cc -o readdir -Wall -Wextra readdir.c +mycc -o readdir -Wall -Wextra readdir.c rm -f readdir.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mount -t tmpfs tmpfs $mntpoint echo "Testing tmpfs(5)" cp -a /usr/include $mntpoint /tmp/readdir $mntpoint umount $mntpoint echo "Testing fdescfs(5)" mount -t fdescfs null /dev/fd /tmp/readdir /dev/fd umount /dev/fd echo "Testing procfs(5)" mount -t procfs procfs $mntpoint /tmp/readdir $mntpoint umount $mntpoint if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then echo "Testing nfs" mount -t nfs -o nfsv3,tcp,nolockd $nfs_export $mntpoint /tmp/readdir $mntpoint umount $mntpoint fi mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cp -a /usr/include $mntpoint echo "Testing UFS" /tmp/readdir $mntpoint umount $mntpoint mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cp -a /usr/include $mntpoint echo "Testing FFS" /tmp/readdir $mntpoint umount $mntpoint mdconfig -d -u $mdstart mount -t nullfs /bin $mntpoint echo "Testing nullfs(5)" /tmp/readdir $mntpoint umount $mntpoint rm -f /tmp/readdir exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include /* copy from /usr/src/lib/libc/gen/gen-private.h */ struct _telldir; /* see telldir.h */ struct pthread_mutex; /* * Structure describing an open directory. * * NOTE. Change structure layout with care, at least dd_fd field has to * remain unchanged to guarantee backward compatibility. */ struct _dirdesc { int dd_fd; /* file descriptor associated with directory */ long dd_loc; /* offset in current buffer */ long dd_size; /* amount of data returned by getdirentries */ char *dd_buf; /* data buffer */ int dd_len; /* size of data buffer */ long dd_seek; /* magic cookie returned by getdirentries */ long dd_rewind; /* magic cookie for rewinding */ int dd_flags; /* flags for readdir */ struct pthread_mutex *dd_lock; /* lock */ struct _telldir *dd_td; /* telldir position recording */ }; /* End copy */ static void hand(int i __unused) { /* handler */ _exit(1); } int test(char *path) { DIR *dirp, fuzz; int i; signal(SIGSEGV, hand); for (i = 0; i < 2000; i++) { if ((dirp = opendir(path)) == NULL) break; bcopy(dirp, &fuzz, sizeof(fuzz)); fuzz.dd_len = arc4random(); readdir(&fuzz); closedir(dirp); } exit(0); } int main(int argc __unused, char **argv) { int i; for (i = 0; i < 1000; i++) { if (fork() == 0) test(argv[1]); wait(NULL); } return (0); } Index: user/pho/stress2/misc/rename.sh =================================================================== --- user/pho/stress2/misc/rename.sh (revision 278500) +++ user/pho/stress2/misc/rename.sh (revision 278501) @@ -1,124 +1,126 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test race between ISDOTDOT lookups and directory removal/rename # With lookup_shared=1 rename() will fail from time to time with ENOENT and # the following stat() will succed. # Test scenario by tegge +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename.c -cc -o rename -Wall rename.c +mycc -o rename -Wall rename.c rm -f rename.c rm -rf /tmp/rename.dir.* for i in `jot 10`; do for j in `jot 10`; do /tmp/rename & done for j in `jot 10`; do wait done done rm -rf /tmp/rename.dir.* /tmp/rename exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define N 30000 static char dir1[128]; static char dir2[128]; int main(int argc, char **argv) { int i, status; struct stat sb; pid_t p; sprintf(dir1, "rename.dir.%d", getpid()); sprintf(dir2, "rename.dir.2.%d", getpid()); if (mkdir(dir1, 0700) == -1) err(1, "mkdir(%s)", dir1); if (chdir(dir1) == -1) err(1, "chdir(%s)", dir1); if ((p = fork()) == -1) err(1, "fork()"); if (p == 0) { if (chdir("..") == -1) err(1, "chdir(%s)", ".."); for (i = 0; i < N; i++) { if (rename(dir1, dir2) == -1) { warn("rename(%s, %s)", dir1, dir2); stat(dir1, &sb); if (stat(dir1, &sb) == -1) err(1, "stat(%s)", dir1); else errx(1, "stat(%s) succeeded!", dir1); } if (rename(dir2, dir1) == -1) { warn("rename(%s, %s)", dir2, dir1); stat(dir2, &sb); if (stat(dir2, &sb) == -1) err(1, "stat(%s)", dir2); else errx(1, "stat(%s) succeeded!", dir2); } } _exit(0); } else { for (i = 0; i < N; i++) { if (stat("..", &sb) == -1) err(1, "stat(..)"); } } if (waitpid(p, &status, 0) == -1) err(1, "waitpid()"); if (chdir("..") == -1) err(1, "chdir(%s)", ".."); if (rmdir(dir1) == -1) err(1, "rmdir(%s)", dir1); return (0); } Index: user/pho/stress2/misc/rename10.sh =================================================================== --- user/pho/stress2/misc/rename10.sh (revision 278500) +++ user/pho/stress2/misc/rename10.sh (revision 278501) @@ -1,181 +1,181 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Regression test for rename(2) problem with missing reference release of # a busy "to" vnode, resulting in a leak. # Fixed in r253998. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename10.c -cc -o rename10 -Wall -Wextra -g -O2 rename10.c || exit 1 +mycc -o rename10 -Wall -Wextra -g -O2 rename10.c || exit 1 rm -f rename10.c cd $here mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 4g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint avail=`df -k $mntpoint | tail -1 | awk '{print $4}'` (cd $mntpoint; /tmp/rename10) for i in `jot 3`; do sync sleep 2 done if [ `df -k $mntpoint | tail -1 | awk '{print $4}'` -lt $avail ]; then echo FAIL ls -ial $mntpoint df -i $mntpoint fi n=0 while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 n=$((n + 1)) [ $n -gt 5 ] && { umount -f $mntpoint; break; } done checkfs /dev/md${mdstart}$part mdconfig -d -u $mdstart exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define PARALLEL 4 #define SIZE (1 * 1024 * 1024) static char *logfile = "logfile"; static char *oldfiles[] = { "logfile.0", "logfile.1", "logfile.2", "logfile.3", "logfile.4" }; void * logger(void) { int fd; char * cp; setproctitle("logger"); cp = calloc(1, SIZE); for(;;) { if ((fd = open(logfile, O_RDWR | O_APPEND)) != -1) { if (write(fd, cp, SIZE) != SIZE) err(1, "write()"); close(fd); } usleep(1); } _exit(0); } void * spin(void) { int fd, i; setproctitle("spin"); for(;;) { for (i = 0; i < 5; i++) { if ((fd = open(oldfiles[i], O_RDWR | O_APPEND)) != -1) close(fd); } usleep(1); } _exit(0); } void renamer() { int fd, i; time_t start; setproctitle("renamer"); start = time(NULL); i = 0; while (time(NULL) - start < 60) { if ((fd = open(logfile, O_RDWR | O_CREAT | O_EXCL, 0644)) == -1) err(1, "creat(%s)", logfile); close(fd); if (rename(logfile, oldfiles[i]) == -1) err(1, "rename(%s, %s)", logfile, oldfiles[i]); i = (i + 1) % 5; } for (i = 0; i < 5; i++) { unlink(oldfiles[i]); } unlink(logfile); } int main() { pid_t pids[PARALLEL], spids[PARALLEL]; int i; for (i = 0; i < PARALLEL; i++) { if ((pids[i] = fork()) == 0) logger(); if ((spids[i] = fork()) == 0) spin(); } renamer(); for (i = 0; i < PARALLEL; i++) { kill(pids[i], SIGINT); kill(spids[i], SIGINT); } for (i = 0; i < PARALLEL * 2; i++) wait(NULL); wait(NULL); return (0); } Index: user/pho/stress2/misc/rename11.sh =================================================================== --- user/pho/stress2/misc/rename11.sh (revision 278500) +++ user/pho/stress2/misc/rename11.sh (revision 278501) @@ -1,139 +1,139 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # SU problem with "mkdir(d.008740.000987): Too many links" seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename11.c -cc -o rename11 -Wall -Wextra rename11.c || exit 1 +mycc -o rename11 -Wall -Wextra rename11.c || exit 1 rm -f rename11.c mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto #newfs md${mdstart}$part > /dev/null # No problems seen without SU newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint mkdir ${mntpoint}/dir ( cd ${mntpoint}/dir /tmp/rename11 || echo FAIL ) while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done checkfs /dev/md${mdstart}$part mdconfig -d -u $mdstart rm -rf /tmp/rename11 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #define LOOPS 10 #define PARALLEL 3 #define ND 5000 void check(char *name) { struct stat sb; if (stat(name, &sb) == -1) warn("stat(%s)", name); else warnx("stat(%s) succeeded!", name); } void dirs(void) { pid_t pid; int i, j; char name[80], to[80]; pid = getpid(); for (j = 0; j < LOOPS; j++) { for (i = 0; i < ND; i++) { snprintf(name, sizeof(name), "d.%06d.%06d", pid, i); if (mkdir(name, 0700) == -1) err(1, "mkdir(%s)", name); snprintf(to , sizeof(to ), "d2.%06d.%06d", pid, i); if (rename(name, to) == -1) warn("rename(%s, %s)", name, to); if (rename(to, name) == -1) warn("rename(%s, %s)", to, name); if (rmdir(name) == -1) { check(name); err(1, "rmdir(%s)", name); } } } _exit(0); } int main(void) { int i, r, s; r = 0; for (i = 0; i < PARALLEL; i++) { if (fork() == 0) dirs(); } for (i = 0; i < PARALLEL; i++) { wait(&s); r += WEXITSTATUS(s); } return (r); } Index: user/pho/stress2/misc/rename12.sh =================================================================== --- user/pho/stress2/misc/rename12.sh (revision 278500) +++ user/pho/stress2/misc/rename12.sh (revision 278501) @@ -1,187 +1,187 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # No problems seen with SU. Panics with SU+J, just like suj30.sh [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename12.c -cc -o rename12 -Wall -Wextra rename12.c || exit 1 +mycc -o rename12 -Wall -Wextra rename12.c || exit 1 rm -f rename12.c mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 4g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint inodes=`df -i $mntpoint | tail -1 | awk '{print $7}'` N=12 for i in `jot 4`; do for j in `jot $N`; do mkdir -p $mntpoint/d$j/dir1 mkdir -p $mntpoint/d$j/dir2 (cd $mntpoint/d$j; /tmp/rename12 $((inodes/N)) ) & done for j in `jot $N`; do wait rmdir $mntpoint/d$j/dir1 rmdir $mntpoint/d$j/dir2 done done while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done checkfs /dev/md${mdstart}$part mdconfig -d -u $mdstart rm -rf /tmp/rename12 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include pid_t crpid; long n; int mvpipe[2], rmpipe[2]; void cr(void) { pid_t pid; int i; char name[80]; setproctitle("cr"); pid = getpid(); usleep(arc4random() & 1000); for (i = 0; i < n; i++) { snprintf(name, sizeof(name), "dir1/d.%06d.%06d", pid, i); if (mkdir(name, 0700) == -1) err(1, "mkdir(%s). %s:%d", name, __FILE__, __LINE__); if (write(mvpipe[1], &i, sizeof(i)) != sizeof(i)) err(1, "write mvpipe"); } _exit(0); } void mv(void) { pid_t pid; int i; char name[80], to[80]; setproctitle("mv"); pid = crpid; i = 0; while (i != n - 1 && read(mvpipe[0], &i, sizeof(i)) == sizeof(i)) { snprintf(name, sizeof(name), "dir1/d.%06d.%06d", pid, i); snprintf(to , sizeof(to ), "dir2/d.%06d.%06d", pid, i); if (rename(name, to) == -1) warn("rename(%s, %s)", name, to); if (write(rmpipe[1], &i, sizeof(i)) != sizeof(i)) err(1, "write rmpipe"); } _exit(0); } void rm(void) { pid_t pid; int i; char to[80]; setproctitle("rm"); pid = crpid; i = 0; while (i != n - 1 && read(rmpipe[0], &i, sizeof(i)) == sizeof(i)) { snprintf(to, sizeof(to ), "dir2/d.%06d.%06d", pid, i); if (rmdir(to) == -1) warn("rmdir(%s)", to); } _exit(0); } int main(int argc, char **argv) { int r, s; if (argc != 2) errx(1, "Usage %s ", argv[0]); n = atol(argv[1]); if (n > 32765) { // fprintf(stderr, "Changing number of dirs from %ld to 32765\n", n); n = 32765 - 1; } if (pipe(mvpipe) == -1) err(1, "pipe()"); if (pipe(rmpipe) == -1) err(1, "pipe()"); r = 0; if ((crpid = fork()) == 0) cr(); if (fork() == 0) mv(); if (fork() == 0) rm(); wait(&s); r += WEXITSTATUS(s); wait(&s); r += WEXITSTATUS(s); wait(&s); r += WEXITSTATUS(s); return (r); } Index: user/pho/stress2/misc/rename2.sh =================================================================== --- user/pho/stress2/misc/rename2.sh (revision 278500) +++ user/pho/stress2/misc/rename2.sh (revision 278501) @@ -1,104 +1,106 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # With lookup_shared=1 rename() will fail from time to time with ENOENT and # the following stat() will succeed. (Variation of rename.sh) +. ../default.cfg + here=`pwd` cd /tmp -sed '1,/^EOF/d' < $here/$0 > rename.c -cc -o rename -Wall rename.c || exit 1 -rm -f rename.c +sed '1,/^EOF/d' < $here/$0 > rename2.c +mycc -o rename2 -Wall rename2.c || exit 1 +rm -f rename2.c cd $here rm -rf /tmp/rename.dir.* for i in `jot 10`; do for j in `jot 10`; do - /tmp/rename & + /tmp/rename2 & done for j in `jot 10`; do wait done done -rm -rf /tmp/rename.dir.* +rm -rf /tmp/rename.dir.* /tmp/rename2 exit 0 EOF #include #include #include #include #include #include #include #include #include static char dir1[128]; static char dir2[128]; -int +int main(int argc, char **argv) { struct stat sb; time_t start; sprintf(dir1, "/tmp/rename.dir.%d", getpid()); sprintf(dir2, "/tmp/rename.dir.2.%d", getpid()); if (mkdir(dir1, 0700) == -1) err(1, "mkdir(%s)", dir1); if (chdir(dir1) == -1) err(1, "chdir(%s)", dir1); if (chdir("..") == -1) err(1, "chdir(%s)", ".."); start = time(NULL); while ((time(NULL) - start) < 120) { if (rename(dir1, dir2) == -1) { warn("rename(%s, %s)", dir1, dir2); if (stat(dir1, &sb) == -1) err(1, "stat(%s)", dir1); else errx(1, "stat(%s) succeeded!", dir1); } if (rename(dir2, dir1) == -1) { warn("rename(%s, %s)", dir2, dir1); if (stat(dir2, &sb) == -1) err(1, "stat(%s)", dir2); else errx(1, "stat(%s) succeeded!", dir2); } } if (rmdir(dir1) == -1) err(1, "rmdir(%s)", dir1); return (0); } Index: user/pho/stress2/misc/rename4.sh =================================================================== --- user/pho/stress2/misc/rename4.sh (revision 278500) +++ user/pho/stress2/misc/rename4.sh (revision 278501) @@ -1,64 +1,64 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # lookup() does not return error when lookup of path ending on "/." is done # for RENAME operation. # Tets scenario by Jim Meyering . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > rename4.c -cc -o rename4 -Wall rename4.c +mycc -o rename4 -Wall rename4.c rm -f rename4.c cd $RUNDIR rm -rf 1 2 mkdir 1 2 /tmp/rename4 1 2/. rm -rf 1 2 /tmp/rename4 exit EOF #include #include int main(int argc, char **argv) { if (rename(argv[1], argv[2]) == -1) err(1, "rename(%s, %s)", argv[1], argv[2]); return (0); } Index: user/pho/stress2/misc/rename5.sh =================================================================== --- user/pho/stress2/misc/rename5.sh (revision 278500) +++ user/pho/stress2/misc/rename5.sh (revision 278501) @@ -1,135 +1,135 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Rename scenario from kern/156545 by Konstantin, # konstantin malov kaspersky com # On 8.2-STABLE fsck reports # "xxx IS AN EXTRANEOUS HARD LINK TO DIRECTORY yyy" # Fixed by r220986 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename5.c -cc -o rename5 -Wall -Wextra -O2 rename5.c +mycc -o rename5 -Wall -Wextra -O2 rename5.c rm -f rename5.c cd $mntpoint /tmp/rename5 cd $here rm -f /tmp/rename5 while mount | grep -q md${mdstart}$part; do umount $mntpoint || sleep 1 done checkfs /dev/md${mdstart}$part mdconfig -d -u $mdstart exit 0 EOF #include #include #include #include #include #include #include #define N 1000 void test(void) { pid_t pid; int i; char from[128], to[128]; pid = getpid(); for (i = 0; i < N; i++) { snprintf(from, sizeof(from), "src/dir.%06d", i); snprintf(to , sizeof(to), "src/dir.%06d.%06d", i, pid); (void)rename(from, to); } _exit(0); } int main() { int fd, i, j; char dir[128], file[128]; for (j = 0; j < 50; j++) { if (mkdir("src", 0700) == -1) err(1, "mkdir(src)"); for (i = 0; i < N; i++) { snprintf(dir, sizeof(dir), "src/dir.%06d", i); if (mkdir(dir, 0700) == -1) err(1, "mkdir(%s)", dir); snprintf(file, sizeof(file), "%s/meta", dir); if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) err(1, "open(%s)", file); close(fd); snprintf(file, sizeof(file), "%s/data", dir); if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) err(1, "open(%s)", file); close(fd); } for (i = 0; i < 2; i++) { if (fork() == 0) test(); } for (i = 0; i < 2; i++) wait(NULL); system("rm -rf src > /dev/null 2>&1"); } return (0); } Index: user/pho/stress2/misc/rename6.sh =================================================================== --- user/pho/stress2/misc/rename6.sh (revision 278500) +++ user/pho/stress2/misc/rename6.sh (revision 278501) @@ -1,148 +1,148 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Demonstrate rename(2) cache problem, where the original name lingers in the VFS cache. # Original test scenario by Anton Yuzhaninov . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename6.c -cc -o rename6 -Wall -Wextra -O2 rename6.c +mycc -o rename6 -Wall -Wextra -O2 rename6.c rm -f rename6.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su ${testuser} -c "cd $mntpoint; /tmp/rename6" while mount | grep -q md${mdstart}$part; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/rename6 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include pid_t spid; const char *logfile = "test.log"; void cleanup() { kill(spid, SIGINT); } static void Stat() { struct stat sb; int i; setproctitle("Stat"); for (;;) { for (i = 0; i < 1000; i++) { stat(logfile, &sb); } usleep(1000); } } int main(void) { struct stat sb1, sb2; int fd, i; char new[128]; if ((spid = fork()) == 0) Stat(); setproctitle("main"); atexit(cleanup); for (i = 0; i < 20000; i++) { sprintf(new, "test.log.%05d", i); if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "creat(%s)", logfile); close(fd); #if 1 if (rename(logfile, new) == -1) warn("rename(%s, %s)", logfile, new); #else /* No cache problem is seen */ if (link(logfile, new) == -1) err(1, "link(%s, %s)", logfile, new); if (unlink(logfile) == -1) err(1, "unlink(%s)", logfile); #endif /* * stat() for logfile and new will be identical sometimes, * but only when Stat() is running. */ if (stat(logfile, &sb1) == 0 && stat(new, &sb2) == 0 && bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { fprintf(stderr, "At loop #%d\n", i); fprintf(stderr, "%-15s: ino = %d, nlink = %d, size = %jd\n", logfile, sb1.st_ino, sb1.st_nlink, sb1.st_blocks); fprintf(stderr, "%-15s: ino = %d, nlink = %d, size = %jd\n", new , sb2.st_ino, sb2.st_nlink, sb2.st_blocks); } unlink(new); } kill(spid, SIGINT); wait(NULL); return (0); } Index: user/pho/stress2/misc/rename7.sh =================================================================== --- user/pho/stress2/misc/rename7.sh (revision 278500) +++ user/pho/stress2/misc/rename7.sh (revision 278501) @@ -1,152 +1,152 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # After a few runs this will happen: # $ umount /mnt # umount: unmount of /mnt failed: Device busy # $ umount -f /mnt # $ . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename7.c -cc -o rename7 -Wall -Wextra -O2 rename7.c || exit +mycc -o rename7 -Wall -Wextra -O2 rename7.c || exit rm -f rename7.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su ${testuser} -c "cd $mntpoint; /tmp/rename7 || echo FAIL" for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break done if mount | grep -q md${mdstart}$part; then echo "Test failed" exit 1 fi rm -d /tmp/rename7 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include const char *logfile = "test.log"; pid_t wpid, spid; void r1(void) { int i; struct stat sb1, sb2; for (i = 0; i < 800000; i++) { rename(logfile, "r1"); if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { fprintf(stderr, "r1 and r2 are identical after rename(%s, \"r1\")\n", logfile); system("ls -ail"); _exit(1); } } _exit(0); } void r2(void) { int i; struct stat sb1, sb2; // _exit(0); /* No problems with only r1 running */ for (i = 0; i < 800000; i++) { rename(logfile, "r2"); if (stat("r1", &sb1) == 0 && stat("r2", &sb2) == 0 && bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { usleep(10000); fprintf(stderr, "r1 and r2 are identical after rename(%s, \"r2\")\n", logfile); system("ls -ail"); _exit(1); } } _exit(0); } int main(void) { pid_t wpid, spid; int e, fd, i, status; if ((wpid = fork()) == 0) r1(); if ((spid = fork()) == 0) r2(); setproctitle("main"); e = 0; for (i = 0; i < 800000; i++) { if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) warn("creat(%s)", logfile); close(fd); } kill(wpid, SIGINT); kill(spid, SIGINT); wait(&status); e += WEXITSTATUS(status); wait(&status); e += WEXITSTATUS(status); return (e); } Index: user/pho/stress2/misc/rename8.sh =================================================================== --- user/pho/stress2/misc/rename8.sh (revision 278500) +++ user/pho/stress2/misc/rename8.sh (revision 278501) @@ -1,174 +1,174 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Cache inconsistency seen on "to" file for rename(2). # Scenario by jhb@ . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename8.c -cc -o rename8 -Wall -Wextra -O2 rename8.c +mycc -o rename8 -Wall -Wextra -O2 rename8.c rm -f rename8.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su ${testuser} -c "cd $mntpoint; mkdir r; /tmp/rename8 r" ls -li $mntpoint/r | egrep -v "^total" for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 1 done if mount | grep -q md${mdstart}$part; then fuser $mntpoint echo "umount $mntpoint failed" exit 1 fi mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart rm -f /tmp/rename8 exit EOF #include #include #include #include #include #include #include #include #include #include static char *always, *file1, *file2; static ino_t always_ino; static void usage(void) { fprintf(stderr, "Usage: rename_race \n"); exit(1); } static void child(void) { struct stat sb; /* Exit as soon as our parent exits. */ while (getppid() != 1) { stat(file1, &sb); } exit(0); } static void create_file(const char *path) { int fd; fd = open(path, O_CREAT, 0666); if (fd < 0) err(1, "open(%s)", path); close(fd); } int main(int ac, char **av) { struct stat sb, sb2; pid_t pid; int i, r; if (ac != 2) usage(); if (stat(av[1], &sb) != 0) err(1, "stat(%s)", av[1]); if (!S_ISDIR(sb.st_mode)) errx(1, "%s not a directory", av[1]); asprintf(&always, "%s/file.always", av[1]); asprintf(&file1, "%s/file1", av[1]); asprintf(&file2, "%s/file2", av[1]); create_file(always); if (stat(always, &sb) != 0) err(1, "stat(%s)", always); always_ino = sb.st_ino; pid = fork(); if (pid < 0) err(1, "fork"); if (pid == 0) child(); r = 0; for (i = 0; i < 100000; i++) { if (unlink(file1) < 0 && errno != ENOENT) err(1, "unlink(%s)", file1); if (link(always, file1) < 0) err(1, "link(%s, %s)", always, file1); create_file(file2); if (stat(file2, &sb2) < 0) err(1, "stat(%s)", file2); if (rename(file2, file1) < 0) err(1, "rename(%s, %s)", file2, file1); if (stat(file1, &sb) < 0) err(1, "stat(%s)", file1); if (sb.st_ino != sb2.st_ino || sb.st_ino == always_ino) { printf("FAIL. Bad stat: always: %d file1: %d (should be %d)\n", always_ino, sb.st_ino, sb2.st_ino); r = EXIT_FAILURE; break; } } kill(pid, SIGINT); wait(NULL); if (r == 0) { unlink(always); unlink(file1); unlink(file2); } return (r); } Index: user/pho/stress2/misc/rename9.sh =================================================================== --- user/pho/stress2/misc/rename9.sh (revision 278500) +++ user/pho/stress2/misc/rename9.sh (revision 278501) @@ -1,164 +1,164 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Variation of rename6.sh. Cache problem of "to" file name seen. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rename9.c -cc -o rename9 -Wall -Wextra -O2 rename9.c +mycc -o rename9 -Wall -Wextra -O2 rename9.c rm -f rename9.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint rm -rf $mntpoint/.snap chmod 777 $mntpoint (while true; do ls -lRi $mntpoint > /dev/null 2>&1; done) & su ${testuser} -c "cd $mntpoint; /tmp/rename9" kill $! > /dev/null 2>&1 wait ls -ilR $mntpoint | egrep -v "^total " while mount | grep -q md${mdstart}$part; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/rename9 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include pid_t spid; char *fromFile = "fromFile.log"; char toFile[128]; void cleanup() { kill(spid, SIGINT); } static void statFrom() { struct stat sb; setproctitle("Stat"); for (;;) { stat(fromFile, &sb); } } int main(void) { struct stat fb, tb, fa, ta; int fd, i; if ((spid = fork()) == 0) statFrom(); setproctitle("main"); atexit(cleanup); for (i = 0;i < 100000; i++) { bzero(&fb, sizeof(fb)); bzero(&tb, sizeof(tb)); bzero(&fa, sizeof(fa)); bzero(&ta, sizeof(ta)); if ((fd = open(fromFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "creat(%s)", fromFile); close(fd); sprintf(toFile, "toFile.log.%05d", i); if ((fd = open(toFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "creat(%s)", toFile); write(fd, "xxx", 3); close(fd); stat(fromFile, &fb); stat(toFile, &tb); if (rename(fromFile, toFile) == -1) warn("rename(%s, %s)", fromFile, toFile); stat(fromFile, &fa); if (stat(toFile, &ta) == -1) err(1, "stat(%s)", toFile); if (tb.st_ino == ta.st_ino) { fprintf(stderr, "FAIL: old and new \"To\" inode number is identical\n"); fprintf(stderr, "stat() before the rename():\n"); fprintf(stderr, "%-16s: ino = %4d, nlink = %d, size = %jd\n", fromFile, fb.st_ino, fb.st_nlink, fb.st_blocks); fprintf(stderr, "%-16s: ino = %4d, nlink = %d, size = %jd\n", toFile, tb.st_ino, tb.st_nlink, tb.st_blocks); fprintf(stderr, "\nstat() after the rename():\n"); if (fa.st_ino != 0) fprintf(stderr, "%-16s: ino = %4d, nlink = %d, size = %jd\n", fromFile, fa.st_ino, fa.st_nlink, fa.st_blocks); fprintf(stderr, "%-16s: ino = %4d, nlink = %d, size = %jd\n", toFile, ta.st_ino, ta.st_nlink, ta.st_blocks); kill(spid, SIGINT); exit(1); } unlink(toFile); } kill(spid, SIGINT); wait(NULL); return (0); } Index: user/pho/stress2/misc/revoke.sh =================================================================== --- user/pho/stress2/misc/revoke.sh (revision 278500) +++ user/pho/stress2/misc/revoke.sh (revision 278501) @@ -1,118 +1,120 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test. Causes panic on 6.1 +. ../default.cfg + odir=`pwd` dir=/tmp cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/revoke.c -cc -o revoke -Wall revoke.c || exit 1 +mycc -o revoke -Wall revoke.c || exit 1 rm -f revoke.c n=100 # Number of times to test for i in `jot $n`; do ./revoke /dev/ttyv9 > /dev/null 2>&1 & ./revoke /dev/ttyva > /dev/null 2>&1 & ./revoke /dev/ttyvb > /dev/null 2>&1 & ./revoke /dev/ttyvc > /dev/null 2>&1 & for j in `jot 4`; do wait done done rm -f revoke exit EOF /* By Martin Blapp, */ #include #include #include #include #include #include #include #include /*#define TTY "/dev/ttyv9"*/ /* should be totally unused */ #define CTTY "/dev/tty" int main(int argc, char **argv) { int ttyfd; pid_t pid; if (argc != 2) { fprintf(stderr, "Usage: %s /dev/ttyv?\n", argv[0]); return 1; } /* Get rid of my ctty. */ printf("Parent starting: pid %d\n", getpid()); pid = fork(); if (pid < 0) { err(1, "fork"); exit(1); } else if (pid > 0) { int status; /* parent */ waitpid(pid, &status, 0); exit(0); } /* child */ printf("Child: pid %d\n", getpid()); if (setsid() < 0) { err(1, "setsid"); exit(1); } ttyfd = open(argv[1], O_RDWR); if (ttyfd < 0) { err(1, "open(%s)", argv[1]); exit(1); } if (ioctl(ttyfd, TIOCSCTTY) < 0) { err(1, "ioctl(TIOCSCTTY)"); exit(1); } if (revoke(argv[1]) < 0) { err(1, "revoke(%s)", argv[1]); exit(1); } if (open(CTTY, O_RDWR) < 0) { err(1, "open(%s)", CTTY); exit(1); } return 0; } Index: user/pho/stress2/misc/rot.sh =================================================================== --- user/pho/stress2/misc/rot.sh (revision 278500) +++ user/pho/stress2/misc/rot.sh (revision 278501) @@ -1,138 +1,138 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Unmapped I/O test scenario: # http://people.freebsd.org/~pho/stress/log/kostik515.txt . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > rot.c -cc -o rot -Wall -Wextra -O2 -g rot.c || exit 1 +mycc -o rot -Wall -Wextra -O2 -g rot.c || exit 1 rm -f rot.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint (cd $mntpoint; /tmp/rot) (cd /tmp; /tmp/rot) while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/rot exit EOF #include #include #include #include #include #include #include #define N 10240 /* 40 Mb */ #define PARALLEL 20 int test(void) { unsigned char *buf; char path[128]; int fd, i, j, s; s = getpagesize(); sprintf(path,"%s.%05d", getprogname(), getpid()); if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "open(%s)", path); if (lseek(fd, s * N - 1, SEEK_SET) == -1) err(1, "lseek error"); /* write a dummy byte at the last location */ if (write(fd, "", 1) != 1) err(1, "write error"); for (i = 0; i < N; i++) { if ((buf = mmap(0, s, PROT_READ | PROT_WRITE, MAP_SHARED, fd, i * s)) == MAP_FAILED) err(1, "write map"); for (j = 0; j < s; j++) buf[j] = i % 256; } if (munmap(buf, s) == -1) err(1, "unmap (write)"); close(fd); if ((fd = open(path, O_RDONLY)) < 0) err(1, "open(%s)", path); for (i = 0; i < N; i++) { if ((buf = mmap(0, s, PROT_READ, MAP_SHARED, fd, i * s)) == MAP_FAILED) err(1, "write map"); for (j = 0; j < s; j++) if (buf[j] != i % 256) fprintf(stderr, "read %d, expected %d at %d\n", buf[j], i % 256, i); } if (munmap(buf, s) == -1) err(1, "unmap (read)"); close(fd); unlink(path); _exit(0); } int main(void) { int i, j; for (j = 0; j < 50; j++) { for (i = 0; i < PARALLEL; i++) if (fork() == 0) test(); for (i = 0; i < PARALLEL; i++) wait(NULL); } return(0); } Index: user/pho/stress2/misc/rwlock_ronly.sh =================================================================== --- user/pho/stress2/misc/rwlock_ronly.sh (revision 278500) +++ user/pho/stress2/misc/rwlock_ronly.sh (revision 278501) @@ -1,82 +1,84 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by kib@ # Demonstrate process looping in kernel mode. # Fixed in r251684. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/rwlock_ronly.c -cc -o rwlock_ronly -Wall -Wextra rwlock_ronly.c || exit 1 +mycc -o rwlock_ronly -Wall -Wextra rwlock_ronly.c || exit 1 rm -f rwlock_ronly.c cd $odir /tmp/rwlock_ronly || echo OK rm -f /tmp/rwlock_ronly exit EOF /* $Id: rwlock_ronly.c,v 1.2 2013/06/10 04:44:08 kostik Exp kostik $ */ #include #include #include #include #include #include int main(void) { char *p; struct urwlock *rw; int error; p = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (p == (char *)MAP_FAILED) err(1, "mmap"); rw = (struct urwlock *)p; rw->rw_state = URWLOCK_READ_WAITERS; error = mprotect(p, getpagesize(), PROT_READ); if (error == -1) err(1, "mprotect"); error = _umtx_op(p, UMTX_OP_RW_RDLOCK, 0, NULL, NULL); if (error != 0) err(1, "rdlock"); return (0); } Index: user/pho/stress2/misc/sem.sh =================================================================== --- user/pho/stress2/misc/sem.sh (revision 278500) +++ user/pho/stress2/misc/sem.sh (revision 278501) @@ -1,148 +1,148 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for panic in semexit_myhook # Test scenario by kib@ . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > sem.c -cc -o sem -Wall sem.c +mycc -o sem -Wall sem.c rm -f sem.c cd $RUNDIR/.. for i in `jot 5`; do /tmp/sem& done for i in `jot 5`; do wait done rm -f /tmp/sem exit EOF #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include int semid = -1; key_t semkey; struct sembuf sop[2]; size_t pgsize; pid_t pid; void random_work(void) { int i, n; n = (arc4random() % 5000) + 200; for (i = 0; i < n; i++) (void) getpid(); } int main() { int i, j, seed, status; seed = getpid(); semkey = ftok("/", seed); for (i = 0; i < 5000; i++) { pid = fork(); if (pid == -1) { perror("fork"); exit(2); } if (pid == 0) { /* child */ j = 0; /* get sem */ do { sched_yield(); semid = semget(semkey, 0, 0); } while (semid == -1 && j++ < 10000); if (semid == -1) exit(1); /* * Attempt to acquire the semaphore. */ sop[0].sem_num = 0; sop[0].sem_op = -1; sop[0].sem_flg = SEM_UNDO; semop(semid, sop, 1); random_work(); _exit(0); } else { /* parent */ /* create sem */ if ((semid = semget(semkey, 1, IPC_CREAT | 010640)) == -1) err(1, "semget (%s:%d)", __FILE__, __LINE__); usleep(2000); sop[0].sem_num = 0; sop[0].sem_op = 1; sop[0].sem_flg = 0; if (semop(semid, sop, 1) == -1) warn("init: semop (%s:%d)", __FILE__, __LINE__); random_work(); if (semctl(semid, 0, IPC_RMID, 0) == -1 && errno != EINVAL) warn("shmctl IPC_RMID (%s:%d)", __FILE__, __LINE__); } waitpid(pid, &status, 0); } return (0); } Index: user/pho/stress2/misc/sendfile.sh =================================================================== --- user/pho/stress2/misc/sendfile.sh (revision 278500) +++ user/pho/stress2/misc/sendfile.sh (revision 278501) @@ -1,215 +1,215 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario for sendfile livelock seen on 7.2-STABLE for non SMP # Scenario by kib@ . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > sendfile.c -cc -o sendfile -Wall sendfile.c -pthread +mycc -o sendfile -Wall sendfile.c -pthread rm -f sendfile.c [ -d "$RUNDIR" ] || mkdir -p $RUNDIR cd $RUNDIR in=/tmp/inputFile out=/tmp/outputFile for i in 1 2 3 4 8 16 1k 2k 3k 4k 5k 1m 2m 3m 4m 5m ; do rm -f $in $out dd if=/dev/random of=$in bs=$i count=1 2>&1 | \ egrep -v "records|transferred" /tmp/sendfile $in $out 12345 cmp $in $out || { echo FAIL; ls -l $in $out; } rm -f $in $out done rm -f /tmp/sendfile exit EOF #include #include #include #include #include #include #include #include #include #include #include #include int port; char *inputFile; char *outputFile; int bufsize = 4096; static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; int n, t, *buf, fd; on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); t = 0; if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", outputFile); for (;;) { if ((n = read(msgsock, buf, bufsize)) < 0) err(1, "read(), %s:%d", __FILE__, __LINE__); t += n; if (n == 0) break; if ((write(fd, buf, n)) != n) err(1, "write"); } close(msgsock); close(fd); return; } static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; struct stat statb; int i, r, fd; off_t off = 0; #if 1 size_t size; #endif on = 1; for (i = 1; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); #if 1 /* livelock trigger */ size = getpagesize() -4; if (setsockopt(tcpsock, SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0) err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__, __LINE__); #endif hostent = gethostbyname ("localhost"); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); if (stat(inputFile, &statb) != 0) err(1, "stat(%s)", inputFile); if ((fd = open(inputFile, O_RDONLY)) == -1) err(1, "open(%s)", inputFile); if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1) err(1, "sendfile"); return; } int main(int argc, char **argv) { pid_t pid; if (argc != 4) { fprintf(stderr, "Usage: %s 0) { reader(); kill(pid, SIGINT); } else err(1, "fork(), %s:%d", __FILE__, __LINE__); return (0); } Index: user/pho/stress2/misc/sendfile2.sh =================================================================== --- user/pho/stress2/misc/sendfile2.sh (revision 278500) +++ user/pho/stress2/misc/sendfile2.sh (revision 278501) @@ -1,144 +1,144 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario for sendfile corruption of read only input file # Scenario by Ming Fu . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > sendfile2.c -cc -o sendfile2 -Wall sendfile2.c +mycc -o sendfile2 -Wall sendfile2.c rm -f sendfile2.c [ -d "$RUNDIR" ] || mkdir -p $RUNDIR cd $RUNDIR dd if=/dev/random of=large bs=1m count=3 2>&1 | egrep -v "records|transferred" md1=`md5 large` nc -l 7000 > lf & sleep 0.1 /tmp/sendfile2 kill $! 2>/dev/null md2=`md5 large` [ "$md1" != "$md2" ] && printf "%s\n%s\n" "$md1" "$md2" rm -f /tmp/sendfile2 large lf exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main () { int s, f; struct sockaddr_in addr; struct hostent *hostent; int flags; char str[32]="\r\n800\r\n"; char *p = str; struct stat sb; int n; fd_set wset; int64_t size; off_t sbytes; off_t sent = 0; int chunk; alarm(120); s = socket(AF_INET, SOCK_STREAM, 0); bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(7000); hostent = gethostbyname ("localhost"); memcpy (&addr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); n = connect(s, (struct sockaddr *)&addr, sizeof (addr)); if (n < 0) warn ("fail to connect"); flags = fcntl(s, F_GETFL); flags |= O_NONBLOCK; fcntl(s, F_SETFL); f = open("large", O_RDONLY); if (f < 0) warn("fail to open file"); n = fstat(f, &sb); if (n < 0) warn("fstat failed"); size = sb.st_size; chunk = 0; while (size > 0) { FD_ZERO(&wset); FD_SET(s, &wset); n = select(f+1, NULL, &wset, NULL, NULL); if (n < 0) continue; if (chunk > 0) { sbytes = 0; n = sendfile(f, s, sent, chunk, NULL, &sbytes, 0); if (n < 0) continue; chunk -= sbytes; size -= sbytes; sent += sbytes; continue; } if (size > 2048) chunk = 2048; else chunk = size; n = sprintf(str, "\r\n%x\r\n", 2048); p = str; write(s, p, n); } return (0); } Index: user/pho/stress2/misc/sendfile3.sh =================================================================== --- user/pho/stress2/misc/sendfile3.sh (revision 278500) +++ user/pho/stress2/misc/sendfile3.sh (revision 278501) @@ -1,215 +1,217 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario for sendfile deadlock (processes stuck in sfbufa) # Variation of sendfile.sh # kern.ipc.nsfbufs should be low for this test +. ../default.cfg + odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > sendfile3.c -cc -o sendfile3 -Wall -Wextra sendfile3.c +mycc -o sendfile3 -Wall -Wextra sendfile3.c rm -f sendfile3.c [ -d "$RUNDIR" ] || mkdir -p $RUNDIR cd $RUNDIR in=/tmp/inputFile out=/tmp/outputFile parallel=20 for i in 50m 100m; do rm -f $in dd if=/dev/random of=$in bs=$i count=1 2>&1 | \ egrep -v "records|transferred" for j in `jot $parallel`; do rm -f ${out}$j /tmp/sendfile3 $in ${out}$j 1234$j & done for j in `jot $parallel`; do wait done for j in `jot $parallel`; do rm -f ${out}$j done done rm -f $in /tmp/sendfile3 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include int port; char *inputFile; char *outputFile; int bufsize = 4096; static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; int n, t, *buf, fd; on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); t = 0; if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", outputFile); for (;;) { if ((n = read(msgsock, buf, bufsize)) < 0) err(1, "read(), %s:%d", __FILE__, __LINE__); t += n; if (n == 0) break; if ((write(fd, buf, n)) != n) err(1, "write"); } close(msgsock); close(fd); return; } static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; struct stat statb; int i, r, fd; off_t off = 0; on = 1; for (i = 0; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); bzero((char *) &inetaddr, sizeof(inetaddr)); hostent = gethostbyname ("localhost"); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); if (stat(inputFile, &statb) != 0) err(1, "stat(%s)", inputFile); if ((fd = open(inputFile, O_RDONLY)) == -1) err(1, "open(%s)", inputFile); if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1) err(1, "sendfile"); } int main(int argc, char **argv) { pid_t pid; if (argc != 4) { fprintf(stderr, "Usage: %s 0) { reader(); kill(pid, SIGINT); waitpid(pid, NULL, 0); } else err(1, "fork(), %s:%d", __FILE__, __LINE__); return (0); } Index: user/pho/stress2/misc/sendfile4.sh =================================================================== --- user/pho/stress2/misc/sendfile4.sh (revision 278500) +++ user/pho/stress2/misc/sendfile4.sh (revision 278501) @@ -1,140 +1,142 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # sendfile(2) test by kib@ # Both processes will sit in the sbwait state forever: +. ../default.cfg + here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sendfile4.c -cc -o sendfile4 -Wall -Wextra -O2 sendfile4.c || exit +mycc -o sendfile4 -Wall -Wextra -O2 sendfile4.c || exit rm -f sendfile4.c cd $here /tmp/sendfile4 /usr/libexec/cc1 || echo FAIL rm -f /tmp/sendfile4 exit EOF #include #include #include #include #include #include #include #include #include #include #include static void handler(int i __unused) { _exit(1); } int main(int argc, char *argv[]) { const char *from_name; char *buf; int sv[2]; struct stat st; off_t written, pos; int child, error, from, status; if (argc != 2) errx(1, "Usage: %s from", argv[0]); from_name = argv[1]; from = open(from_name, O_RDONLY); if (from == -1) err(1, "open read %s", from_name); error = fstat(from, &st); if (error == -1) err(1, "stat %s", from_name); error = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); if (error == -1) err(1, "socketpair"); signal(SIGALRM, handler); alarm(120); child = fork(); if (child == -1) err(1, "fork"); else if (child != 0) { close(sv[1]); pos = 0; for (;;) { error = sendfile(from, sv[0], pos, st.st_size - pos, NULL, &written, 0); if (error == -1) { if (errno != EAGAIN) err(1, "sendfile"); } pos += written; if (pos == st.st_size) break; } close(sv[0]); waitpid(child, &status, 0); } else { close(sv[0]); buf = malloc(st.st_size); if (buf == NULL) err(1, "malloc %jd", st.st_size); pos = 0; for (;;) { written = 413; if (written > st.st_size - pos) written = st.st_size - pos; #if 0 written = st.st_size - pos; if (written > 1000) written = 1000; written = arc4random_uniform(written) + 1; #endif error = read(sv[1], buf + pos, written); if (error == -1) err(1, "read"); else if (error == 0) errx(1, "short read"); pos += error; if (pos == st.st_size) break; } close(sv[1]); _exit(0); } return (0); } Index: user/pho/stress2/misc/sendfile5.sh =================================================================== --- user/pho/stress2/misc/sendfile5.sh (revision 278500) +++ user/pho/stress2/misc/sendfile5.sh (revision 278501) @@ -1,159 +1,159 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # sendfile(2) test by kib@ # Deadlock seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sendfile5.c -cc -o sendfile5 -Wall -Wextra -O2 sendfile5.c +mycc -o sendfile5 -Wall -Wextra -O2 sendfile5.c rm -f sendfile5.c dd if=/dev/zero of=/tmp/big bs=1m count=1k 2>&1 | egrep -v "records|transferred" cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mount -t tmpfs tmpfs $mntpoint echo "Testing tmpfs(5)" cp /tmp/big $mntpoint /tmp/sendfile5 $mntpoint/big umount $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint echo "Testing FFS" cp /tmp/big $mntpoint /tmp/sendfile5 $mntpoint/big umount $mntpoint mount -t nullfs /tmp $mntpoint echo "Testing nullfs(5)" /tmp/sendfile5 $mntpoint/big umount $mntpoint rm -f /tmp/sendfile5 /tmp/big exit EOF #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { const char *from_name; char *buf; int sv[2]; struct stat st; off_t written, pos; int child, error, from, status; if (argc != 2) errx(1, "Usage: %s from", argv[0]); from_name = argv[1]; from = open(from_name, O_RDONLY); if (from == -1) err(1, "open read %s", from_name); error = fstat(from, &st); if (error == -1) err(1, "stat %s", from_name); error = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); if (error == -1) err(1, "socketpair"); child = fork(); if (child == -1) err(1, "fork"); else if (child != 0) { close(sv[1]); pos = 0; for (;;) { error = sendfile(from, sv[0], pos, st.st_size - pos, NULL, &written, 0); if (error == -1) { if (errno != EAGAIN) err(1, "sendfile"); } pos += written; if (pos == st.st_size) break; } close(sv[0]); waitpid(child, &status, 0); } else { close(sv[0]); buf = malloc(st.st_size); if (buf == NULL) err(1, "malloc %jd", st.st_size); pos = 0; for (;;) { written = 413; if (written > st.st_size - pos) written = st.st_size - pos; #if 0 written = st.st_size - pos; if (written > 1000) written = 1000; written = arc4random_uniform(written) + 1; #endif error = read(sv[1], buf + pos, written); if (error == -1) err(1, "read"); else if (error == 0) errx(1, "short read"); pos += error; if (pos == st.st_size) break; } close(sv[1]); _exit(0); } return (0); } Index: user/pho/stress2/misc/sendfile6.sh =================================================================== --- user/pho/stress2/misc/sendfile6.sh (revision 278500) +++ user/pho/stress2/misc/sendfile6.sh (revision 278501) @@ -1,256 +1,256 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by Nate Eldredge neldredge math ucsdnedu # kern/127213: [tmpfs] sendfile on tmpfs data corruption # Variation of tmpfs7.sh where UFS is used instead of tmpfs. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg set -e odir=`pwd` cd /tmp -cat > server.c < sendfile6_server.c < #include #include #include #include "util.h" int main(int argc, char *argv[]) { int f, listener, connection; if (argc < 3) { fprintf(stderr, "Usage: %s filename socketname\n", argv[0]); exit(1); } if ((f = open(argv[1], O_RDONLY)) < 0) { perror(argv[1]); exit(1); } if ((listener = listen_unix_socket(argv[2])) < 0) { exit(1); } if ((connection = accept_unix_socket(listener)) >= 0) { real_sendfile(f, connection); } return 0; } EOF -cat > client.c < sendfile6_client.c < #include #include #include #include "util.h" int main(int argc, char *argv[]) { int s; if (argc < 2) { fprintf(stderr, "Usage: %s socketname\n", argv[0]); exit(1); } if ((s = connect_unix_socket(argv[1])) < 0) { exit(1); } fake_sendfile(s, 1); return 0; } EOF cat > util.c < #include #include #include #include #include #include #include #include #include int create_unix_socket(void) { int fd; if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { perror("socket"); return -1; } return fd; } int make_unix_sockaddr(const char *pathname, struct sockaddr_un *sa) { memset(sa, 0, sizeof(*sa)); sa->sun_family = PF_LOCAL; if (strlen(pathname) + 1 > sizeof(sa->sun_path)) { // fprintf(stderr, "%s: pathname too long (max %lu)\n", // pathname, sizeof(sa->sun_path)); errno = ENAMETOOLONG; return -1; } strcpy(sa->sun_path, pathname); return 0; } static char *sockname; void delete_socket(void) { unlink(sockname); } int listen_unix_socket(const char *path) { int fd; struct sockaddr_un sa; if (make_unix_sockaddr(path, &sa) < 0) return -1; if ((fd = create_unix_socket()) < 0) return -1; if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror("bind"); close(fd); return -1; } sockname = strdup(path); atexit(delete_socket); if (listen(fd, 5) < 0) { perror("listen"); close(fd); return -1; } return fd; } int accept_unix_socket(int fd) { int s; if ((s = accept(fd, NULL, 0)) < 0) { perror("accept"); return -1; } return s; } int connect_unix_socket(const char *path) { int fd; struct sockaddr_un sa; if (make_unix_sockaddr(path, &sa) < 0) return -1; if ((fd = create_unix_socket()) < 0) return -1; if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror("connect"); return -1; } return fd; } #define BUFSIZE 65536 int fake_sendfile(int from, int to) { char buf[BUFSIZE]; int v; int sent = 0; while ((v = read(from, buf, BUFSIZE)) > 0) { int d = 0; while (d < v) { int w = write(to, buf, v - d); if (w <= 0) { perror("write"); return -1; } d += w; sent += w; } } if (v != 0) { perror("read"); return -1; } return sent; } int real_sendfile(int from, int to) { int v; v = sendfile(from, to, 0, 0, NULL, NULL, 0); if (v < 0) { perror("sendfile"); } return v; } EOF cat > util.h < #include #include #include #include #include #include int create_unix_socket(void); int make_unix_sockaddr(const char *pathname, struct sockaddr_un *sa); int listen_unix_socket(const char *path); int accept_unix_socket(int fd); int connect_unix_socket(const char *path); int fake_sendfile(int from, int to); int real_sendfile(int from, int to); EOF -cc -c -Wall -Wextra -O2 util.c -cc -o server -Wall -Wextra -O2 server.c util.o -cc -o client -Wall -Wextra -O2 client.c util.o -rm -f server.c client.c util.c util.o util.h mysocket +mycc -c -Wall -Wextra -O2 util.c +mycc -o sendfile6_server -Wall -Wextra -O2 sendfile6_server.c util.o +mycc -o sendfile6_client -Wall -Wextra -O2 sendfile6_client.c util.o +rm -f sendfile6_server.c sendfile6_client.c util.c util.o util.h mysocket mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint dd if=/dev/random of=$mntpoint/data bs=123456 count=1 > /dev/null 2>&1 -./server $mntpoint/data mysocket & +./sendfile6_server $mntpoint/data mysocket & sleep 0.2 -./client mysocket > data.$$ -cmp $mntpoint/data data.$$ || +./sendfile6_client mysocket > data.$$ +cmp $mntpoint/data data.$$ || { echo "FAIL Data mismatch"; ls -l $mntpoint/data data.$$; } -rm -f data.$$ server client mysocket +rm -f data.$$ sendfile6_server sendfile6_client mysocket while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart Index: user/pho/stress2/misc/sendfile_shm.sh =================================================================== --- user/pho/stress2/misc/sendfile_shm.sh (revision 278500) +++ user/pho/stress2/misc/sendfile_shm.sh (revision 278501) @@ -1,200 +1,202 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Sendfile(2) over posix shmfd # Test scenario by kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + [ -r /boot/kernel/kernel ] || exit 0 here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sendfile_shm.c -cc -o sendfile_shm -Wall -Wextra -O2 sendfile_shm.c || exit 1 +mycc -o sendfile_shm -Wall -Wextra -O2 sendfile_shm.c || exit 1 rm -f sendfile_shm.c cd $here daemon ../testcases/swap/swap -t 2m -i 20 > /dev/null 2>&1 sleep 5 for i in `jot 10`; do /tmp/sendfile_shm /boot/kernel/kernel /tmp/sendfile_shm.$i > \ /dev/null & done for i in `jot 10`; do wait done while pkill -9 swap; do sleep .5 done for i in `jot 10`; do cmp -s /boot/kernel/kernel /tmp/sendfile_shm.$i 2>/dev/null || e=1 rm -f /tmp/sendfile_shm.$i done [ -n "$e" ] && echo FAIL wait rm -f /tmp/sendfile_shm exit EOF /* $Id: sendfile_shm1.c,v 1.2 2013/08/25 14:35:14 kostik Exp kostik $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PAGE_SIZE 4096 static void load(int infd, int shmfd, off_t size) { off_t c, r; char buf[100]; for (c = 0; c < size; c += r) { r = read(infd, buf, sizeof(buf)); if (r == -1) err(1, "read disk"); else if (r == 0) errx(1, "too short"); write(shmfd, buf, r); } } static void sendfd(int s, int shmfd, off_t size) { off_t sbytes; int error; error = sendfile(shmfd, s, 0, size, NULL, &sbytes, 0); if (error == -1) err(1, "sendfile(%d, %d, %jd)", s, shmfd, size); printf("sent %jd bytes, requested %jd\n", (uintmax_t)sbytes, (uintmax_t)size); } static void receivefd(int s, int outfd, off_t size) { char buf[100]; off_t c, r, r1; for (c = 0; c < size; c += r) { r = read(s, buf, sizeof(buf)); if (r == -1) err(1, "read sock"); else if (r == 0) break; else { r1 = write(outfd, buf, r); if (r1 == -1) err(1, "write disk"); else if (r1 != r) { err(1, "short write %jd %jd", (uintmax_t)r, (uintmax_t)r1); } } } printf("received %jd bytes\n", (uintmax_t)c); } int main(int argc, char *argv[]) { struct stat st; struct sigaction sa; pid_t child; int s[2], infd, outfd, shmfd, error; if (argc != 3) { fprintf(stderr, "usage: sendfile_shm infile outfile\n"); exit(2); } memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; error = sigaction(SIGPIPE, &sa, NULL); if (error == -1) err(1, "sigaction SIGPIPE"); infd = open(argv[1], O_RDONLY); if (infd == -1) err(1, "open %s", argv[1]); error = fstat(infd, &st); if (error == -1) err(1, "stat"); outfd = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0666); if (outfd == -1) err(1, "open %s", argv[2]); shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); if (shmfd == -1) err(1, "shm_open"); error = ftruncate(shmfd, st.st_size); if (error == -1) err(1, "ftruncate"); load(infd, shmfd, st.st_size); error = socketpair(AF_UNIX, SOCK_STREAM, 0, s); if (error == -1) err(1, "socketpair"); fflush(stdout); fflush(stderr); child = fork(); if (child == -1) err(1, "fork"); else if (child == 0) { close(s[1]); sendfd(s[0], shmfd, st.st_size); exit(0); } else { close(shmfd); close(s[0]); sleep(1); receivefd(s[1], outfd, st.st_size); } return (0); } Index: user/pho/stress2/misc/setuid.sh =================================================================== --- user/pho/stress2/misc/setuid.sh (revision 278500) +++ user/pho/stress2/misc/setuid.sh (revision 278501) @@ -1,118 +1,118 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for r218019: "panic: oof, we didn't get our fd" [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > setuid.c rm -f /tmp/setuid -cc -o setuid -Wall -Wextra -O2 -g setuid.c -static || exit 1 +mycc -o setuid -Wall -Wextra -O2 -g setuid.c -static || exit 1 rm -f setuid.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint mkdir $mntpoint/root cp /tmp/setuid $mntpoint/root/nop chown nobody:nobody $mntpoint/root/nop chmod 4755 $mntpoint/root/nop chmod 777 $mntpoint/root echo "Expect Abort trap" ./setuid $mntpoint/root 1 ./setuid $mntpoint/root 2 ./setuid $mntpoint/root 3 ./setuid $mntpoint/root 4 ./setuid $mntpoint/root 5 ./setuid $mntpoint/root 6 ./setuid $mntpoint/root 7 while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done rm -f /tmp/setuid /tmp/nop exit EOF #include #include #include #include #include #include int main(int argc, char **argv) { char *av[4]; int fd; if (argc == 1) return (0); if (chroot(argv[1]) != 0) err(1, "chroot(%s)", argv[1]); fd = atoi(argv[2]); if (fd & 1) { fprintf(stderr, "Close fd 0 "); close(0); } if (fd & 2) { fprintf(stderr, "Close fd 1 "); close(1); } if (fd & 4) { fprintf(stderr, "Close fd 2\n"); close(2); } else fprintf(stderr, "\n"); if (chdir("/") != 0) err(1, "chdir"); av[0] = "nop"; av[1] = "nop"; av[3] = 0; if (execve(av[0], av, NULL) == -1) err(1, "execve"); return (0); } Index: user/pho/stress2/misc/shm_open.sh =================================================================== --- user/pho/stress2/misc/shm_open.sh (revision 278500) +++ user/pho/stress2/misc/shm_open.sh (revision 278501) @@ -1,73 +1,75 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: kmem_malloc(4096): kmem_map too small" seen. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/shm_open.c -cc -o shm_open -Wall -Wextra -O2 -g shm_open.c || exit 1 +mycc -o shm_open -Wall -Wextra -O2 -g shm_open.c || exit 1 rm -f shm_open.c cd $odir su $testuser -c /tmp/shm_open rm -f /tmp/shm_open exit EOF #include #include #include #include #include #include int main(void) { int fd, i; off_t len; char name[80]; len = 1024 * 1024; for (i = 0; i < 500000; i++) { sprintf(name, "/testing.%06d", i); if ((fd = shm_open(name, O_RDWR | O_CREAT, 0644)) == -1) err(1, "shm_open()"); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); close(fd); } return(0); } Index: user/pho/stress2/misc/signal.sh =================================================================== --- user/pho/stress2/misc/signal.sh (revision 278500) +++ user/pho/stress2/misc/signal.sh (revision 278501) @@ -1,228 +1,230 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for kern/150138: signal sent to stopped, traced process # not immediately handled on continue. # Fixed in r212047. # Test scenario by Dan McNulty +. ../default.cfg + cat > waitthread.c < #include #include #include #include #include #include #include #include #include #include #include #include struct threadArg { int id; pthread_mutex_t *mutex; }; void *entry(void *arg) { struct threadArg *thisArg = (struct threadArg *)arg; long lwp_id = thisArg->id; if( syscall(SYS_thr_self, &lwp_id) ) { perror("syscall"); } printf("%ld waiting on lock\n", lwp_id); if( pthread_mutex_lock(thisArg->mutex) != 0 ) { perror("pthread_mutex_lock"); return NULL; } printf("%ld obtained lock\n", lwp_id); if( pthread_mutex_unlock(thisArg->mutex) != 0 ) { perror("pthread_mutex_unlock"); return NULL; } printf("%ld released lock\n", lwp_id); return NULL; } int main(int argc, char **argv) { if( 2 != argc ) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } printf("%d\n", getpid()); int numThreads; sscanf(argv[1], "%d", &numThreads); if( numThreads < 1 ) numThreads = 1; pthread_t *threads = (pthread_t *)malloc(sizeof(pthread_t)*numThreads); pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); if( pthread_mutex_init(mutex, NULL) != 0 ) { perror("pthread_mutex_init"); return EXIT_FAILURE; } if( pthread_mutex_lock(mutex) != 0 ) { perror("pthread_mutex_lock"); return EXIT_FAILURE; } int i; for(i = 0; i < numThreads; ++i) { struct threadArg *arg = (struct threadArg *)malloc(sizeof(struct threadArg)); arg->id = i; arg->mutex = mutex; assert( !pthread_create(&threads[i], NULL, &entry, (void *)arg) ); } // Wait on the named pipe unlink("/tmp/waitthread"); if( mkfifo("/tmp/waitthread", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) ) { perror("mkfifo"); return EXIT_FAILURE; } FILE *fifo; do { if( (fifo = fopen("/tmp/waitthread", "r")) == NULL ) { if( errno == EINTR ) continue; perror("fopen"); return EXIT_FAILURE; } break; }while(1); unsigned char byte; if( fread(&byte, sizeof(unsigned char), 1, fifo) != 1 ) { perror("fread"); } fclose(fifo); unlink("/tmp/waitthread"); printf("Received notification\n"); if( pthread_mutex_unlock(mutex) != 0 ) { perror("pthread_mutex_unlock"); return EXIT_FAILURE; } printf("Unlocked mutex, joining\n"); for(i = 0; i < numThreads; ++i ) { assert( !pthread_join(threads[i], NULL) ); } return EXIT_SUCCESS; } EOF cat > tkill.c < #include #include #include #include #include int main(int argc, char *argv[]) { if( argc != 4 ) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } pid_t pid; sscanf(argv[1], "%d", &pid); long id; sscanf(argv[2], "%ld", &id); int sig; sscanf(argv[3], "%d", &sig); if( syscall(SYS_thr_kill2, pid, id, sig) ) { perror("syscall"); } return EXIT_SUCCESS; } EOF -cc -o waitthread -Wall -Wextra waitthread.c -lpthread || exit -cc -o tkill -Wall -Wextra tkill.c || exit +mycc -o waitthread -Wall -Wextra waitthread.c -lpthread || exit +mycc -o tkill -Wall -Wextra tkill.c || exit rm -f waitthread.c tkill.c rm -f gdbfifo gdbout pstat /tmp/waitthread ps | grep -v grep | grep waitthread | awk '{print $1}' | xargs kill mkfifo gdbfifo trap "rm -f gdbfifo" 0 sleep 300 > gdbfifo & # Keep the fifo open fifopid=$! gdb ./waitthread < gdbfifo > gdbout 2>&1 & gdbpid=$! echo "set args 8" > gdbfifo echo "run" > gdbfifo sleep .5 pid=`ps | grep -v grep | grep "waitthread 8" | sed 's/^ *//;s/ .*//'` if [ -n "$pid" ]; then procstat -t $pid > pstat t1=`grep fifo pstat | awk '{print $2}'` t2=`grep umtxn pstat | awk '{print $2}' | tail -1` ./tkill $pid $t1 5 # SIGTRAP ./tkill $pid $t2 2 # SIGINT echo "c" > gdbfifo echo "quit" > gdbfifo sleep 1 grep -q "signal SIGINT" gdbout || echo FAIL else echo "Did not find pid for test program waitthread" fi kill $fifopid $gdbpid > /dev/null 2>&1 rm -f gdbfifo gdbout pstat waitthread tkill /tmp/waitthread ps | grep -v grep | grep waitthread | awk '{print $1}' | xargs kill Index: user/pho/stress2/misc/sigreturn.sh =================================================================== --- user/pho/stress2/misc/sigreturn.sh (revision 278500) +++ user/pho/stress2/misc/sigreturn.sh (revision 278501) @@ -1,116 +1,118 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: smp_tlb_shootdown: interrupts disabled" seen. # http://people.freebsd.org/~pho/stress/log/freebsd4_sigreturn.txt # Fixed in r251033. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/sigreturn.c -cc -o sigreturn -Wall -Wextra sigreturn.c -lpthread || exit 1 +mycc -o sigreturn -Wall -Wextra sigreturn.c -lpthread || exit 1 rm -f sigreturn.c cd $odir /tmp/sigreturn rm -f /tmp/sigreturn ./sigreturn.core exit EOF #include #include #include #include #include #include #include #include #include #include #include unsigned long buf[] = { 0xe8243489, 0x000e7cc9, 0x85204e8b, 0xc0940fc9, 0x0fc2950f, 0x5589d2b6, 0x56bf0fe4, 0xe855890e, 0x890fd285, 0x0000014a, 0x850fc084, 0x00000142, 0x891c468b, 0xd1ff2404, 0x00012ee9, 0x04b3e800, 0x388bffff, 0xe8243489, 0xfffefbd9, 0xff04a4e8, 0xe93889ff, 0x00000343, 0x0fc08566, 0x00031f84, 0x46bf0f00, 0x2404890e, 0x042444c7, 0x00000003, 0xfefb90e8, 0x85c789ff, 0x0d880fff, 0x89000002, 0x03e083f8, 0x7402f883, 0xf04d8b0e, 0x3903e183, 0xe1850fc8, 0xf6000002, 0x74080c46, 0x24348908, 0x0e7c2ce8, 0xf0458b00, 0xf931c189, 0x7408c1f6, 0xf7e7832b, 0x0908e083, 0x4ebf0ff8, 0x2444890e, 0x240c8908, 0x042444c7, 0x00000004, 0xfefb34e8, 0x0fc085ff, 0x0001b388, 0xf0458b00, 0x7404c4f6, 0x46bf0f1f, 0x2404890e, 0x082444c7, 0x00000000, 0x042444c7, 0x00000000, 0xff0898e8, 0xf0458bff, 0x237508a8, 0xc7243489, 0x000c2444, 0xc7000000, 0x00082444, 0xc7000000, 0x00042444, 0xe8000000, 0x000e86ad, 0xa9f0458b, 0x00100000, 0xbf0f1c74, 0x04890e46, 0x2444c724, 0x00000108, 0x2444c700, 0x00000204, 0xfabbe800, 0xbf0ffffe, 0x45c70e7e, 0xffffffe8, 0xe445c7ff, 0x00000000, 0xc76634eb, 0x00200c46, 0xffe845c7 }; static void hand(int i __unused) { /* handler */ _exit(1); } void * calls(void *arg __unused) { alarm(1); syscall(SYS_freebsd4_sigreturn, buf); return (0); } int main(void) { pthread_t cp; signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); if (fork() == 0) { if (pthread_create(&cp, NULL, calls, NULL) != 0) perror("pthread_create"); pthread_join(cp, NULL); _exit(0); } wait(NULL); return (0); } Index: user/pho/stress2/misc/sigstop.sh =================================================================== --- user/pho/stress2/misc/sigstop.sh (revision 278500) +++ user/pho/stress2/misc/sigstop.sh (revision 278501) @@ -1,100 +1,100 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Regression test. # Will display "FAIL exit status = 0" without r240467 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sigstop.c -cc -o sigstop -Wall -Wextra sigstop.c || exit 1 +mycc -o sigstop -Wall -Wextra sigstop.c || exit 1 rm -f sigstop.c cd $here su $testuser -c "/tmp/sigstop" rm -f /tmp/sigstop exit EOF #include #include #include #include #include #include #define PARALLEL 4 void test(void) { pid_t pid; int i, status; for (i = 0; i < 1000; i++) { if ((pid = fork()) == 0) { _exit(64); } if (pid == -1) err(1, "fork()"); if (kill(pid, SIGSTOP) == -1) warn("sigstop"); if (kill(pid, SIGCONT) == -1) warn("sigcont"); wait(&status); if (WEXITSTATUS(status) != 64) { fprintf(stderr, "FAIL exit status = %d\n", WEXITSTATUS(status)); break; } } _exit(0); } int main(void) { int i; for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/sigxcpu.sh =================================================================== --- user/pho/stress2/misc/sigxcpu.sh (revision 278500) +++ user/pho/stress2/misc/sigxcpu.sh (revision 278501) @@ -1,154 +1,154 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # "panic: softdep_deallocate_dependencies: dangling deps" seen: # http://people.freebsd.org/~pho/stress/log/sigxcpu7.txt . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sigxcpu.c -cc -o sigxcpu -Wall -Wextra sigxcpu.c +mycc -o sigxcpu -Wall -Wextra sigxcpu.c rm -f sigxcpu.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 4g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint export runRUNTIME=4m export RUNDIR=$mntpoint/stressX set `df -ik /mnt | tail -1 | awk '{print $4,$7}'` export KBLOCKS=$(($1 / 4)) export INODES=$(($2 / 4)) su $testuser -c 'ulimit -t 3; cd ..; ./run.sh marcus.cfg' > /dev/null & sleep 2 for i in `jot 10`; do /tmp/sigxcpu $mntpoint done kill $! ../tools/killall.sh ../tools/killall.sh while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/sigxcpu exit EOF #include #include #include #include #include #include #include #include #include #include static void hand(int i __unused) { /* handler */ _exit(1); } int test(char *path) { FTS *fts; FTSENT *p; int ftsoptions; char *args[2]; ftsoptions = FTS_PHYSICAL; args[0] = path; args[1] = 0; if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { switch (p->fts_info) { case FTS_F: /* Ignore. */ break; case FTS_D: /* Ignore. */ break; case FTS_DP: break; case FTS_DC: /* Ignore. */ break; case FTS_SL: /* Ignore. */ break; case FTS_DNR: /* Warn, continue. */ case FTS_ERR: case FTS_NS: case FTS_DEFAULT: break; default: printf("%s: default, %d\n", getprogname(), p->fts_info); break; } } if (errno != 0 && errno != ENOENT) err(1, "fts_read"); if (fts_close(fts) == -1) err(1, "fts_close()"); return (0); } int main(int argc, char **argv) { int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); signal(SIGALRM, hand); alarm(20); for (i = 0; i < 100; i++) test(argv[1]); return (0); } Index: user/pho/stress2/misc/snap8.sh =================================================================== --- user/pho/stress2/misc/snap8.sh (revision 278500) +++ user/pho/stress2/misc/snap8.sh (revision 278501) @@ -1,94 +1,94 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Deadlock seen when deleting the snapshots during an "ls" of the FS # Based on test scenario by John Kozubik # kern/94769: [ufs] Multiple file deletions on multi-snapshotted filesystems # causes hang [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q /dev/md${mdstart}$part && umount -f /dev/md${mdstart}$part mdconfig -l | grep -q md${mdstart} && mdconfig -d -u $mdstart parallel=20 size=25 # Gb [ `df -k $(dirname $diskimage) | tail -1 | awk '{print $4'}` -lt $((size * 1024 * 1024)) ] && \ echo "Not enough disk space." && exit 1 truncate -s ${size}G $diskimage mdconfig -a -t vnode -f $diskimage -u $mdstart bsdlabel -w md$mdstart auto newfs -O2 $newfs_flags md${mdstart}${part} > /dev/null mount /dev/md${mdstart}${part} $mntpoint -cc -o /tmp/fstool -Wall ../tools/fstool.c +mycc -o /tmp/fstool -Wall ../tools/fstool.c for i in `jot $parallel`; do (mkdir $mntpoint/test$i; cd $mntpoint/test$i; /tmp/fstool -l -f 50 -n 500 -s 8k) & done for i in `jot $parallel`; do wait done rm -f /tmp/fstool mksnap_ffs $mntpoint $mntpoint/.snap/snap1 mksnap_ffs $mntpoint $mntpoint/.snap/snap2 mksnap_ffs $mntpoint $mntpoint/.snap/snap3 mksnap_ffs $mntpoint $mntpoint/.snap/snap4 mksnap_ffs $mntpoint $mntpoint/.snap/snap5 mksnap_ffs $mntpoint $mntpoint/.snap/snap6 mksnap_ffs $mntpoint $mntpoint/.snap/snap7 mksnap_ffs $mntpoint $mntpoint/.snap/snap8 mksnap_ffs $mntpoint $mntpoint/.snap/snap9 for i in `jot $parallel`; do rm -rf $mntpoint/test$i & done for i in `jot $parallel`; do wait done rm -rf $mntpoint/.snap/snap? & for i in `jot 10`; do ls -lsrt $mntpoint > /dev/null 2>&1 sleep 2 done wait umount /dev/md${mdstart}$part mount | grep -q /dev/md${mdstart}$part && umount -f /dev/md${mdstart}$part mdconfig -l | grep -q md${mdstart} && mdconfig -d -u $mdstart rm -f $diskimage Index: user/pho/stress2/misc/sndstat.sh =================================================================== --- user/pho/stress2/misc/sndstat.sh (revision 278500) +++ user/pho/stress2/misc/sndstat.sh (revision 278501) @@ -1,141 +1,141 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test of access to /dev/sndstat # Permanent "/dev/sndstat: Device busy" seen. # "panic: sbuf_put_byte called with finished or corrupt sbuf" seen. # Fixed in r234932 . ../default.cfg [ -r /dev/sndstat ] || exit 1 here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sndstat.c -cc -o sndstat -Wall -Wextra sndstat.c -lpthread +mycc -o sndstat -Wall -Wextra sndstat.c -lpthread rm -f sndstat.c /tmp/sndstat > /dev/null rm -f /tmp/sndstat exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include int fd; char path[] = "/dev/sndstat"; void * test1(void *arg __unused) { int sfd, i, n; char buf[512]; n = 0; for (i = 0; i < 5; i++) { if ((sfd = open(path, O_RDONLY)) == -1) continue; read(sfd, buf, sizeof(buf)); fprintf(stdout, "%s\n", buf); n++; close(sfd); } if (n == 0) { if ((sfd = open(path, O_RDONLY)) == -1) warn("FAIL open(%s)", path); if (sfd > 0) close(sfd); } return (0); } void * test2(void *arg __unused) { char buf[512]; bzero(buf, sizeof(buf)); if (read(fd, buf, sizeof(buf)) != -1) fprintf(stdout, "%s\n", buf); else warn("read()"); return (0); } int main(void) { pthread_t rp[10]; int i, j; /* Parallel open test */ for (i = 0; i < 10; i++) { if (pthread_create(&rp[i], NULL, test1, NULL) != 0) perror("pthread_create"); } for (i = 0; i < 10; i++) pthread_join(rp[i], NULL); /* Parallel read test */ for (i = 0; i < 10; i++) { if ((fd = open(path, O_RDONLY)) == -1) { warn("open()"); continue; } for (j = 0; j < 4; j++) if (pthread_create(&rp[j], NULL, test2, NULL) != 0) perror("pthread_create"); for (j = 0; j < 4; j++) pthread_join(rp[j], NULL); close(fd); } return (0); } Index: user/pho/stress2/misc/socketpair.sh =================================================================== --- user/pho/stress2/misc/socketpair.sh (revision 278500) +++ user/pho/stress2/misc/socketpair.sh (revision 278501) @@ -1,106 +1,106 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Page fault due to recursion. Fixed in r216150. # Looping in kernel: http://people.freebsd.org/~pho/stress/log/kostik737.txt # Fixed in r274712 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > socketpair.c -cc -o socketpair -Wall -Wextra -O2 socketpair.c +mycc -o socketpair -Wall -Wextra -O2 socketpair.c rm -f socketpair.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR ulimit -b 10485760 /tmp/socketpair cd $here rm -f /tmp/socketpair exit 0 EOF /* From http://lkml.org/lkml/2010/11/25/8 */ #include #include #include #include #include #include #include #include #include #include static int send_fd(int unix_fd, int fd) { struct msghdr msgh; struct cmsghdr *cmsg; char buf[CMSG_SPACE(sizeof(fd))]; memset(&msgh, 0, sizeof(msgh)); memset(buf, 0, sizeof(buf)); msgh.msg_control = buf; msgh.msg_controllen = sizeof(buf); cmsg = CMSG_FIRSTHDR(&msgh); cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; msgh.msg_controllen = cmsg->cmsg_len; memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); return sendmsg(unix_fd, &msgh, 0); } int main() { int fd[2], ff[2]; if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fd) == -1) return 1; for (;;) { if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, ff) == -1) return 2; send_fd(ff[0], fd[0]); send_fd(ff[0], fd[1]); close(fd[1]); close(fd[0]); fd[0] = ff[0]; fd[1] = ff[1]; } } Index: user/pho/stress2/misc/socketpair2.sh =================================================================== --- user/pho/stress2/misc/socketpair2.sh (revision 278500) +++ user/pho/stress2/misc/socketpair2.sh (revision 278501) @@ -1,275 +1,275 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Default unix domain socket limits causes hang: # 1001 880 871 0 52 0 5780 1524 keglimit D+ 0 0:00.35 /tmp/socketpair2 # Test scenario by peter@ # Fixed in r269489. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > socketpair2.c -cc -o socketpair2 -Wall -Wextra -O2 socketpair2.c || exit +mycc -o socketpair2 -Wall -Wextra -O2 socketpair2.c || exit rm -f socketpair2.c /tmp/socketpair2 > /dev/null 2>&1 rm -f /tmp/socketpair2 exit 0 EOF /* Peter Wemm Some systems seem to base how much can be written to the pipe based on the size of the socket receive buffer (read-side), while others on the size of the socket send buffer (send-side). This little hack tries to make an educated guess as to what is the case on this particular system. */ #include #include #include #include #include #include #include #include #ifndef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif /* !MIN */ #ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif /* !MAX */ #if NEED_AF_LOCAL #define AF_LOCAL AF_UNIX #endif /* NEED_AF_LOCAL */ #define PACKETSIZE (1024) #define SEND_PIPE (0) #define RECV_PIPE (1) #define EXIT_SENDSIDE (1) #define EXIT_READSIDE (0) /* looking for readside - exit 0 */ #define EXIT_UNKNOWN (1) static void setsockets(const int doreverse, const size_t packetsize, const int s, const int r, size_t *sndbuf, size_t *sndbuf_set, size_t *rcvbuf, size_t *rcvbuf_set); static size_t sendtest(const int s, const char *buf, const size_t buflen); int main(void) { size_t sent, packetcount, sndbuf, sndbuf_set, rcvbuf, rcvbuf_set; char buf[PACKETSIZE - 64]; /* allow for some padding between messages. */ int datapipev[2]; if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, datapipev) != 0) { perror("socketpair()"); exit(EXIT_UNKNOWN); } setsockets(0, PACKETSIZE, datapipev[SEND_PIPE], datapipev[RECV_PIPE], &sndbuf, &sndbuf_set, &rcvbuf, &rcvbuf_set); packetcount = MIN(sndbuf, sndbuf_set) / PACKETSIZE; fprintf(stderr, "Requested sndbuf to be %ld, is %ld. " "Requested rcvbuf to be %ld, is %ld.\n" "Calculated packetcount is %lu\n", (long)sndbuf, (long)sndbuf_set, (long)rcvbuf, (long)rcvbuf_set, (unsigned long)packetcount); sent = sendtest(datapipev[SEND_PIPE], buf, sizeof(buf)); if (sent >= (size_t)sndbuf) { fprintf(stderr, "status determined by send-side\n"); return EXIT_SENDSIDE; } /* * Try the reverse. Perhaps this system wants a large rcvbuf rather than * a large sndbuf. */ close(datapipev[SEND_PIPE]); close(datapipev[RECV_PIPE]); if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, datapipev) != 0) { perror("socketpair()"); exit(EXIT_UNKNOWN); } setsockets(1, PACKETSIZE, datapipev[SEND_PIPE], datapipev[RECV_PIPE], &sndbuf, &sndbuf_set, &rcvbuf, &rcvbuf_set); packetcount = MIN(rcvbuf, rcvbuf_set) / PACKETSIZE; fprintf(stderr, "Requested sndbuf to be %ld, is %ld. " "Requested rcvbuf to be %ld, is %ld.\n" "Calculated packetcount is %lu\n", (long)sndbuf, (long)sndbuf_set, (long)rcvbuf, (long)rcvbuf_set, (unsigned long)packetcount); sent = sendtest(datapipev[SEND_PIPE], buf, sizeof(buf)); if (sent >= (size_t)rcvbuf) { fprintf(stderr, "status determined by read-side\n"); return EXIT_READSIDE; } fprintf(stderr, "status is unknown\n"); return EXIT_UNKNOWN; } static void setsockets(doreverse, packetsize, s, r, sndbuf, sndbuf_set, rcvbuf, rcvbuf_set) const int doreverse; const size_t packetsize; const int s; const int r; size_t *sndbuf, *sndbuf_set; size_t *rcvbuf, *rcvbuf_set; { socklen_t len; int p; if ((p = fcntl(s, F_GETFL, 0)) == -1 || fcntl(s, F_SETFL, p | O_NONBLOCK) == -1 || fcntl(r, F_SETFL, p | O_NONBLOCK) == -1) { perror("fcntl(F_SETFL/F_GETFL, O_NONBLOCK) failed"); exit(EXIT_UNKNOWN); } len = sizeof(*sndbuf_set); if (doreverse) { *sndbuf = packetsize; if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, sndbuf, sizeof(*sndbuf)) != 0) { perror("setsockopt(SO_SNDBUF)"); exit(EXIT_UNKNOWN); } if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, sndbuf_set, &len) != 0) { perror("getsockopt(SO_SNDBUF)"); exit(EXIT_UNKNOWN); } *rcvbuf = *sndbuf_set * 10; if (setsockopt(r, SOL_SOCKET, SO_RCVBUF, rcvbuf, sizeof(*rcvbuf)) != 0) { perror("setsockopt(SO_RCVBUF)"); exit(EXIT_UNKNOWN); } } else { *rcvbuf = packetsize; if (setsockopt(r, SOL_SOCKET, SO_RCVBUF, rcvbuf, sizeof(*rcvbuf)) != 0) { perror("setsockopt(SO_RCVBUF)"); exit(EXIT_UNKNOWN); } if (getsockopt(r, SOL_SOCKET, SO_RCVBUF, rcvbuf_set, &len) != 0) { perror("getsockopt(SO_RCVBUF)"); exit(EXIT_UNKNOWN); } *sndbuf = *rcvbuf_set * 10; if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, sndbuf, sizeof(*sndbuf)) != 0) { perror("setsockopt(SO_SNDBUF)"); exit(EXIT_UNKNOWN); } } if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, sndbuf_set, &len) != 0 || getsockopt(r, SOL_SOCKET, SO_RCVBUF, rcvbuf_set, &len) != 0) { perror("getsockopt(SO_SNDBUF/SO_RCVBUF)"); exit(EXIT_UNKNOWN); } fprintf(stderr, "sndbuf is %lu, rcvbuf is %lu\n", (unsigned long)*sndbuf_set, (unsigned long)*rcvbuf_set); if (doreverse) { if (*rcvbuf_set < *rcvbuf) { fprintf(stderr, "failed to set rcvbuf to %lu. Is %lu\n", (unsigned long)*rcvbuf, (unsigned long)*rcvbuf_set); exit(EXIT_UNKNOWN); } } else { if (*sndbuf_set < *sndbuf) { fprintf(stderr, "failed to set sndbuf to %lu (is %lu)\n", (unsigned long)*sndbuf, (unsigned long)*sndbuf_set); exit(EXIT_UNKNOWN); } } } static size_t sendtest(s, buf, buflen) const int s; const char *buf; const size_t buflen; { ssize_t rc; int i; i = 1; errno = 0; while (errno == 0) { if ((rc = sendto(s, buf, buflen, 0, NULL, 0)) != (ssize_t)buflen) fprintf(stderr, "sendto(2) failed on iteration %d, sent %ld/%lu. " "Total bytes sent: %lu. Error on last packet: %s\n", i, (long)rc, (unsigned long)buflen, (unsigned long)(i * buflen + MAX(rc, 0)), strerror(errno)); else ++i; } return (size_t)(i * buflen + MAX(rc, 0)); } Index: user/pho/stress2/misc/spin.sh =================================================================== --- user/pho/stress2/misc/spin.sh (revision 278500) +++ user/pho/stress2/misc/spin.sh (revision 278501) @@ -1,129 +1,129 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Demonstrate starvation: Thread stuck in "ufs" for minutes. # Only seen with >= 16 CPUs. # Not a problem with 4BSD. # http://people.freebsd.org/~pho/stress/log/spin.txt # Fixed by r273966. mntpoint=/mnt mdstart=5 part=a timeout=1200 [ -r ../default.cfg ] && . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > spin.c -cc -o spin -Wall -Wextra -O0 spin.c || exit 1 +mycc -o spin -Wall -Wextra -O0 spin.c || exit 1 rm -f spin.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags -n md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cpus=`sysctl hw.ncpu | sed 's/.*: //'` (cd $mntpoint; /tmp/spin $((cpus + 1))) & error=0 n=0 while kill -0 $! 2>/dev/null; do sleep 1 n=$((n + 1)) if [ $n -gt $timeout ]; then echo FAIL ps -l | grep -v sed | sed -n '1p;/ufs/p' pkill spin error=1 fi done wait while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/spin exit $error EOF #include #include #include #include #include #include #include void work(void) { while (access("rendezvous", R_OK) != 0) ; _exit(0); } int main(int argc, char **argv) { int fd, i, parallel; if (argc == 2) parallel = atoi(argv[1]); else errx(1, "Usage: %s ", argv[0]); for (i = 0; i < parallel; i++) { if (fork() == 0) work(); } /* open(2) blocked on "ufs" for minutes */ if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < parallel; i++) wait(NULL); if (unlink("rendezvous") == -1) err(1, "unlink()"); return (0); } Index: user/pho/stress2/misc/statfs.sh =================================================================== --- user/pho/stress2/misc/statfs.sh (revision 278500) +++ user/pho/stress2/misc/statfs.sh (revision 278501) @@ -1,128 +1,130 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for statfs problems with deleting a large number of files # $ ./statfs.sh # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on # /dev/ad0s1e 1982798 1782134 42042 98% 4965 254105 2% /tmp # Free inodes on /tmp: 254105 # Creating 100000 files... # Deleting 100000 files... # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on # /dev/ad0s1e 1982798 -284096 2108272 -16% 4965 254105 2% /tmp # $ umount -f /tmp; mount /tmp # $ df -i /tmp # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on # /dev/ad0s1e 1982798 1784528 39648 98% 4965 254105 2% /tmp +. ../default.cfg + odir=`pwd` dir=/tmp cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/statfs.c -cc -o statfs -Wall statfs.c +mycc -o statfs -Wall statfs.c rm -f statfs.c df -i /tmp ./statfs df -i /tmp exit EOF /* $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include int64_t inodes(void) { char path[MAXPATHLEN+1]; struct statfs buf; sync(); if (getcwd(path, sizeof(path)) == NULL) err(1, "getcwd()"); if (statfs(path, &buf) < 0) err(1, "statfs(%s)", path); printf("Free inodes on %s: %jd\n", path, buf.f_ffree); return (buf.f_ffree); } int main() { int fd, i, j; int64_t size; pid_t pid; char file[128]; size = inodes() - 1000; if (size > 100000) size = 100000; printf("Creating %jd files...", size); fflush(stdout); pid = getpid(); for (j = 0; j < size; j++) { sprintf(file,"p%06d.%05d", pid, j); if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) { if (errno != EINTR) { warn("creat(%s)", file); printf("break out at %d, errno %d\n", j, errno); break; } } if (fd != -1 && close(fd) == -1) err(2, "close(%d)", j); } printf("\nDeleting %jd files...", size); fflush(stdout); for (i = --j; i >= 0; i--) { sprintf(file,"p%06d.%05d", pid, i); if (unlink(file) == -1) err(3, "unlink(%s)", file); } printf("\n"); return (0); } Index: user/pho/stress2/misc/stealer.sh =================================================================== --- user/pho/stress2/misc/stealer.sh (revision 278500) +++ user/pho/stress2/misc/stealer.sh (revision 278501) @@ -1,133 +1,133 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Process stuck in objtrm wait state # http://people.freebsd.org/~pho/stress/log/stealer.txt # Fixed in r263328. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > stealer.c -cc -o stealer -Wall -Wextra stealer.c || exit 1 +mycc -o stealer -Wall -Wextra stealer.c || exit 1 rm -f stealer.c cd $here swapoff -a > /dev/null dd if=/dev/zero of=$diskimage bs=1m count=1k 2>&1 | egrep -v 'records|transferred' mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t vnode -f $diskimage -u $mdstart swapon /dev/md$mdstart hw=`sysctl hw.pagesize | sed 's/.*: //'` pages=`sysctl hw.usermem | sed 's/.*: //'` pages=$((pages / hw)) echo "`date '+%T'` Test with $pages pages." su $testuser -c "sh -c \"/tmp/stealer $pages\"" & sleep 30 while swapinfo | grep -q /dev; do swapoff /dev/md$mdstart 2>&1 | grep -v "Cannot allocate memory" sleep 2 done ps auxwwl | grep -v grep | grep objtrm && echo FAIL wait swapon -a > /dev/null mdconfig -d -u $mdstart rm -rf /tmp/stealer $diskimage exit 0 EOF #include #include #include #include #include #include #define N 200 void handler(int i __unused) { _exit(0); } void stealer(int pages) { char *c; int i, page, size; page = getpagesize(); size = pages * page; if ((c = malloc(size)) == 0) err(1, "malloc(%d pages)", pages); signal(SIGALRM, handler); alarm(3 * 60); for (;;) { i = 0; while (i < size) { c[i] = 0; i += page; } } } int main(int argc __unused, char **argv) { int i, j, n, pages, status; pages = atoi(argv[1]); n = pages / N; j = 0; for ( i = 0; i < N; i++, j++) { if (fork() == 0) stealer(n); pages = pages - n; } if (pages > 0) { j++; if (fork() == 0) stealer(pages); } while (j-- > 0) if (wait(&status) == -1) err(1, "wait()"); return (0); } Index: user/pho/stress2/misc/suj10.sh =================================================================== --- user/pho/stress2/misc/suj10.sh (revision 278500) +++ user/pho/stress2/misc/suj10.sh (revision 278501) @@ -1,184 +1,184 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/suj.sh 210724 2010-08-01 10:33:03Z pho $ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Page fault in softdep_revert_mkdir+0x4d seen and # fsck updates "clean" FS: # *** /tmp/dumpfs.1 2010-12-24 19:18:44.000000000 +0100 # --- /tmp/dumpfs.2 2010-12-24 19:18:46.000000000 +0100 # *************** # *** 5,11 **** # frag 8 shift 3 fsbtodb 2 # minfree 8% optim time symlinklen 120 # maxbsize 16384 maxbpg 2048 maxcontig 8 contigsumsize 8 # ! nbfree 62794 ndir 2 nifree 141307 nffree 25 # bpg 11761 fpg 94088 ipg 23552 unrefs 0 # nindir 2048 inopb 64 maxfilesize 140806241583103 # sbsize 2048 cgsize 16384 csaddr 3000 cssize 2048 # --- 5,11 ---- # frag 8 shift 3 fsbtodb 2 # minfree 8% optim time symlinklen 120 # maxbsize 16384 maxbpg 2048 maxcontig 8 contigsumsize 8 # ! nbfree 62794 ndir 30 nifree 141307 nffree 25 # bpg 11761 fpg 94088 ipg 23552 unrefs 0 # nindir 2048 inopb 64 maxfilesize 140806241583103 # sbsize 2048 cgsize 16384 csaddr 3000 cssize 2048 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj10.c -cc -o suj10 -Wall -O2 suj10.c +mycc -o suj10 -Wall -O2 suj10.c rm -f suj10.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su ${testuser} -c "cd $mntpoint; /tmp/suj10" while mount | grep "$mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done dumpfs /dev/md${mdstart}$part | grep -v UFS2 > /tmp/dumpfs.1 sleep 1 fsck -t ufs -y -v /dev/md${mdstart}$part > /tmp/fsck.log 2>&1 dumpfs /dev/md${mdstart}$part | grep -v UFS2 > /tmp/dumpfs.2 diff -c /tmp/dumpfs.1 /tmp/dumpfs.2 || cat /tmp/fsck.log mdconfig -d -u $mdstart rm -f /tmp/fsck.log /tmp/dumpfs.? exit EOF #include #include #include #include #include #include #include #include #include #include #include #define PARALLEL 10 /* static int size = 14100; Causes: Fatal trap 12: page fault while in kernel mode Stopped at softdep_revert_mkdir+0x4d: movl 0x28(%ebx),%eax */ //static int size = 14000; static int size = 13000; void test(void) { int fd, i, j; pid_t pid; char file[128]; for (;;) { if (access("rendezvous", R_OK) == 0) break; sched_yield(); } pid = getpid(); sprintf(file,"d%05d", pid); if (mkdir(file, 0740) == -1) err(1, "mkdir(%s)", file); chdir(file); for (j = 0; j < size; j++) { sprintf(file,"p%05d.%05d", pid, j); if ((fd = mkdir(file, 0740)) == -1) { if (errno != EINTR) { warn("mkdir(%s). %s:%d", file, __FILE__, __LINE__); unlink("continue"); break; } } } sleep(3); for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (rmdir(file) == -1) err(3, "unlink(%s)", file); } chdir(".."); sprintf(file,"d%05d", pid); if (rmdir(file) == -1) err(3, "unlink(%s)", file); } int main(void) { int fd, i, j; umask(0); if ((fd = open("continue", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < 1; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) { test(); exit(0); } } if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (j = 0; j < PARALLEL; j++) wait(NULL); unlink("rendezvous"); if (access("continue", R_OK) == -1) { fprintf(stderr, "Loop #%d\n", i + 1); fflush(stderr); break; } } unlink("continue"); return (0); } Index: user/pho/stress2/misc/suj17.sh =================================================================== --- user/pho/stress2/misc/suj17.sh (revision 278500) +++ user/pho/stress2/misc/suj17.sh (revision 278501) @@ -1,137 +1,137 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Truncate scenario for suj. # "panic: worklist_insert: 0xc8bc5b00 freework(0x8009) already on list" # seen. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj17.c -cc -o suj17 -Wall -Wextra -O2 suj17.c +mycc -o suj17 -Wall -Wextra -O2 suj17.c rm -f suj17.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto [ $# -eq 1 ] && opt="$1" [ $# -eq 0 ] && opt="-j" echo "newfs $opt md${mdstart}$part" newfs $opt md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "cd $mntpoint; /tmp/suj17" while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done checkfs /dev/md${mdstart}$part mdconfig -d -u $mdstart rm -f /tmp/suj17 exit EOF #include #include #include #include #include #include #include #define SIZ (1024 * 1024 - 1) char buf[SIZ]; void test() { int fd, i; char name[128]; off_t len = 104857600LL; /* 100 Mb */ off_t pos; sprintf(name, "%06d", getpid()); if ((fd = open(name, O_WRONLY | O_CREAT, 0666)) == -1) err(1, "open(%s)", name); for (i = 0; i < 100; i++) { if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write"); } for (;;) { if (access("rendezvous", R_OK) == 0) break; sched_yield(); } srand48(getpid()); for (i = 0; i < 50000; i++) { pos = lrand48() % (len - sizeof(buf)); if (ftruncate(fd, pos) == -1) err(1, "ftruncate"); pos = lrand48() % (len - sizeof(buf)); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write"); } close(fd); unlink(name); _exit(0); } int main() { int fd, i, j, status; for (i = 0; i < 1; i++) { for (j = 0; j < 6; j++) { if (fork() == 0) test(); } if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (j = 0; j < 6; j++) wait(&status); unlink("rendezvous"); } return (0); } Index: user/pho/stress2/misc/suj2.sh =================================================================== --- user/pho/stress2/misc/suj2.sh (revision 278500) +++ user/pho/stress2/misc/suj2.sh (revision 278501) @@ -1,80 +1,80 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/rename4.sh 199143 2009-11-10 16:51:15Z pho $ # # Page fault on SUJ enabled FS # Fix: http://docs.freebsd.org/cgi/mid.cgi?20100823211257.GI2396 # Tets scenario by Mateusz Guzik mjguzik gmail com [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > suj2.c -cc -o suj2 -Wall -Wextra -O2 suj2.c +mycc -o suj2 -Wall -Wextra -O2 suj2.c rm -f suj2.c mount | grep "$mntpoint" | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint rm -rf foo bar /tmp/suj2 cd / while mount | grep "$mntpoint" | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -rf foo bar /tmp/suj2 exit EOF #include #include int main(void) { mkdir("foo", 00700); mkdir("bar", 00700); rename("foo", "bar"); return (0); } Index: user/pho/stress2/misc/suj20.sh =================================================================== --- user/pho/stress2/misc/suj20.sh (revision 278500) +++ user/pho/stress2/misc/suj20.sh (revision 278501) @@ -1,179 +1,179 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Looping mksnap_ffs seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg # Scenario by mckusick@ # # create a bunch of files/directories # create a snapshot # remove many (but not all) of those files/directories # create some new files/directories in what remains of those # original files/directories. # create another snapshot # repeat { # remove many (somewhat different) of those files/directories # create some new files/directories in what remains of those # remaining files/directories. # create a new snapshot # remove oldest snapshot # } snap () { for i in `jot 5`; do mksnap_ffs $1 $2 2>&1 | grep -v "Resource temporarily unavailable" [ ! -s $2 ] && rm -f $2 || return 0 sleep 1 done return 1 } here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj20.c -cc -o suj20 -Wall -Wextra -g -O2 suj20.c +mycc -o suj20 -Wall -Wextra -g -O2 suj20.c rm -f suj20.c mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} mdconfig -a -t swap -s 1g -u ${mdstart} bsdlabel -w md${mdstart} auto newfs -j md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint chmod 777 $mntpoint /tmp/suj20 snap $mntpoint ${mntpoint}/.snap/snap1 /tmp/suj20 prune snap $mntpoint ${mntpoint}/.snap/snap2 /tmp/suj20 for i in `jot 10`; do /tmp/suj20 prune /tmp/suj20 snap $mntpoint ${mntpoint}/.snap/snap$((i + 2)) sn=`ls -tU ${mntpoint}/.snap | tail -1` rm -f ${mntpoint}/.snap/$sn done cd $here while mount | grep -q ${mntpoint}; do umount ${mntpoint} || sleep 1 done mdconfig -d -u ${mdstart} rm -f /tmp/suj20 exit 0 EOF #include #include #include #include #include #include #include #include static char buf[4096]; #define ND 100 #define NF 100 void setup(void) { int d, f, fd, i, n; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (mkdir(name, 00700) == -1 && errno != EEXIST) err(1, "mkdir(%s)", name); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", name); n = arc4random() % 10; for (i = 0; i < n; i++) { if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write()"); } close(fd); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } } void prune(void) { int d, f; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if (unlink(name) == -1 && errno != ENOENT) err(1, "unlink(%s)", name); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } for (d = 0; d < ND; d++) { if (arc4random() % 100 > 10) continue; snprintf(name, sizeof(name), "rm -rf d%03d", d); system(name); } } int main(int argc, char **argv __unused) { if (argc == 1) setup(); if (argc == 2) prune(); return (0); } Index: user/pho/stress2/misc/suj21.sh =================================================================== --- user/pho/stress2/misc/suj21.sh (revision 278500) +++ user/pho/stress2/misc/suj21.sh (revision 278501) @@ -1,180 +1,180 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Copy of suj20.sh, but with test user as non root. # "panic: handle_disk_write_complete: Unknown type freedep" seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg # Scenario by mckusick@ # # create a bunch of files/directories # create a snapshot # remove many (but not all) of those files/directories # create some new files/directories in what remains of those # original files/directories. # create another snapshot # repeat { # remove many (somewhat different) of those files/directories # create some new files/directories in what remains of those # remaining files/directories. # create a new snapshot # remove oldest snapshot # } snap () { for i in `jot 5`; do mksnap_ffs $1 $2 2>&1 | grep -v "Resource temporarily unavailable" [ ! -s $2 ] && rm -f $2 || return 0 sleep 1 done return 1 } here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj21.c -cc -o suj21 -Wall -Wextra -g -O2 suj21.c +mycc -o suj21 -Wall -Wextra -g -O2 suj21.c rm -f suj21.c mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} mdconfig -a -t swap -s 1g -u ${mdstart} bsdlabel -w md${mdstart} auto newfs -j md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint chmod 777 $mntpoint su $testuser -c '/tmp/suj21' snap $mntpoint ${mntpoint}/.snap/snap1 su $testuser -c '/tmp/suj21 prune' snap $mntpoint ${mntpoint}/.snap/snap2 su $testuser -c '/tmp/suj21' for i in `jot 10`; do su $testuser -c '/tmp/suj21 prune' su $testuser -c '/tmp/suj21' snap $mntpoint ${mntpoint}/.snap/snap$((i + 2)) sn=`ls -tU ${mntpoint}/.snap | tail -1` rm -f ${mntpoint}/.snap/$sn done cd $here while mount | grep -q ${mntpoint}; do umount ${mntpoint} || sleep 1 done mdconfig -d -u ${mdstart} rm -f /tmp/suj21 exit 0 EOF #include #include #include #include #include #include #include #include static char buf[4096]; #define ND 100 #define NF 100 void setup(void) { int d, f, fd, i, n; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (mkdir(name, 00700) == -1 && errno != EEXIST) err(1, "mkdir(%s)", name); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", name); n = arc4random() % 10; for (i = 0; i < n; i++) { if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write()"); } close(fd); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } } void prune(void) { int d, f; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if (unlink(name) == -1 && errno != ENOENT) err(1, "unlink(%s)", name); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } for (d = 0; d < ND; d++) { if (arc4random() % 100 > 10) continue; snprintf(name, sizeof(name), "rm -rf d%03d", d); system(name); } } int main(int argc, char **argv __unused) { if (argc == 1) setup(); if (argc == 2) prune(); return (0); } Index: user/pho/stress2/misc/suj22.sh =================================================================== --- user/pho/stress2/misc/suj22.sh (revision 278500) +++ user/pho/stress2/misc/suj22.sh (revision 278501) @@ -1,197 +1,197 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Variation of suj20.sh, with focus on the FS state after a panic / power # cycle. # Demonstrate "multiple references to blocks" in FS after reboot from a # looping mksnap_ffs(8). [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg # Scenario by mckusick@ # # create a bunch of files/directories # create a snapshot # remove many (but not all) of those files/directories # create some new files/directories in what remains of those # original files/directories. # create another snapshot # repeat { # remove many (somewhat different) of those files/directories # create some new files/directories in what remains of those # remaining files/directories. # create a new snapshot # remove oldest snapshot # } snap () { for i in `jot 5`; do mksnap_ffs $1 $2 2>&1 | grep -v "Resource temporarily unavailable" [ ! -s $2 ] && rm -f $2 || return 0 sleep 1 done return 1 } D=$diskimage if [ -n "`find $D -mtime -1h 2>/dev/null`" ]; then # FS left by previous crash mdconfig -a -t vnode -f $D -u ${mdstart} fsck -t ufs -y md${mdstart}${part} fsck -t ufs -y md${mdstart}${part} rm -f $D exit 0 fi here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj22.c -cc -o suj22 -Wall -Wextra -O2 suj22.c +mycc -o suj22 -Wall -Wextra -O2 suj22.c rm -f suj22.c mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} dede $D 1m 1k || exit 1 mdconfig -a -t vnode -f $D -u ${mdstart} bsdlabel -w md${mdstart} auto newfs -j md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mntpoint cd $mntpoint chmod 777 $mntpoint /tmp/suj22 snap $mntpoint ${mntpoint}/.snap/snap1 /tmp/suj22 prune snap $mntpoint ${mntpoint}/.snap/snap2 /tmp/suj22 for i in `jot 10`; do /tmp/suj22 prune /tmp/suj22 snap $mntpoint ${mntpoint}/.snap/snap$((i + 2)) || break sn=`ls -tU ${mntpoint}/.snap | tail -1` rm -f ${mntpoint}/.snap/$sn done cd $here while mount | grep -q ${mntpoint}; do umount ${mntpoint} || sleep 1 done fsck -t ufs -y md${mdstart}${part} fsck -t ufs -y md${mdstart}${part} mdconfig -d -u ${mdstart} rm -f /tmp/suj22 $D exit 0 EOF #include #include #include #include #include #include #include #include static char buf[4096]; #define ND 100 #define NF 100 void setup(void) { int d, f, fd, i, n; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (mkdir(name, 00700) == -1 && errno != EEXIST) err(1, "mkdir(%s)", name); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1) err(1, "open(%s)", name); n = arc4random() % 10; for (i = 0; i < n; i++) { if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write()"); } close(fd); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } } void prune(void) { int d, f; char name[128]; for (d = 0; d < ND; d++) { snprintf(name, sizeof(name), "d%03d", d); if (chdir(name) == -1) err(1, "chdir(%s)", name); for (f = 0; f < NF; f++) { if (arc4random() % 100 < 33) continue; snprintf(name, sizeof(name), "f%03d", f); if (unlink(name) == -1 && errno != ENOENT) err(1, "unlink(%s)", name); } if (chdir("..") == -1) err(1, "chdir(%s)", ".."); } for (d = 0; d < ND; d++) { if (arc4random() % 100 > 10) continue; snprintf(name, sizeof(name), "rm -rf d%03d", d); system(name); } } int main(int argc, char **argv __unused) { if (argc == 1) setup(); if (argc == 2) prune(); return (0); } Index: user/pho/stress2/misc/suj23.sh =================================================================== --- user/pho/stress2/misc/suj23.sh (revision 278500) +++ user/pho/stress2/misc/suj23.sh (revision 278501) @@ -1,429 +1,429 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Scenario from kern/159971 # bstg0003.c by Kirk Russell [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj23.c -cc -o suj23 -Wall -Wextra -O2 suj23.c +mycc -o suj23 -Wall -Wextra -O2 suj23.c rm -f suj23.c mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} mdconfig -a -t swap -s 1g -u ${mdstart} bsdlabel -w md${mdstart} auto newfs -j md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c '/tmp/suj23' while mount | grep -q ${mntpoint}; do umount ${mntpoint} || sleep 1 done mdconfig -d -u ${mdstart} rm -f /tmp/suj23 exit 0 EOF /* * Copyright 2011 Kirk J. Russell * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ #include #include #include #include #include #include #include #include #include #include #include static char *bstg_pathstore[] = { "/mnt/111/z", "/mnt/111/aaaa", "/mnt/111/bbbbb", "/mnt/111/ccccc", "/mnt/111/d", "/mnt/111/e", "/mnt/111/ffffff.fff.f", "/mnt/111/gggggggggggg", "/mnt/111/hhhh", "/mnt/111/iiiii.ii", "/mnt/111/jjjj.jj.jjjjjjjj", "/mnt/111/kkkk.kkkkkkkk", "/mnt/111/lllll", "/mnt/222/z", "/mnt/222/aaaa", "/mnt/222/bbbbb", "/mnt/222/ccccc", "/mnt/222/d", "/mnt/222/e", "/mnt/222/ffffff.fff.f", "/mnt/222/gggggggggggg", "/mnt/222/hhhh", "/mnt/222/iiiii.ii", "/mnt/222/jjjj.jj.jjjjjjjj", "/mnt/222/kkkk.kkkkkkkk", "/mnt/222/lllll", "/mnt/333/z", "/mnt/333/aaaa", "/mnt/333/bbbbb", "/mnt/333/ccccc", "/mnt/333/d", "/mnt/333/e", "/mnt/333/ffffff.fff.f", "/mnt/333/gggggggggggg", "/mnt/333/hhhh", "/mnt/333/iiiii.ii", "/mnt/333/jjjj.jj.jjjjjjjj", "/mnt/333/kkkk.kkkkkkkk", "/mnt/333/lllll", "/mnt/444/z", "/mnt/444/aaaa", "/mnt/444/bbbbb", "/mnt/444/ccccc", "/mnt/444/d", "/mnt/444/e", "/mnt/444/ffffff.fff.f", "/mnt/444/gggggggggggg", "/mnt/444/hhhh", "/mnt/444/iiiii.ii", "/mnt/444/jjjj.jj.jjjjjjjj", "/mnt/444/kkkk.kkkkkkkk", "/mnt/444/lllll", "/mnt/555/z", "/mnt/555/aaaa", "/mnt/555/bbbbb", "/mnt/555/ccccc", "/mnt/555/d", "/mnt/555/e", "/mnt/555/ffffff.fff.f", "/mnt/555/gggggggggggg", "/mnt/555/hhhh", "/mnt/555/iiiii.ii", "/mnt/555/jjjj.jj.jjjjjjjj", "/mnt/555/kkkk.kkkkkkkk", "/mnt/555/lllll", "/mnt/666/z", "/mnt/666/aaaa", "/mnt/666/bbbbb", "/mnt/666/ccccc", "/mnt/666/d", "/mnt/666/e", "/mnt/666/ffffff.fff.f", "/mnt/666/gggggggggggg", "/mnt/666/hhhh", "/mnt/666/iiiii.ii", "/mnt/666/jjjj.jj.jjjjjjjj", "/mnt/666/kkkk.kkkkkkkk", "/mnt/666/lllll", "/mnt/777/z", "/mnt/777/aaaa", "/mnt/777/bbbbb", "/mnt/777/ccccc", "/mnt/777/d", "/mnt/777/e", "/mnt/777/ffffff.fff.f", "/mnt/777/gggggggggggg", "/mnt/777/hhhh", "/mnt/777/iiiii.ii", "/mnt/777/jjjj.jj.jjjjjjjj", "/mnt/777/kkkk.kkkkkkkk", "/mnt/777/lllll", "/mnt/888/z", "/mnt/888/aaaa", "/mnt/888/bbbbb", "/mnt/888/ccccc", "/mnt/888/d", "/mnt/888/e", "/mnt/888/ffffff.fff.f", "/mnt/888/gggggggggggg", "/mnt/888/hhhh", "/mnt/888/iiiii.ii", "/mnt/888/jjjj.jj.jjjjjjjj", "/mnt/888/kkkk.kkkkkkkk", "/mnt/888/lllll", "/mnt/999/z", "/mnt/999/aaaa", "/mnt/999/bbbbb", "/mnt/999/ccccc", "/mnt/999/d", "/mnt/999/e", "/mnt/999/ffffff.fff.f", "/mnt/999/gggggggggggg", "/mnt/999/hhhh", "/mnt/999/iiiii.ii", "/mnt/999/jjjj.jj.jjjjjjjj", "/mnt/999/kkkk.kkkkkkkk", "/mnt/999/lllll", "/mnt/aaa/z", "/mnt/aaa/aaaa", "/mnt/aaa/bbbbb", "/mnt/aaa/ccccc", "/mnt/aaa/d", "/mnt/aaa/e", "/mnt/aaa/ffffff.fff.f", "/mnt/aaa/gggggggggggg", "/mnt/aaa/hhhh", "/mnt/aaa/iiiii.ii", "/mnt/aaa/jjjj.jj.jjjjjjjj", "/mnt/aaa/kkkk.kkkkkkkk", "/mnt/aaa/lllll", "/mnt/bbb/z", "/mnt/bbb/aaaa", "/mnt/bbb/bbbbb", "/mnt/bbb/ccccc", "/mnt/bbb/d", "/mnt/bbb/e", "/mnt/bbb/ffffff.fff.f", "/mnt/bbb/gggggggggggg", "/mnt/bbb/hhhh", "/mnt/bbb/iiiii.ii", "/mnt/bbb/jjjj.jj.jjjjjjjj", "/mnt/bbb/kkkk.kkkkkkkk", "/mnt/bbb/lllll", "/mnt/ccc/z", "/mnt/ccc/aaaa", "/mnt/ccc/bbbbb", "/mnt/ccc/ccccc", "/mnt/ccc/d", "/mnt/ccc/e", "/mnt/ccc/ffffff.fff.f", "/mnt/ccc/gggggggggggg", "/mnt/ccc/hhhh", "/mnt/ccc/iiiii.ii", "/mnt/ccc/jjjj.jj.jjjjjjjj", "/mnt/ccc/kkkk.kkkkkkkk", "/mnt/ccc/lllll", "/mnt/ddd/z", "/mnt/ddd/aaaa", "/mnt/ddd/bbbbb", "/mnt/ddd/ccccc", "/mnt/ddd/d", "/mnt/ddd/e", "/mnt/ddd/ffffff.fff.f", "/mnt/ddd/gggggggggggg", "/mnt/ddd/hhhh", "/mnt/ddd/iiiii.ii", "/mnt/ddd/jjjj.jj.jjjjjjjj", "/mnt/ddd/kkkk.kkkkkkkk", "/mnt/ddd/lllll", "/mnt/eee/z", "/mnt/eee/aaaa", "/mnt/eee/bbbbb", "/mnt/eee/ccccc", "/mnt/eee/d", "/mnt/eee/e", "/mnt/eee/ffffff.fff.f", "/mnt/eee/gggggggggggg", "/mnt/eee/hhhh", "/mnt/eee/iiiii.ii", "/mnt/eee/jjjj.jj.jjjjjjjj", "/mnt/eee/kkkk.kkkkkkkk", "/mnt/eee/lllll", "/mnt/fff/z", "/mnt/fff/aaaa", "/mnt/fff/bbbbb", "/mnt/fff/ccccc", "/mnt/fff/d", "/mnt/fff/e", "/mnt/fff/ffffff.fff.f", "/mnt/fff/gggggggggggg", "/mnt/fff/hhhh", "/mnt/fff/iiiii.ii", "/mnt/fff/jjjj.jj.jjjjjjjj", "/mnt/fff/kkkk.kkkkkkkk", "/mnt/fff/lllll" }; char * bstg_pathstore_get() { return bstg_pathstore[rand() % ((sizeof(bstg_pathstore) / sizeof(bstg_pathstore[0])))]; } void dogcore() { pid_t sleepchild, gcorechild; extern char **environ; /* create a child for the gcore target */ if ((sleepchild = fork()) == 0) { sleep(30); _exit(1); } else if (sleepchild > 0) { char *token[] = {NULL, NULL, NULL, NULL, NULL}; char buf[64]; int status; /* use the first process as the target */ snprintf(buf, sizeof(buf), "%d", sleepchild); token[0] = "gcore"; token[1] = "-c"; token[2] = bstg_pathstore_get(); token[3] = buf; assert(token[4] == NULL); if ((gcorechild = fork()) > 0) { waitpid(gcorechild, &status, 0); } else if (gcorechild == 0) { execve("/usr/bin/gcore", token, environ); _exit(1); } kill(sleepchild, SIGKILL); waitpid(sleepchild, &status, 0); } } void dowrite() { struct iovec data[] = { {"12", 2}, {NULL, 0}, {"12345678", 8}, }; static int fd = -1; if (fd == -1) { /* keep existing file open during life of this process */ fd = open(bstg_pathstore_get(), O_RDWR | O_NONBLOCK | O_NOCTTY); } data[1].iov_base = bstg_pathstore_get(); data[1].iov_len = strlen((char *)data[1].iov_base); ftruncate(fd, 0); pwritev(fd, data, 3, 0); } void dounlink() { unlink(bstg_pathstore_get()); } void dolink() { link(bstg_pathstore_get(), bstg_pathstore_get()); } void domkdir() { char **pdir; static char *bstg_dirs[] = { "/mnt/111", "/mnt/222", "/mnt/333", "/mnt/444", "/mnt/555", "/mnt/666", "/mnt/777", "/mnt/888", "/mnt/999", "/mnt/aaa", "/mnt/bbb", "/mnt/ccc", "/mnt/ddd", "/mnt/eee", "/mnt/fff", NULL }; for (pdir = bstg_dirs; *pdir; pdir++) { if (mkdir(*pdir, 0777) == -1) err(1, "mkdir(%s)", *pdir); } } void dosync() { sync(); } int main() { unsigned x; int i, status; void (*funcs[]) () = { dogcore, dowrite, dounlink, dolink, dowrite, dounlink, dolink, dowrite, dosync, dowrite, dounlink, dolink, dowrite, dounlink, dolink, dowrite, }; /* we only can domkdir() once at startup */ domkdir(); /* create 128 children that loop forever running 4 operations */ dosync(); for (x = 0; x < 128; x++) { if (fork() == 0) { /* give child a new seed for the pathname selection */ srand(x); for (i = 0; i < 1000; i++) { /* each child will start looping at different * function */ (*funcs[x++ % 16]) (); } /* we never expect this code to run */ _exit(1); } } /* block forever for all our children */ while (wait(&status) > 0); return 0; } Index: user/pho/stress2/misc/suj30.sh =================================================================== --- user/pho/stress2/misc/suj30.sh (revision 278500) +++ user/pho/stress2/misc/suj30.sh (revision 278501) @@ -1,282 +1,282 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # SUJ rename test scenario by Andrey Zonov # "panic: flush_pagedep_deps: MKDIR_PARENT" seen: # http://people.freebsd.org/~pho/stress/log/suj30.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj30.c -cc -o suj30 -Wall -Wextra -O2 suj30.c -lpthread +mycc -o suj30 -Wall -Wextra -O2 suj30.c -lpthread rm -f suj30.c mount | grep "on $mntpoint " | grep -q md$mdstart && umount $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 4g -u ${mdstart} bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint for i in `jot 10`; do /tmp/suj30 $mntpoint/test-$i 100000 & done for i in `jot 10`; do wait done while mount | grep -q $mntpoint; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/suj30 exit 0 EOF /* * Andrey Zonov (c) 2012 * * compile as `cc -o rename rename.c -lpthread' */ #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #define __NP__ #endif #include #include #include #include #include #include #define LOCK(x) pthread_mutex_lock(&x.mtx) #define UNLOCK(x) pthread_mutex_unlock(&x.mtx) #define SIGNAL(x) pthread_cond_signal(&x.wait) #define WAIT(x) pthread_cond_wait(&x.wait, &x.mtx) int max; int exited; char *dirname1; char *dirname2; struct file { char *name; STAILQ_ENTRY(file) next; }; struct files { pthread_mutex_t mtx; pthread_cond_t wait; STAILQ_HEAD(, file) list; }; static struct files newfiles; static struct files renamedfiles; void *loop_create(void *arg __unused); void *loop_rename(void *arg __unused); void *loop_unlink(void *arg __unused); int main(int argc, char **argv) { int i; int rc; pthread_t tid[3]; if (argc != 3) errx(1, "usage: pthread_count "); asprintf(&dirname1, "%s.1", argv[1]); asprintf(&dirname2, "%s.2", argv[1]); if (mkdir(dirname1, 0755) == -1) err(1, "mkdir(%s)", dirname1); if (mkdir(dirname2, 0755) == -1) err(1, "mkdir(%s)", dirname2); max = atoi(argv[2]); STAILQ_INIT(&newfiles.list); STAILQ_INIT(&renamedfiles.list); rc = pthread_mutex_init(&newfiles.mtx, NULL); if (rc != 0) errc(1, rc, "pthread_mutex_init()"); rc = pthread_cond_init(&newfiles.wait, NULL); if (rc != 0) errc(1, rc, "pthread_cond_init()"); rc = pthread_mutex_init(&renamedfiles.mtx, NULL); if (rc != 0) errc(1, rc, "pthread_mutex_init()"); rc = pthread_cond_init(&renamedfiles.wait, NULL); if (rc != 0) errc(1, rc, "pthread_cond_init()"); rc = pthread_create(&tid[0], NULL, loop_create, NULL); if (rc != 0) errc(1, rc, "pthread_create()"); rc = pthread_create(&tid[1], NULL, loop_rename, NULL); if (rc != 0) errc(1, rc, "pthread_create()"); rc = pthread_create(&tid[2], NULL, loop_unlink, NULL); if (rc != 0) errc(1, rc, "pthread_create()"); for (i = 0; i < 3; i++) { rc = pthread_join(tid[i], NULL); if (rc != 0) errc(1, rc, "pthread_join(%d)", i); } rc = pthread_mutex_destroy(&newfiles.mtx); if (rc != 0) errc(1, rc, "pthread_mutex_destroy(newfiles)"); rc = pthread_cond_destroy(&newfiles.wait); if (rc != 0) errc(1, rc, "pthread_cond_destroy(newfiles)"); rc = pthread_mutex_destroy(&renamedfiles.mtx); if (rc != 0) errc(1, rc, "pthread_mutex_destroy(renamedfiles)"); rc = pthread_cond_destroy(&renamedfiles.wait); if (rc != 0) errc(1, rc, "pthread_cond_destroy(renamedfiles)"); rmdir(dirname1); rmdir(dirname2); free(dirname1); free(dirname2); exit(0); } void * loop_create(void *arg __unused) { int i; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for (i = 0; i < max; i++) { file = malloc(sizeof(*file)); asprintf(&file->name, "%s/filename_too-long:%d", dirname1, i); if (mkdir(file->name, 0666) == -1) { warn("mkdir(%s)", file->name); free(file->name); free(file); break; } LOCK(newfiles); STAILQ_INSERT_TAIL(&newfiles.list, file, next); UNLOCK(newfiles); SIGNAL(newfiles); } exited = 1; SIGNAL(newfiles); pthread_exit(NULL); } void * loop_rename(void *arg __unused) { char *filename, *newname; struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for ( ;; ) { LOCK(newfiles); while (STAILQ_EMPTY(&newfiles.list) && exited < 1) WAIT(newfiles); if (STAILQ_EMPTY(&newfiles.list) && exited == 1) { UNLOCK(newfiles); break; } file = STAILQ_FIRST(&newfiles.list); STAILQ_REMOVE_HEAD(&newfiles.list, next); UNLOCK(newfiles); filename = strrchr(file->name, '/'); asprintf(&newname, "%s/%s", dirname2, filename); if (rename(file->name, newname) == -1) err(1, "rename(%s, %s)", file->name, newname); free(file->name); file->name = newname; LOCK(renamedfiles); STAILQ_INSERT_TAIL(&renamedfiles.list, file, next); UNLOCK(renamedfiles); SIGNAL(renamedfiles); } exited = 2; SIGNAL(renamedfiles); pthread_exit(NULL); } void * loop_unlink(void *arg __unused) { struct file *file; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif for ( ;; ) { LOCK(renamedfiles); while (STAILQ_EMPTY(&renamedfiles.list) && exited < 2) WAIT(renamedfiles); if (STAILQ_EMPTY(&renamedfiles.list) && exited == 2) { UNLOCK(renamedfiles); break; } file = STAILQ_FIRST(&renamedfiles.list); STAILQ_REMOVE_HEAD(&renamedfiles.list, next); UNLOCK(renamedfiles); rmdir(file->name); free(file->name); free(file); } pthread_exit(NULL); } Index: user/pho/stress2/misc/suj32.sh =================================================================== --- user/pho/stress2/misc/suj32.sh (revision 278500) +++ user/pho/stress2/misc/suj32.sh (revision 278501) @@ -1,95 +1,95 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # tunefs -j enable is not aware of the indirect blocks. # Problem fixed in r247399. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj32.c -cc -o suj32 -Wall -Wextra -O2 suj32.c || exit 1 +mycc -o suj32 -Wall -Wextra -O2 suj32.c || exit 1 rm -f suj32.c cd $here mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} mdconfig -a -t swap -s 5g -u ${mdstart} bsdlabel -w md${mdstart} auto newfs -U md${mdstart}${part} > /dev/null mount /dev/md${mdstart}$part $mntpoint # fill the root directory to become larger than NIDIR * blksize (cd $mntpoint; /tmp/suj32) while mount | grep -q ${mntpoint}; do umount ${mntpoint} || sleep 1 done tunefs -j enable /dev/md${mdstart}$part if ! mount /dev/md${mdstart}$part $mntpoint; then echo FAIL fsck_ffs -y /dev/md${mdstart}$part else umount $mntpoint fi mdconfig -d -u ${mdstart} rm -f /tmp/suj32 exit 0 EOF #include #include #include int main(void) { int i; char name[800]; char *filler = "fillerfillerfillerfillerfillerfillerfillerfillerfiller" "fillerfillerfillerfillerfillerfillerfillerfillerfiller" "fillerfillerfillerfillerfillerfillerfillerfillerfiller" "fillerfillerfillerfillerfillerfillerfillerfillerfiller"; for (i = 0; i < 2000; i++) { snprintf(name, sizeof(name), "%s.%d", filler, i); if (mkdir(name, 00700) == -1) err(1, "mkdir(%s)", name); } return (0); } Index: user/pho/stress2/misc/suj5.sh =================================================================== --- user/pho/stress2/misc/suj5.sh (revision 278500) +++ user/pho/stress2/misc/suj5.sh (revision 278501) @@ -1,185 +1,185 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/suj.sh 210724 2010-08-01 10:33:03Z pho $ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Deadlock seen . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj5.c -cc -o suj5 -Wall -O2 suj5.c +mycc -o suj5 -Wall -O2 suj5.c rm -f suj5.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "cd $mntpoint; /tmp/suj5" while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/suj5 exit EOF #include #include #include #include #include #include #include #include #include #define PARALLEL 10 static int random_int(int mi, int ma) { return (arc4random() % (ma - mi + 1) + mi); } static int64_t df(void) { char path[MAXPATHLEN+1]; struct statfs buf; if (getcwd(path, sizeof(path)) == NULL) err(1, "getcwd()"); if (statfs(path, &buf) < 0) err(1, "statfs(%s)", path); printf("Free space on %s: %jd Mb\n", path, buf.f_bavail * buf.f_bsize / 1024 / 1024); return (buf.f_bavail * buf.f_bsize); } static void test(int size) { int buf[1024], index, to; #ifdef TEST int i; #endif int fd; char file[128]; sprintf(file,"p%05d", getpid()); if ((fd = creat(file, 0660)) == -1) err(1, "creat(%s)", file); to = sizeof(buf); index = 0; while (index < size) { if (index + to > size) to = size - index; #ifdef TEST for (i = 0; i < to; i++) buf[i] = index + i; #endif index += to; if (write(fd, buf, to) != to) err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); } if (close(fd) == -1) err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); if ((fd = open(file, O_RDONLY)) == -1) err(1, "open(%s), %s:%d", file, __FILE__, __LINE__); index = 0; while (index < size) { if (index + to > size) to = size - index; if (read(fd, buf, to) != to) err(1, "rw read. %s.%d", __FILE__, __LINE__); #ifdef TEST for (i = 0; i < to; i++) { if (buf[i] != index + i) { fprintf(stderr, "%s, pid %d: expected %d @ %d, got %d\n", getprogname(), getpid(), index+i, index+i, buf[i]); exit(EXIT_FAILURE); } } #endif index += to; } if (close(fd) == -1) err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); if (unlink(file) == -1) err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); exit(0); } int main() { int i, j, pct; int size; /* in k */ int64_t bl; bl = df(); if (bl > (int64_t)INT_MAX * PARALLEL) bl = (int64_t)INT_MAX * PARALLEL; size = bl / PARALLEL / 1024; pct = random_int(1, 50); size = size / 100 * pct + 1; if (random_int(1, 100) <= 50) size = 34 * 1024; /* Known good deadlock value */ printf("Max file size: %d Mb\n", size / 1024); for (i = 0; i < 100; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) { arc4random_stir(); test(random_int(1, size) * 1024); } } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/suj6.sh =================================================================== --- user/pho/stress2/misc/suj6.sh (revision 278500) +++ user/pho/stress2/misc/suj6.sh (revision 278501) @@ -1,188 +1,188 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/suj.sh 210724 2010-08-01 10:33:03Z pho $ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Variation of suj5.sh # "panic: indir_trunc: Index out of range -2 parent -2061 lbn -2060" seen . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > suj6.c -cc -o suj6 -Wall -O2 suj6.c +mycc -o suj6 -Wall -O2 suj6.c rm -f suj6.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint su $testuser -c "cd $mntpoint; /tmp/suj6" > /dev/null while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/suj6 exit EOF #include #include #include #include #include #include #include #include #include #define PARALLEL 10 static int random_int(int mi, int ma) { return (arc4random() % (ma - mi + 1) + mi); } static int64_t df(void) { char path[MAXPATHLEN+1]; struct statfs buf; if (getcwd(path, sizeof(path)) == NULL) err(1, "getcwd()"); if (statfs(path, &buf) < 0) err(1, "statfs(%s)", path); printf("Free space on %s: %jd Mb\n", path, buf.f_bavail * buf.f_bsize / 1024 / 1024); return (buf.f_bavail * buf.f_bsize); } static void test(int size) { int buf[1024], index, to; #ifdef TEST int i; #endif int fd; char file[128]; sprintf(file,"p%05d", getpid()); if ((fd = creat(file, 0660)) == -1) err(1, "creat(%s)", file); to = sizeof(buf); index = 0; while (index < size) { if (index + to > size) to = size - index; #ifdef TEST for (i = 0; i < to; i++) buf[i] = index + i; #endif index += to; if (write(fd, buf, to) != to) err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); } if (close(fd) == -1) err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); #if 0 if ((fd = open(file, O_RDONLY)) == -1) err(1, "open(%s), %s:%d", file, __FILE__, __LINE__); index = 0; while (index < size) { if (index + to > size) to = size - index; if (read(fd, buf, to) != to) err(1, "rw read. %s.%d", __FILE__, __LINE__); #ifdef TEST for (i = 0; i < to; i++) { if (buf[i] != index + i) { fprintf(stderr, "%s, pid %d: expected %d @ %d, got %d\n", getprogname(), getpid(), index+i, index+i, buf[i]); exit(EXIT_FAILURE); } } #endif index += to; } if (close(fd) == -1) err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); #endif if (unlink(file) == -1) err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); exit(0); } int main() { int i, j, pct; int size; /* in k */ int64_t bl; bl = df(); if (bl > (int64_t)INT_MAX * PARALLEL) bl = (int64_t)INT_MAX * PARALLEL; size = bl / PARALLEL / 1024; pct = random_int(1, 50); size = size / 100 * pct + 1; if (random_int(1, 100) <= 50) size = 34 * 1024; /* Known good deadlock value */ printf("Max file size: %d Mb\n", size / 1024); for (i = 0; i < 100; i++) { for (j = 0; j < PARALLEL; j++) { if (fork() == 0) { arc4random_stir(); test(random_int(1, size) * 1024); } } for (j = 0; j < PARALLEL; j++) wait(NULL); } return (0); } Index: user/pho/stress2/misc/swap.sh =================================================================== --- user/pho/stress2/misc/swap.sh (revision 278500) +++ user/pho/stress2/misc/swap.sh (revision 278501) @@ -1,152 +1,154 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Swap test. Variation of testcases/swap. +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/swap.c -cc -o swap -Wall -Wextra -O2 swap.c || exit 1 +mycc -o swap -Wall -Wextra -O2 swap.c || exit 1 rm -f swap.c usermem=`sysctl hw.usermem | sed 's/.* //'` swap=`sysctl vm.swap_total | sed 's/.* //'` if [ $swap -gt 0 ]; then size=$((usermem/10*11)) else size=$((usermem/10*9)) fi /tmp/swap $((size / 4096)) rm -f /tmp/swap exit EOF #include #include #include #include #include #include #include #include #include #define RUNTIME (5 * 60) #define INCARNATIONS 32 static unsigned long size, original; void setup(void) { struct rlimit rlp; size = size / INCARNATIONS; original = size; if (size == 0) errx(1, "Argument too small"); if (getrlimit(RLIMIT_DATA, &rlp) < 0) err(1,"getrlimit"); rlp.rlim_cur -= 1024 * 1024; if (size > (unsigned long)rlp.rlim_cur) size = rlp.rlim_cur; #if 0 printf("setup: pid %d. Total %luMb\n", getpid(), size / 1024 / 1024 * INCARNATIONS); #endif if (size == 0) errx(1, "Argument too small"); return; } int test(void) { char *c; int page; unsigned long i, j; time_t start; c = malloc(size); while (c == NULL) { size -= 1024 * 1024; c = malloc(size); } if (size != original) printf("Malloc size changed from %ld Mb to %ld Mb\n", original / 1024 / 1024, size / 1024 / 1024); page = getpagesize(); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { i = j = 0; while (i < size) { c[i] = 0; i += page; if (++j % 1024 == 0) { if ((time(NULL) - start) >= RUNTIME) break; if (arc4random() % 100 < 5) usleep(1000); } } } free(c); _exit(0); } int main(int argc, char **argv) { int i; if (argc != 2) errx(1, "Usage: %s bytes", argv[0]); size = atol(argv[1]) * 4096; setup(); for (i = 0; i < INCARNATIONS; i++) if (fork() == 0) test(); for (i = 0; i < INCARNATIONS; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/swap2.sh =================================================================== --- user/pho/stress2/misc/swap2.sh (revision 278500) +++ user/pho/stress2/misc/swap2.sh (revision 278501) @@ -1,179 +1,179 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Swap test. Variation of swap.sh # panic: vm_radix_remove: impossible to locate the key # panic: vm_page_alloc: cache page 0xff... is missing from the free queue # panic: vm_radix_node_put: rnode 0xfffffe00099035a0 has a child # panic: vm_radix_remove: impossible to locate the key [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint export runRUNTIME=30m export RUNDIR=$mntpoint/stressX rm -rf /tmp/stressX.control dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/swap2.c -cc -o swap2 -Wall -Wextra -O2 swap2.c || exit 1 +mycc -o swap2 -Wall -Wextra -O2 swap2.c || exit 1 rm -f swap2.c cd $odir usermem=`sysctl hw.usermem | sed 's/.* //'` swap=`sysctl vm.swap_total | sed 's/.* //'` if [ $swap -gt 0 ]; then size=$((usermem/10*11)) else size=$((usermem/10*9)) fi /tmp/swap2 $((size / 4096)) & sleep 30 su $testuser -c "(cd ../testcases/rw; ./rw -t 3m -i 40 -l 100 -v -h -h)" & wait; wait while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/swap2 exit EOF #include #include #include #include #include #include #include #include #include #define RUNTIME (5 * 60) #define INCARNATIONS 32 static unsigned long size, original; void setup(void) { struct rlimit rlp; size = size / INCARNATIONS; original = size; if (size == 0) errx(1, "Argument too small"); if (getrlimit(RLIMIT_DATA, &rlp) < 0) err(1,"getrlimit"); rlp.rlim_cur -= 1024 * 1024; if (size > (unsigned long)rlp.rlim_cur) size = rlp.rlim_cur; #if 0 printf("setup: pid %d. Total %luMb\n", getpid(), size / 1024 / 1024 * INCARNATIONS); #endif if (size == 0) errx(1, "Argument too small"); return; } int test(void) { char *c; int page; unsigned long i, j; time_t start; c = malloc(size); while (c == NULL) { size -= 1024 * 1024; c = malloc(size); } if (size != original) printf("Malloc size changed from %ld Mb to %ld Mb\n", original / 1024 / 1024, size / 1024 / 1024); page = getpagesize(); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { i = j = 0; while (i < size) { c[i] = 0; i += page; if (++j % 1024 == 0) { if ((time(NULL) - start) >= RUNTIME) break; if (arc4random() % 100 < 5) usleep(1000); } } } free(c); _exit(0); } int main(int argc, char **argv) { int i; if (argc != 2) errx(1, "Usage: %s bytes", argv[0]); size = atol(argv[1]) * 4096; setup(); for (i = 0; i < INCARNATIONS; i++) if (fork() == 0) test(); for (i = 0; i < INCARNATIONS; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/symlink.sh =================================================================== --- user/pho/stress2/misc/symlink.sh (revision 278500) +++ user/pho/stress2/misc/symlink.sh (revision 278501) @@ -1,129 +1,129 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Testing problem with premature disk full problem with symlinks [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg D=$diskimage dede $D 1m 1024 || exit 1 odir=`pwd` dir=$mntpoint cd /tmp sed '1,/^EOF/d' < $odir/$0 > symlink.c -cc -o symlink -Wall symlink.c +mycc -o symlink -Wall symlink.c rm -f symlink.c cd $odir mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} mdconfig -a -t vnode -f $D -u ${mdstart} tst() { cd $dir df -ik $mntpoint i=`df -ik $mntpoint | tail -1 | awk '{printf "%d\n", ($7 - 500)/2}'` [ $i -gt 20000 ] && i=20000 for k in `jot 5`; do for j in `jot 2`; do /tmp/symlink $i & done for j in `jot 2`; do wait done df -ik $mntpoint | tail -1 # sleep 30 # With this enabled, soft update also works done cd $odir } for i in "" "-U"; do echo "newfs $i /dev/md${mdstart}" newfs $i /dev/md${mdstart} > /dev/null 2>&1 mount /dev/md${mdstart} ${mntpoint} tst umount -f ${mntpoint} done mdconfig -d -u $mdstart exit EOF #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { int i, j; int64_t size; pid_t pid; char file[128]; size = atol(argv[1]); // printf("Creating %jd symlinks...\n", size); fflush(stdout); pid = getpid(); for (j = 0; j < size; j++) { sprintf(file,"p%05d.%05d", pid, j); if (symlink("/mnt/not/there", file) == -1) { if (errno != EINTR) { warn("symlink(%s)", file); printf("break out at %d, errno %d\n", j, errno); break; } } } // printf("Deleting %jd files...\n", size); fflush(stdout); for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) err(3, "unlink(%s)", file); } return (0); } Index: user/pho/stress2/misc/symlink2.sh =================================================================== --- user/pho/stress2/misc/symlink2.sh (revision 278500) +++ user/pho/stress2/misc/symlink2.sh (revision 278501) @@ -1,121 +1,121 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Testing problem with buffer cache inconsistancy [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg D=$diskimage dede $D 1m 10 || exit 1 odir=`pwd` dir=$mntpoint cd /tmp sed '1,/^EOF/d' < $odir/$0 > symlink2.c -cc -o symlink2 -Wall symlink2.c +mycc -o symlink2 -Wall symlink2.c rm -f symlink2.c cd $odir mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} mdconfig -a -t vnode -f $D -u ${mdstart} for i in "" "-U"; do echo "newfs $i /dev/md${mdstart}" newfs $i /dev/md${mdstart} > /dev/null 2>&1 mount /dev/md${mdstart} $mntpoint mkdir ${mntpoint}/dir /tmp/symlink2 ${mntpoint}/dir/link ls -l ${mntpoint}/dir > /dev/null 2>&1 if [ $? -ne 0 ]; then set -x ls -l ${mntpoint}/dir umount $mntpoint mount /dev/md${mdstart} $mntpoint ls -l ${mntpoint}/dir set +x fi umount -f ${mntpoint} done mdconfig -d -u $mdstart exit EOF #include #include #include #include #include #include #include static char *path; int main(int argc, char **argv) { int i, n; pid_t p; char buf[128]; path = argv[1]; for (i = 0; i < 100; i++) { if ((p = fork()) == 0) { if ((n = readlink(path, buf, sizeof(buf) -1)) < 0) { for (i = 0; i < 60; i++) { sleep(1); if ((n = readlink(path, buf, sizeof(buf) -1)) > 0) { break; } } } if (n < 0) err(1, "readlink(%s). %s:%d", path, __FILE__, __LINE__); exit(0); } } (void) unlink(path); sleep(2); if (symlink("1234", path) < 0) err(1, "symlink(%s, %s)", path, "1234"); for (i = 0; i < 100; i++) { if (wait(&n) == -1) err(1, "wait(), %s:%d", __FILE__, __LINE__); } return (0); } Index: user/pho/stress2/misc/syscall2.sh =================================================================== --- user/pho/stress2/misc/syscall2.sh (revision 278500) +++ user/pho/stress2/misc/syscall2.sh (revision 278501) @@ -1,228 +1,228 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test calls with random arguments, in reverse order # Variation of the syscall test program. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > syscall2.c -cc -o syscall2 -Wall -I $odir/../include -L $odir/../lib syscall2.c -lstress -lutil +mycc -o syscall2 -Wall -I $odir/../include -L $odir/../lib syscall2.c -lstress -lutil rm -f syscall2.c kldstat -v | grep -q sysvmsg || kldload sysvmsg kldstat -v | grep -q sysvsem || kldload sysvsem kldstat -v | grep -q sysvshm || kldload sysvshm kldstat -v | grep -q aio || kldload aio kldstat -v | grep -q mqueuefs || kldload mqueuefs syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'` n=$syscall [ $# -eq 1 ] && n=$1 rm -f /tmp/syscall2.log while [ $n -gt 0 ]; do echo "`date '+%T'` syscall $n" echo "`date '+%T'` syscall $n" >> /tmp/syscall2.log for i in `jot 5`; do su ${testuser} -c "sh -c \"/tmp/syscall2 -t 30s -i 100 -h -l 100 -k $n\"" done chflags -R 0 $RUNDIR rm -rf $RUNDIR n=$((n - 1)) done rm -f /tmp/syscall2 exit EOF /* Call random system calls with random arguments */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include "stress.h" static char path[128]; static int num; static int starting_dir = 0; uint32_t rb[7][10]; static int ignore[] = { SYS_syscall, SYS_exit, SYS_fork, 11, /* 11 is obsolete execv */ SYS_unmount, SYS_reboot, SYS_vfork, 109, /* 109 is old sigblock */ 111, /* 111 is old sigsuspend */ SYS_shutdown, SYS___syscall, SYS_rfork, SYS_sigsuspend, SYS_mac_syscall, SYS_sigtimedwait, SYS_sigwaitinfo, }; int setup(int nb) { int i; struct rlimit rl; umask(0); sprintf(path,"%s.%05d", getprogname(), getpid()); (void)mkdir(path, 0770); if (chdir(path) == -1) err(1, "chdir(%s), %s:%d", path, __FILE__, __LINE__); if ((starting_dir = open(".", 0)) < 0) err(1, "."); if (op->argc == 1) { num = atoi(op->argv[0]); for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) if (num == ignore[i]) { printf("syscall %d is marked a no test!\n", num); exit(1); } } else { num = 0; while (num == 0) { num = random_int(0, SYS_MAXSYSCALL); for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) if (num == ignore[i]) { num = 0; break; } } } if (op->verbose > 1) printf("Testing syscall #%d, pid %d\n", num, getpid()); /* Multiple parallel core dump may panic the kernel with: panic: kmem_malloc(184320): kmem_map too small: 84426752 total allocated */ rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); setproctitle("#%d", num); return (0); } void cleanup(void) { if (starting_dir != 0) { if (fchdir(starting_dir) == -1) err(1, "fchdir()"); (void)system("find . -type d -exec chmod 777 {} \\;"); (void)system("find . -type f -exec chmod 666 {} \\;"); (void)system("find . -delete"); if (chdir("..") == -1) err(1, "chdir(..)"); if (rmdir(path) == -1) err(1, "rmdir(%s), %s:%d", path, __FILE__, __LINE__); } starting_dir = 0; } void rainit(void) { int i, j; for (i = 0; i < 7; i++) { for (j = 0; j < 10; j++) { if (arc4random() % 100 > 20) rb[i][j] = arc4random(); else rb[i][j] = (uint32_t) &rb[i][j]; } } } uint32_t ra(int i) { uint32_t r; r = arc4random(); if ((r & 1) == 0) r = arc4random(); else r = (uint32_t) &rb[i][0]; return (r); } int test(void) { int i; unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7; for (i = 0; i < 128; i++) { rainit(); arg1 = ra(0); arg2 = ra(1); arg3 = ra(2); arg4 = ra(3); arg5 = ra(4); arg6 = ra(5); arg7 = ra(6); if (op->verbose > 3) printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } return (0); } Index: user/pho/stress2/misc/syscall3.sh =================================================================== --- user/pho/stress2/misc/syscall3.sh (revision 278500) +++ user/pho/stress2/misc/syscall3.sh (revision 278501) @@ -1,133 +1,133 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test random syscalls with random arguments. # Regression test of r209697 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > syscall3.c -cc -o syscall3 -Wall syscall3.c +mycc -o syscall3 -Wall syscall3.c rm -f syscall3.c kldstat -v | grep -q sysvmsg || kldload sysvmsg kldstat -v | grep -q sysvsem || kldload sysvsem kldstat -v | grep -q sysvshm || kldload sysvshm kldstat -v | grep -q aio || kldload aio kldstat -v | grep -q mqueuefs || kldload mqueuefs mkdir -p $RUNDIR/syscall3 cd $RUNDIR/syscall3 for i in `jot 4`; do su $testuser -c /tmp/syscall3 & done for i in `jot 4`; do wait done chflags -R 0 $RUNDIR/syscall3 rm -rf /tmp/syscall3 $RUNDIR/syscall3 exit EOF #include #include #include #include #include #include #include #include #include static unsigned int ignore[] = { SYS_syscall, SYS_exit, SYS_fork, 11, /* 11 is obsolete execv */ SYS_unmount, SYS_reboot, SYS_vfork, 109, /* 109 is old sigblock */ 111, /* 111 is old sigsuspend */ SYS_shutdown, SYS___syscall, SYS_rfork, SYS_sigsuspend, SYS_mac_syscall, SYS_sigtimedwait, SYS_sigwaitinfo, }; void handler(int i) { _exit(0); } int main(int argc, char **argv) { unsigned int i; unsigned int arg1, arg2, arg3, arg4, arg5, arg6, arg7, num; signal(SIGSYS, SIG_IGN); signal(SIGALRM, handler); alarm(600); for (;;) { num = 0; while (num == 0) { num = arc4random(); for (i = 0; i < sizeof(ignore) / sizeof(ignore[0]); i++) if (num == ignore[i]) { num = 0; break; } } arg1 = arc4random(); arg2 = arc4random(); arg3 = arc4random(); arg4 = arc4random(); arg5 = arc4random(); arg6 = arc4random(); arg7 = arc4random(); if (argc > 1) printf("%2d : syscall(%3d, %x, %x, %x, %x, %x, %x, %x)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } return (0); } Index: user/pho/stress2/misc/syscall4.sh =================================================================== --- user/pho/stress2/misc/syscall4.sh (revision 278500) +++ user/pho/stress2/misc/syscall4.sh (revision 278501) @@ -1,345 +1,345 @@ #!/bin/sh # # Copyright (c) 2011-2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Threaded syscall(2) fuzz test inspired by the iknowthis test suite # by Tavis Ormandy [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > syscall4.c rm -f /tmp/syscall4 -cc -o syscall4 -Wall -Wextra -O2 -g syscall4.c -lpthread || exit 1 +mycc -o syscall4 -Wall -Wextra -O2 -g syscall4.c -lpthread || exit 1 rm -f syscall4.c kldstat -v | grep -q sysvmsg || kldload sysvmsg kldstat -v | grep -q sysvsem || kldload sysvsem kldstat -v | grep -q sysvshm || kldload sysvshm kldstat -v | grep -q aio || kldload aio kldstat -v | grep -q mqueuefs || kldload mqueuefs mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint sleeptime=${sleeptime:-12} st=`date '+%s'` while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -k -h)" > /dev/null (cd $mntpoint; /tmp/syscall4 $* ) & start=`date '+%s'` while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do ps aux | grep -v grep | egrep -q "syscall4$" || break sleep .5 done while pkill -9 syscall4; do : done wait pkill -9 swap ipcs | grep nobody | awk '/^(q|m|s)/ {print " -" $1, $2}' | xargs -L 1 ipcrm done while pkill -9 syscall4; do : done for i in `jot 10`; do mount | grep -q md${mdstart}$part && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 10 done if mount | grep -q md${mdstart}$part; then fstat $mntpoint echo "umount $mntpoint failed" exit 1 fi rm -f /tmp/syscall4 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int ignore[] = { SYS_syscall, SYS_exit, SYS_fork, 11, /* 11 is obsolete execv */ SYS_unmount, SYS_reboot, SYS_vfork, 109, /* 109 is old sigblock */ 111, /* 111 is old sigsuspend */ SYS_shutdown, SYS___syscall, 216, /* custom syscall */ SYS_rfork, SYS_sigsuspend, SYS_mac_syscall, SYS_sigtimedwait, SYS_sigwaitinfo, #if __FreeBSD_version < 804500 SYS_thr_create, SYS_thr_new, #endif #if __FreeBSD_version >= 900041 SYS_pdfork, #endif }; int fd[900], fds[2], socketpr[2]; #ifndef nitems #define nitems(x) (sizeof((x)) / sizeof((x)[0])) #endif #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define MAGIC 1664 u_int32_t r[N]; int magic1, syscallno, magic2; static int random_int(int mi, int ma) { return (arc4random() % (ma - mi + 1) + mi); } static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions; char *args[5]; int i; ftsoptions = FTS_PHYSICAL; args[0] = "/dev"; args[1] = "/proc"; args[2] = "/usr/compat/linux/proc"; args[3] = "."; args[4] = 0; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) if ((fd[i] = open(p->fts_path, O_RDONLY)) == -1) continue; i++; i = i % 900; } if (fts_close(fts) == -1) err(1, "fts_close()"); if (pipe(fds) == -1) err(1, "pipe()"); if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, socketpr) == -1) err(1, "socketpair()"); sleep(1); close(socketpr[0]); close(socketpr[1]); close(fds[0]); close(fds[1]); } return(0); } void * calls(void *arg __unused) { int i, j, num; unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; for (i = 0;; i++) { if (i == 0) usleep(1000); num = syscallno; while (num == 0) { num = random_int(0, SYS_MAXSYSCALL); for (j = 0; j < (int)nitems(ignore); j++) if (num == ignore[j]) { num = 0; break; } } arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); #if 0 fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); sleep(2); #endif alarm(1); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); num = 0; if (magic1 != MAGIC || magic2 != MAGIC) _exit(1); } return (0); } int main(int argc, char **argv) { struct passwd *pw; struct rlimit limit; pthread_t rp, cp[50]; time_t start; int j; magic1 = magic2 = MAGIC; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (setgroups(1, &pw->pw_gid) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); limit.rlim_cur = limit.rlim_max = 1000; #if defined(RLIMIT_NPTS) if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); #endif signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); if (argc > 2) errx(1, "Usage: %s {}", argv[0]); if (argc == 2) { syscallno = atoi(argv[1]); for (j = 0; j < (int)nitems(ignore); j++) if (syscallno == ignore[j]) errx(0, "syscall #%d is on the ignore list.", syscallno); } if (daemon(0, 0) == -1) err(1, "daemon()"); start = time(NULL); while ((time(NULL) - start) < 120) { if (fork() == 0) { arc4random_stir(); if (pthread_create(&rp, NULL, test, NULL) != 0) perror("pthread_create"); usleep(1000); for (j = 0; j < 50; j++) if (pthread_create(&cp[j], NULL, calls, NULL) != 0) perror("pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } Index: user/pho/stress2/misc/tmpfs10.sh =================================================================== --- user/pho/stress2/misc/tmpfs10.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs10.sh (revision 278501) @@ -1,157 +1,157 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # tmpfs(5) name lookup problem seen: # $ ./tmpfs10.sh # tmpfs10: unlink(p01193.14729) at loop #2: No such file or directory # unlink(p01193.14729) succeeded at call #2. # tmpfs10: unlink(p01186.14409) at loop #2: No such file or directory # unlink(p01186.14409) succeeded at call #2. # FAIL # $ # Fixed in r253967. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > tmpfs10.c -cc -o tmpfs10 -Wall -Wextra -O2 -g tmpfs10.c || exit 1 +mycc -o tmpfs10 -Wall -Wextra -O2 -g tmpfs10.c || exit 1 rm -f tmpfs10.c cd $odir mount | grep -q "on $mntpoint " && umount $mntpoint mount -t tmpfs tmpfs $mntpoint cd $mntpoint /tmp/tmpfs10 || { find $mntpoint ! -type d | xargs ls -il; echo FAIL; } cd $odir umount $mntpoint rm -f /tmp/tmpfs10 exit 0 EOF #include #include #include #include #include #include #include #include #include static int loop; int error; #define PARALLEL 20 #define SIZE 16000 void test2(void) { int i, j, k; pid_t pid; char file[128], dir[128]; loop++; pid = getpid(); sprintf(dir,"%s.%05d", getprogname(), pid); if (mkdir(dir, 0770) < 0) err(1, "mkdir(%s), %s:%d", dir, __FILE__, __LINE__); if (chdir(dir) == -1) err(1, "chdir(%s), %s:%d", dir, __FILE__, __LINE__); for (j = 0; j < SIZE; j++) { sprintf(file,"p%05d.%05d", pid, j); if (symlink("/tmp/not/there", file) == -1) { if (errno != EINTR) { warn("symlink(%s). %s.%d", file, __FILE__, __LINE__); break; } } } for (i = --j; i >= 0; i--) { sprintf(file,"p%05d.%05d", pid, i); if (unlink(file) == -1) { warn("unlink(%s) at loop #%d", file, loop); error++; for (k = 0; k < 10; k++) { usleep(10000); if (unlink(file) == 0) { fprintf(stderr, "unlink(%s) succeeded at call #%d.\n", file, k + 2); break; } } } } (void)chdir(".."); if (rmdir(dir) == -1) warn("rmdir(%s), %s:%d", dir, __FILE__, __LINE__); } void test(void) { sleep(arc4random() % 3 + 1); test2(); if (error == 0) test2(); _exit(error); } int main(void) { int e, i, status; for (i = 0; i < PARALLEL; i++) if (fork() == 0) test(); e = 0; for (i = 0; i < PARALLEL; i++) { wait(&status); e += WEXITSTATUS(status); } return (e); } Index: user/pho/stress2/misc/tmpfs5.sh =================================================================== --- user/pho/stress2/misc/tmpfs5.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs5.sh (revision 278501) @@ -1,55 +1,55 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # tmpfs + fsx test scenario. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` src=`uname -v | sed 's/.*:.*:\(.*\)\/sys\/.*/\1/'` [ -r $src/tools/regression/fsx/fsx.c ] || exit 1 cd /tmp -cc -o fsx -Wall $src/tools/regression/fsx/fsx.c +mycc -o fsx -Wall $src/tools/regression/fsx/fsx.c mount | grep "$mntpoint" | grep -q tmpfs && umount $mntpoint mount -t tmpfs tmpfs $mntpoint ( /tmp/fsx -q -N 100000 $mntpoint/file.1 & /tmp/fsx -q -N 100000 $mntpoint/file.2 & ) | grep -v A-OK wait;wait while mount | grep "$mntpoint" | grep -q tmpfs; do umount $mntpoint || sleep 1 done rm -f /tmp/fsx Index: user/pho/stress2/misc/tmpfs6.sh =================================================================== --- user/pho/stress2/misc/tmpfs6.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs6.sh (revision 278501) @@ -1,112 +1,112 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # panic: deadlkres: possible deadlock detected for 0xc8576a00, blocked for 1801792 ticks # Scenario by kib@ [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > tmpfs6.c -cc -o tmpfs6 -Wall -Wextra -O2 tmpfs6.c || exit 1 +mycc -o tmpfs6 -Wall -Wextra -O2 tmpfs6.c || exit 1 rm -f tmpfs6.c mount | grep $mntpoint | grep -q tmpfs && umount $mntpoint mount -t tmpfs tmpfs $mntpoint (cd $mntpoint; /tmp/tmpfs6) rm -f /tmp/tmpfs6 while mount | grep $mntpoint | grep -q tmpfs; do umount $mntpoint || sleep 1 done exit EOF #include #include #include #include #include #include #include #include int pagesize; #define FILESIZE (32 * 1024) char wbuffer[FILESIZE]; void test(void) { int fd; int len; void *addr; char filename[80]; snprintf(filename, sizeof(filename), "file.%07d", getpid()); if ((fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) err(1, "open(%s)", filename); if ((len = write(fd, wbuffer, FILESIZE)) != FILESIZE) err(1, "write()"); fsync(fd); if ((addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0)) == MAP_FAILED) err(1, "mmap()"); if (lseek(fd, 0, SEEK_SET) != 0) err(1, "lseek()"); if ((len = write(fd, addr, FILESIZE)) != FILESIZE) err(1, "write() 2"); if (munmap(addr, FILESIZE) == -1) err(1, "munmap()"); close(fd); unlink(filename); } int main(void) { int i; for (i = 0; i < 10000; i++) test(); return (0); } Index: user/pho/stress2/misc/tmpfs7.sh =================================================================== --- user/pho/stress2/misc/tmpfs7.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs7.sh (revision 278501) @@ -1,250 +1,250 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by Nate Eldredge neldredge math ucsdnedu # kern/127213: [tmpfs] sendfile on tmpfs data corruption [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg set -e odir=`pwd` cd /tmp cat > server.c < #include #include #include #include "util.h" int main(int argc, char *argv[]) { int f, listener, connection; if (argc < 3) { fprintf(stderr, "Usage: %s filename socketname\n", argv[0]); exit(1); } if ((f = open(argv[1], O_RDONLY)) < 0) { perror(argv[1]); exit(1); } if ((listener = listen_unix_socket(argv[2])) < 0) { exit(1); } if ((connection = accept_unix_socket(listener)) >= 0) { real_sendfile(f, connection); } return 0; } EOF cat > client.c < #include #include #include #include "util.h" int main(int argc, char *argv[]) { int s; if (argc < 2) { fprintf(stderr, "Usage: %s socketname\n", argv[0]); exit(1); } if ((s = connect_unix_socket(argv[1])) < 0) { exit(1); } fake_sendfile(s, 1); return 0; } EOF cat > util.c < #include #include #include #include #include #include #include #include #include int create_unix_socket(void) { int fd; if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { perror("socket"); return -1; } return fd; } int make_unix_sockaddr(const char *pathname, struct sockaddr_un *sa) { memset(sa, 0, sizeof(*sa)); sa->sun_family = PF_LOCAL; if (strlen(pathname) + 1 > sizeof(sa->sun_path)) { // fprintf(stderr, "%s: pathname too long (max %lu)\n", // pathname, sizeof(sa->sun_path)); errno = ENAMETOOLONG; return -1; } strcpy(sa->sun_path, pathname); return 0; } static char *sockname; void delete_socket(void) { unlink(sockname); } int listen_unix_socket(const char *path) { int fd; struct sockaddr_un sa; if (make_unix_sockaddr(path, &sa) < 0) return -1; if ((fd = create_unix_socket()) < 0) return -1; if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror("bind"); close(fd); return -1; } sockname = strdup(path); atexit(delete_socket); if (listen(fd, 5) < 0) { perror("listen"); close(fd); return -1; } return fd; } int accept_unix_socket(int fd) { int s; if ((s = accept(fd, NULL, 0)) < 0) { perror("accept"); return -1; } return s; } int connect_unix_socket(const char *path) { int fd; struct sockaddr_un sa; if (make_unix_sockaddr(path, &sa) < 0) return -1; if ((fd = create_unix_socket()) < 0) return -1; if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror("connect"); return -1; } return fd; } #define BUFSIZE 65536 int fake_sendfile(int from, int to) { char buf[BUFSIZE]; int v; int sent = 0; while ((v = read(from, buf, BUFSIZE)) > 0) { int d = 0; while (d < v) { int w = write(to, buf, v - d); if (w <= 0) { perror("write"); return -1; } d += w; sent += w; } } if (v != 0) { perror("read"); return -1; } return sent; } int real_sendfile(int from, int to) { int v; v = sendfile(from, to, 0, 0, NULL, NULL, 0); if (v < 0) { perror("sendfile"); } return v; } EOF cat > util.h < #include #include #include #include #include #include int create_unix_socket(void); int make_unix_sockaddr(const char *pathname, struct sockaddr_un *sa); int listen_unix_socket(const char *path); int accept_unix_socket(int fd); int connect_unix_socket(const char *path); int fake_sendfile(int from, int to); int real_sendfile(int from, int to); EOF -cc -c -Wall -Wextra -O2 util.c -cc -o server -Wall -Wextra -O2 server.c util.o -cc -o client -Wall -Wextra -O2 client.c util.o +mycc -c -Wall -Wextra -O2 util.c +mycc -o server -Wall -Wextra -O2 server.c util.o +mycc -o client -Wall -Wextra -O2 client.c util.o rm -f server.c client.c util.c util.o util.h mysocket mount | grep "$mntpoint" | grep -q tmpfs && umount $mntpoint mount -t tmpfs tmpfs $mntpoint dd if=/dev/random of=$mntpoint/data bs=123456 count=1 > /dev/null 2>&1 ./server $mntpoint/data mysocket & sleep 0.2 ./client mysocket > data.$$ cmp $mntpoint/data data.$$ || { echo "FAIL Data mismatch"; ls -l $mntpoint/data data.$$; } rm -f data.$$ server client mysocket while mount | grep "$mntpoint" | grep -q tmpfs; do umount $mntpoint || sleep 1 done Index: user/pho/stress2/misc/tmpfs8.sh =================================================================== --- user/pho/stress2/misc/tmpfs8.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs8.sh (revision 278501) @@ -1,174 +1,174 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Demonstrate rename(2) cache problem for tmpfs(5). Fixed in r226987. # Variation of rename6.sh . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > tmpfs8.c -cc -o tmpfs8 -Wall -Wextra -O2 tmpfs8.c +mycc -o tmpfs8 -Wall -Wextra -O2 tmpfs8.c rm -f tmpfs8.c cd $here mount | grep $mntpoint | grep -q tmpfs && umount -f $mntpoint mount -t tmpfs tmpfs $mntpoint chmod 777 $mntpoint su ${testuser} -c "cd $mntpoint; /tmp/tmpfs8" while mount | grep $mntpoint | grep -q tmpfs; do umount $mntpoint || sleep 1 done rm -f /tmp/tmpfs8 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include pid_t spid; const char *logfile = "test.log"; char new[128]; void cleanup() { kill(spid, SIGINT); } static void Stat() { struct stat sb; int i; setproctitle("Stat"); for (;;) { for (i = 0; i < 1000; i++) { stat(logfile, &sb); stat(new, &sb); } // usleep(1000); usleep(100); } } int main(void) { struct stat sb1, sb2, sb3; int fd, i, r1, r2, r3; if ((spid = fork()) == 0) Stat(); setproctitle("main"); atexit(cleanup); for (i = 0; i < 200000; i++) { bzero(&sb1, sizeof(sb1)); bzero(&sb2, sizeof(sb2)); if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "creat(%s)", logfile); close(fd); sprintf(new, "test.log.%05d", i); if ((fd = open(new, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) err(1, "creat(%s)", new); write(fd, "xxx", 3); close(fd); if ((r3 = stat(new, &sb3)) == -1) err(1, "stat(%s)", new); #if 1 if (rename(logfile, new) == -1) warn("rename(%s, %s)", logfile, new); #else /* No cache problem is seen */ if (link(logfile, new) == -1) err(1, "link(%s, %s)", logfile, new); if (unlink(logfile) == -1) err(1, "unlink(%s)", logfile); #endif /* * stat() for logfile and new will be identical sometimes, * but only when Stat() is running. */ r1 = stat(logfile, &sb1); r2 = stat(new, &sb2); if (r1 == 0 && r2 == 0 && bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { fprintf(stderr, "FAIL 1\n"); fprintf(stderr, "%-15s: ino = %4d, nlink = %d, size = %jd\n", logfile, sb1.st_ino, sb1.st_nlink, sb1.st_blocks); fprintf(stderr, "%-15s: ino = %4d, nlink = %d, size = %jd\n", new , sb2.st_ino, sb2.st_nlink, sb2.st_blocks); } if (bcmp(&sb2, &sb3, sizeof(sb2)) == 0) { fprintf(stderr, "Old to file is lingering\n"); } if (sb2.st_ino == sb3.st_ino) { fprintf(stderr, "FAIL 2\n"); if (r1 == 0) fprintf(stderr, "sb1: %-15s: ino = %4d, nlink = %d, size = %jd\n", logfile, sb1.st_ino, sb1.st_nlink, sb1.st_blocks); if (r2 == 0) fprintf(stderr, "sb2: %-15s: ino = %4d, nlink = %d, size = %jd\n", new, sb2.st_ino, sb2.st_nlink, sb2.st_blocks); if (r3 == 0) fprintf(stderr, "sb3: %-15s: ino = %4d, nlink = %d, size = %jd\n", new , sb3.st_ino, sb3.st_nlink, sb3.st_blocks); exit(1); } unlink(new); } kill(spid, SIGINT); wait(NULL); return (0); } Index: user/pho/stress2/misc/tmpfs9.sh =================================================================== --- user/pho/stress2/misc/tmpfs9.sh (revision 278500) +++ user/pho/stress2/misc/tmpfs9.sh (revision 278501) @@ -1,113 +1,113 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Regression test: exec returning EIO problem scenario for tmpfs . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > tmpfs9.c -cc -o tmpfs9 -Wall -Wextra -O2 tmpfs9.c +mycc -o tmpfs9 -Wall -Wextra -O2 tmpfs9.c rm -f tmpfs9.c cd $here mount | grep $mntpoint | grep -q tmpfs && umount -f $mntpoint mount -t tmpfs tmpfs $mntpoint chmod 777 $mntpoint cp /usr/bin/true $mntpoint su ${testuser} -c "/tmp/tmpfs9 $mntpoint" & while kill -0 $! 2>/dev/null; do ../testcases/swap/swap -t 2m -i 40 -h done wait while mount | grep $mntpoint | grep -q tmpfs; do umount $mntpoint || sleep 1 done rm -d /tmp/tmpfs9 exit EOF #include #include #include #include #include #include #include #include #define N 5000 #define PARALLEL 10 const char path[] = "./true"; void test(void) { pid_t p; int i; for (i = 0; i < N; i++) { if ((p = fork()) == 0) if (execl(path, path, (char *)0) == -1) err(1, "exec(%s)", path); if (p > 0) wait(NULL); } _exit(0); } int main(int argc, char **argv) { int i, status; if (argc != 2) errx(1, "Usage: %s ", argv[0]); if (chdir(argv[1]) == -1) err(1, "chdir(%s)", argv[1]); for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) { wait(&status); if (status != 0) return (1); } return (0); } Index: user/pho/stress2/misc/truncate.sh =================================================================== --- user/pho/stress2/misc/truncate.sh (revision 278500) +++ user/pho/stress2/misc/truncate.sh (revision 278501) @@ -1,101 +1,101 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test high water mark for freeblks . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > truncate.c -cc -o truncate -Wall -Wextra -O2 truncate.c || exit 1 +mycc -o truncate -Wall -Wextra -O2 truncate.c || exit 1 rm -f truncate.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR /tmp/truncate rm -f /tmp/truncate exit 0 EOF #include #include #include #include #include #include #include #define SIZ 512 char buf[SIZ]; void test(void) { time_t start; int fd[10], i, j; char name[128]; for (j = 0; j < 10; j++) { sprintf(name, "%05d.%05d", getpid(), j); if ((fd[j] = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) err(1, "%s", name); unlink(name); } start = time(NULL); for (i = 0; i < 100000; i++) { if (time(NULL) - start > 1200) break; for (j = 0; j < 10; j++) { if (write(fd[j], buf, 2) != 2) err(1, "write"); if (ftruncate(fd[j], 0) == -1) err(1, "ftruncate"); } } _exit(0); } int main(void) { int i, status; for (i = 0; i < 20; i++) { if (fork() == 0) test(); } for (i = 0; i < 20; i++) wait(&status); return (0); } Index: user/pho/stress2/misc/truncate2.sh =================================================================== --- user/pho/stress2/misc/truncate2.sh (revision 278500) +++ user/pho/stress2/misc/truncate2.sh (revision 278501) @@ -1,101 +1,101 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > truncate2.c -cc -o truncate2 -Wall -O2 truncate2.c +mycc -o truncate2 -Wall -O2 truncate2.c rm -f truncate2.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR /tmp/truncate2 & sleep 1 while ps | grep -v grep | egrep -q "truncate2$"; do $here/../testcases/swap/swap -t 2m -i 20 done rm -f /tmp/truncate2 exit 0 EOF #include #include #include #include #include #include #define SIZ 512 char buf[SIZ]; void test(void) { int fd[10], i, j; char name[128]; off_t len; for (j = 0; j < 10; j++) { sprintf(name, "%05d.%05d", getpid(), j); fd[j] = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); if (fd[j] == -1) err(1, "%s", name); unlink(name); } for (i = 0; i < 100; i++) { for (j = 0; j < 10; j++) { if (write(fd[j], buf, 2) != 2) err(1, "write"); len = arc4random() % 1024 * 1024; if (ftruncate(fd[j], len) == -1) err(1, "ftruncate"); } } exit(0); } int main(int argc, char **argv) { int i, status; for (i = 0; i < 20; i++) { if (fork() == 0) test(); } for (i = 0; i < 20; i++) wait(&status); return (0); } Index: user/pho/stress2/misc/truncate3.sh =================================================================== --- user/pho/stress2/misc/truncate3.sh (revision 278500) +++ user/pho/stress2/misc/truncate3.sh (revision 278501) @@ -1,124 +1,124 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/rename.sh 191485 2009-04-25 10:19:36Z pho $ # # Variation of truncate2.sh whih FS check added. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 400m -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}${part} > /dev/null mount /dev/md${mdstart}${part} $mntpoint export RUNDIR=$mntpoint/stressX here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > truncate3.c -cc -o truncate3 -Wall -O2 truncate3.c +mycc -o truncate3 -Wall -O2 truncate3.c rm -f truncate3.c [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR /tmp/truncate3 cd $here rm -f /tmp/truncate3 sync;sync;sync while mount | grep -q $mntpoint; do sync;sync;sync sleep 1 umount $mntpoint done if fsck -n -t ufs /dev/md${mdstart}${part} | egrep -q "BAD|WRONG"; then fsck -n -t ufs /dev/md${mdstart}${part} fi mdconfig -d -u $mdstart exit 0 EOF #include #include #include #include #include #include #define SIZ 512 char buf[SIZ]; void test(void) { int fd[10], i, j; char name[128]; off_t len; for (j = 0; j < 10; j++) { sprintf(name, "%05d.%05d", getpid(), j); fd[j] = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); if (fd[j] == -1) err(1, "open(%s)", name); unlink(name); } for (i = 0; i < 100; i++) { for (j = 0; j < 10; j++) { if (write(fd[j], buf, 2) != 2) err(1, "write"); len = arc4random() % 1024 * 1024; if (ftruncate(fd[j], len) == -1) err(1, "ftruncate"); } } exit(0); } int main(int argc, char **argv) { int i, status; for (i = 0; i < 20; i++) { if (fork() == 0) test(); } for (i = 0; i < 20; i++) wait(&status); return (0); } Index: user/pho/stress2/misc/truncate5.sh =================================================================== --- user/pho/stress2/misc/truncate5.sh (revision 278500) +++ user/pho/stress2/misc/truncate5.sh (revision 278501) @@ -1,110 +1,110 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/rename.sh 191485 2009-04-25 10:19:36Z pho $ # # "panic: handle_workitem_freeblocks: inode 447489 block count 336" seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q "$mntpoint" && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart bsdlabel -w md${mdstart} auto newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > truncate5.c -cc -o truncate5 -Wall -Wextra -O2 truncate5.c +mycc -o truncate5 -Wall -Wextra -O2 truncate5.c rm -f truncate5.c export RUNDIR=$mntpoint/stressX [ -d $RUNDIR ] || mkdir -p $RUNDIR cd $RUNDIR /tmp/truncate5 cd $here rm -f /tmp/truncate5 while mount | grep -q md${mdstart}$part; do umount $mntpoint || sleep 1 done if fsck -n -t ufs /dev/md${mdstart}$part | egrep -q "BAD|WRONG"; then fsck -n -t ufs /dev/md${mdstart}$part fi mdconfig -d -u $mdstart exit 0 EOF #include #include #include #include #include #include #define SIZ 4096 char buf[SIZ]; int main() { int fd, i, j; char name[128]; off_t len = 21474837416LL; off_t pos; srand48(getpid()); sprintf(name, "%05d.%05d", getpid(), 0); fd = open(name, O_WRONLY | O_CREAT, 0666); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); unlink(name); sleep(1); for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { pos = lrand48() % (len - sizeof(buf)); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek"); if (write(fd, buf, sizeof(buf)) != sizeof(buf)) err(1, "write"); } } close(fd); return (0); } Index: user/pho/stress2/misc/umountf2.sh =================================================================== --- user/pho/stress2/misc/umountf2.sh (revision 278500) +++ user/pho/stress2/misc/umountf2.sh (revision 278501) @@ -1,72 +1,72 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by kris@freebsd.org # Test problems with "umount -f and fsx. Results in a "KDB: enter: watchdog timeout" # http://people.freebsd.org/~pho/stress/log/kostik745.txt # Fixed by r275743 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg fsxc=`find -x /usr/src -name fsx.c | tail -1` [ -z "$fsxc" ] && fsxc=`find -x / -name fsx.c | tail -1` [ -z "$fsxc" ] && exit -cc -o /tmp/fsx $fsxc +mycc -o /tmp/fsx $fsxc D=$diskimage dede $D 1m 1k || exit 1 mount | grep "$mntpoint" | grep md${mdstart}$part > /dev/null && umount $mntpoint mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u $mdstart mdconfig -a -t vnode -f $D -u $mdstart bsdlabel -w md$mdstart auto newfs md${mdstart}$part > /dev/null 2>&1 mount /dev/md${mdstart}$part $mntpoint sleep 5 for i in `jot 100`; do /tmp/fsx -S $i -q ${mntpoint}/xxx$i > /dev/null & done sleep 30 umount -f $mntpoint & for i in `jot 10`; do sleep 30 pgrep -q fsx || break done pgrep -q fsx && echo FAIL && pkill fsx sleep 5 wait mdconfig -d -u $mdstart rm -f $D /tmp/fsx Index: user/pho/stress2/misc/umountf3.sh =================================================================== --- user/pho/stress2/misc/umountf3.sh (revision 278500) +++ user/pho/stress2/misc/umountf3.sh (revision 278501) @@ -1,120 +1,120 @@ #!/bin/sh # # Copyright (c) 2008 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Demonstrate livelock with "umount -f" seen both with UFS and MSDOS [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg D=$diskimage dede $D 1m 1k || exit 1 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > umountf3.c -cc -o umountf3 -Wall umountf3.c +mycc -o umountf3 -Wall umountf3.c rm -f umountf3.c cd $odir mount | grep "$mntpoint" | grep md${mdstart} > /dev/null && umount $mntpoint mdconfig -l | grep md${mdstart} > /dev/null && mdconfig -d -u ${mdstart} mdconfig -a -t vnode -f $D -u ${mdstart} bsdlabel -w md${mdstart} auto newfs md${mdstart}${part} > /dev/null 2>&1 mount /dev/md${mdstart}${part} $mntpoint export RUNDIR=$mntpoint/stressX for i in `jot 25`; do (cd /$mntpoint; /tmp/umountf3) & done sleep $((4 * 60)) echo "umount -f $mntpoint" umount -f $mntpoint mdconfig -d -u $mdstart rm -f $D /tmp/umountf3 exit EOF #include #include #include #include #include #include #include static unsigned long size = 1024 * 1024 * 2; int main(int argc, char **argv) { int buf[1024], index, to, n; int fd; char file[128]; sprintf(file,"p%06d", getpid()); if ((fd = open(file, O_CREAT | O_RDWR, 0666)) == -1) err(1, "creat(%s)", file); to = sizeof(buf); for (;;) { index = 0; while (index < size) { if (index + to > size) to = size - index; index += to; if (write(fd, buf, to) != to) err(1, "write(%s), %s:%d", file, __FILE__, __LINE__); } if (lseek(fd, 0, 0) == -1) err(1, "lseek"); index = 0; while (index < size) { if (index + to > size) to = size - index; if ((n = read(fd, buf, to)) != to) err(1, "rw read(%d, %d, %d). %s.%d", n, to, index, __FILE__, __LINE__); index += to; } if (lseek(fd, 0, 0) == -1) err(1, "lseek"); } if (close(fd) == -1) err(1, "close(%s), %s:%d", file, __FILE__, __LINE__); if (unlink(file) == -1) err(1, "unlink(%s), %s:%d", file, __FILE__, __LINE__); return (0); } Index: user/pho/stress2/misc/umountf7.sh =================================================================== --- user/pho/stress2/misc/umountf7.sh (revision 278500) +++ user/pho/stress2/misc/umountf7.sh (revision 278501) @@ -1,168 +1,168 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # "panic: handle_written_inodeblock: live inodedep 0xcc731200" seen. # http://people.freebsd.org/~pho/stress/log/umountf7.txt # Problem only seen with SU+J. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/umountf7.c -cc -o umountf7 -Wall -Wextra umountf7.c -lpthread || exit 1 +mycc -o umountf7 -Wall -Wextra umountf7.c -lpthread || exit 1 rm -f umountf7.c cd $odir mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 3g -u $mdstart || exit 1 bsdlabel -w md$mdstart auto newfs -j md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint daemon sh -c '(cd ../testcases/swap; ./swap -t 2m -i 4)' parallel=4 for j in `jot $parallel`; do [ -d $mntpoint/$j ] || mkdir $mntpoint/$j done for j in `jot $parallel`; do (cd $mntpoint/$j; /tmp/umountf7 100000) & done sleep 30 umount -f $mntpoint pkill umountf7 wait while pkill -9 swap; do : done find $mntpoint -type f while mount | grep "on $mntpoint " | grep -q /dev/md; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/umountf7 exit EOF #include #include #include #include #include #include pid_t pid; volatile int n, n2; int mx; void * cr(void *arg __unused) { char file[80]; int fd, i; for (i = 0; i < mx; i++) { snprintf(file, sizeof(file), "f%06d.%06d", pid, i); if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "open(%s)", file); close(fd); n++; } return (0); } void * mv(void *arg __unused) { char from[80], to[80]; int i; for (i = 0; i < mx; i++) { while (n == -1 || i > n) pthread_yield(); snprintf(from, sizeof(from), "f%06d.%06d", pid, i); snprintf(to , sizeof(to ), "g%06d.%06d", pid, i); if (rename(from, to) == -1) warn("rename(%s, %s)", from, to); n2++; } return (0); } void * rm(void *arg __unused) { char file[80]; int i; for (i = 0; i < mx; i++) { while (n2 == -1 || i > n2) pthread_yield(); snprintf(file, sizeof(file), "g%06d.%06d", pid, i); if (unlink(file) == -1) warn("unlink(%s)", file); } return (0); } int main(int argc, char **argv) { pthread_t rp[3]; int i; if (argc != 2) errx(1, "Usage: %s ", argv[0]); mx = atoi(argv[1]); n = n2 = -1; pid = getpid(); if (pthread_create(&rp[0], NULL, cr, NULL) != 0) err(1, "pthread_create"); usleep(arc4random() % 1000); if (pthread_create(&rp[1], NULL, mv, NULL) != 0) err(1, "pthread_mv"); usleep(arc4random() % 1000); if (pthread_create(&rp[2], NULL, rm, NULL) != 0) perror("pthread_rm"); for (i = 0; i < 3; i++) pthread_join(rp[i], NULL); return (0); } Index: user/pho/stress2/misc/vfork.sh =================================================================== --- user/pho/stress2/misc/vfork.sh (revision 278500) +++ user/pho/stress2/misc/vfork.sh (revision 278501) @@ -1,125 +1,128 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Regression test for r246484. +. ../default.cfg + +cd /tmp cat > vfork1.c <<- EOF #include #include #include int main(void) { pid_t pid; fprintf(stderr, "%d\n", getpid()); if ((pid = vfork()) == 0) { #if 0 if (ptrace(PT_TRACE_ME, 0, 0, 0) == -1) err(1, "PT_TRACEME"); #endif sleep(30); _exit(0); } if (pid == -1) err(1, "vfork"); return (0); } EOF -cc -o vfork1 -Wall -Wextra -g vfork1.c +mycc -o vfork1 -Wall -Wextra -g vfork1.c rm vfork1.c cat > vfork2.c <<- EOF #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { pid_t pid, rpid; struct rusage ru; int status; if (argc != 2) errx(1, "Usage: %s ", argv[0]); pid = atoi(argv[1]); if (pid == -1) err(1, "fork()"); if (ptrace(PT_ATTACH, pid, NULL, 0) == -1) err(1, "ptrace(%d) attach", pid); if (wait(NULL) == -1) err(1, "wait"); bzero(&ru, sizeof(ru)); usleep(2000); if ((rpid = wait4(-1, &status, WNOHANG, &ru)) == -1) { err(1, "OK wait4"); } if (rpid == 0) { // fprintf(stderr, "No rusage info.\n"); if (ptrace(PT_DETACH, pid, NULL, 0) == -1) err(1, "ptrace(%d) detach", pid); if (wait(&status) == -1) err(1, "wait"); } else { fprintf(stderr, "FAIL Got unexpected rusage.\n"); if (ru.ru_utime.tv_sec != 0) fprintf(stderr, "FAIL tv_sec\n"); } if (status != 0x4000) fprintf(stderr, "FAIL Child exit status 0x%x\n", status); return (0); } EOF -cc -o vfork2 -Wall -Wextra -g vfork2.c +mycc -o vfork2 -Wall -Wextra -g vfork2.c rm vfork2.c ./vfork1 & sleep .2 childpid=`ps -l | grep -v grep | grep vfork1 | tail -1 | grep nanslp | awk '{print $2}'` # Seen before fix: # failed to set signal flags properly for ast() ./vfork2 $childpid rm -f vfork1 vfork2 Index: user/pho/stress2/misc/vnodes.sh =================================================================== --- user/pho/stress2/misc/vnodes.sh (revision 278500) +++ user/pho/stress2/misc/vnodes.sh (revision 278501) @@ -1,83 +1,83 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Demonstrate vnode leak # Test scenario by Petr Salinger . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > vnodes.c -cc -o vnodes -Wall -O2 vnodes.c +mycc -o vnodes -Wall -O2 vnodes.c rm -f vnodes.c old=`sysctl vfs.numvnodes | tail -1 | sed 's/.*: //'` /tmp/vnodes new=`sysctl vfs.numvnodes | tail -1 | sed 's/.*: //'` [ $((new - old)) -gt 100 ] && echo "FAIL vnode leak" rm -f /tmp/vnodes exit 0 EOF #include #include #include #include #include #include char dname[]= "/dev/ptyrX"; void leak(void) { int i, fd; if (fork() == 0) { for (i = '0'; i < '9'; i ++) { dname[9] = i; fd = open(dname, O_RDWR); } exit(0); } wait(NULL); } int main() { int i; for (i = 0 ;i < 100000; i++) { leak(); } return 0; } Index: user/pho/stress2/misc/vunref.sh =================================================================== --- user/pho/stress2/misc/vunref.sh (revision 278500) +++ user/pho/stress2/misc/vunref.sh (revision 278501) @@ -1,225 +1,225 @@ #!/bin/sh # # Copyright (c) 2010 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: projects/stress2/misc/umountf4.sh 197027 2009-09-09 10:13:56Z pho $ # # Vnode reference leak test scenario by kib@. # Will fail with "umount: unmount of /mnt5 failed: Device busy" # vnode leak not seen on HEAD. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` mounts=2 # Number of parallel scripts D=$diskimage [ -d "$RUNDIR" ] || mkdir $RUNDIR cd $RUNDIR if [ $# -eq 0 ]; then sed '1,/^EOF/d' < $here/$0 > vunref.c - cc -o vunref -Wall -Wextra -O2 vunref.c + mycc -o /tmp/vunref -Wall -Wextra -O2 vunref.c rm -f vunref.c cd $here rm -f $RUNDIR/active.* for i in `jot $mounts`; do m=$(( i + mdstart - 1 )) [ ! -d ${mntpoint}$m ] && mkdir ${mntpoint}$m mount | grep "$mntpoint" | grep -q md$m && umount -f ${mntpoint}$m mdconfig -l | grep -q md$m && mdconfig -d -u $m dede $D.$m 1m 10 mdconfig -a -t vnode -f $D.$m -u $m bsdlabel -w md$m auto newfs md${m}$part > /dev/null 2>&1 done # start the parallel tests for i in `jot $mounts`; do m=$((i + mdstart - 1)) $0 mmap $m & sleep 0.2 $0 $m & done sleep 2 while [ ! -z "`ls $RUNDIR/active.* 2>/dev/null`" ] ; do ../testcases/swap/swap -t 2m -i 20 done for i in `jot $mounts`; do wait; wait done for i in `jot $mounts`; do m=$((i + mdstart - 1)) mdconfig -d -u $m rm -f $D$m done - rm -f $RUNDIR/vunref $RUNDIR/active.* $diskimage.* ${mntpoint}*/p* + rm -f /tmp/vunref $RUNDIR/active.* $diskimage.* ${mntpoint}*/p* else if [ $1 = mmap ]; then touch $RUNDIR/active.$2 for i in `jot 500`; do cd ${mntpoint}$2 - $RUNDIR/vunref > /dev/null 2>&1 + /tmp/vunref > /dev/null 2>&1 cd / [ -f $RUNDIR/active.$2 ] || exit sleep 0.1 done rm -f $RUNDIR/active.$2 else # The test: Parallel mount and unmounts m=$1 mount $opt /dev/md${m}$part ${mntpoint}$m while [ -f $RUNDIR/active.$m ] ; do sleep 0.1 n=0 while mount | grep -qw $mntpoint$m; do umount ${mntpoint}$m > /dev/null 2>&1 && n=0 n=$((n + 1)) if [ $n -gt 600 ]; then echo "*** Leak detected ***" fstat $mntpoint$m rm -f $RUNDIR/active.* exit 1 fi sleep 0.1 done mount $opt /dev/md${m}$part ${mntpoint}$m done mount | grep "$mntpoint" | grep -q md$m && umount ${mntpoint}$m fi fi exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INPUTFILE "/bin/date" int test(void) { int i; pid_t pid; char file[128]; int fdin, fdout; char *src, *dst; struct stat statbuf; pid = getpid(); for (i = 0; i < 100; i++) { sprintf(file,"p%05d.%05d", pid, i); if ((fdin = open(INPUTFILE, O_RDONLY)) < 0) err(1, INPUTFILE); if ((fdout = open(file, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "%s", file); if (fstat(fdin, &statbuf) < 0) err(1, "fstat error"); if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) == -1) err(1, "lseek error"); /* write a dummy byte at the last location */ if (write(fdout, "", 1) != 1) err(1, "write error"); if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) == (caddr_t) - 1) err(1, "mmap error for input"); if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdout, 0)) == (caddr_t) - 1) err(1, "mmap error for output"); memcpy(dst, src, statbuf.st_size); if (munmap(src, statbuf.st_size) == -1) err(1, "munmap"); close(fdin); if (munmap(dst, statbuf.st_size) == -1) err(1, "munmap"); close(fdout); if (unlink(file) == -1) err(3, "unlink(%s)", file); } return (0); } int main() { int i; char path[MAXPATHLEN+1]; struct statfs buf; if (getcwd(path, sizeof(path)) == NULL) err(1, "getcwd()"); if (statfs(path, &buf) < 0) err(1, "statfs(%s)", path); if (!strcmp(buf.f_mntonname, "/")) return (1); for (i = 0; i < 2; i++) { if (fork() == 0) test(); } for (i = 0; i < 2; i++) wait(NULL); return (0); } Index: user/pho/stress2/misc/wire_no_page.sh =================================================================== --- user/pho/stress2/misc/wire_no_page.sh (revision 278500) +++ user/pho/stress2/misc/wire_no_page.sh (revision 278501) @@ -1,105 +1,107 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # Test scenario by kib@ # "panic: vm_page_set_invalid: page 0xc3dfe8c0 is busy" seen. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c -cc -o wire_no_page -Wall -Wextra wire_no_page.c -lpthread || exit 1 +mycc -o wire_no_page -Wall -Wextra wire_no_page.c -lpthread || exit 1 rm -f wire_no_page.c cd $odir cp /tmp/wire_no_page /tmp/wire_no_page2 for i in `jot 100`; do for j in `jot 50`; do /tmp/wire_no_page /tmp/wire_no_page2 & done for j in `jot 50`; do wait done done rm -f /tmp/wire_no_page /tmp/wire_no_page2 exit EOF /* $Id: wire_no_page.c,v 1.1 2013/05/17 07:50:30 kostik Exp kostik $ */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { struct stat st; char *p1, *p2; size_t len; pid_t child; int error, fd; if (argc < 2) errx(1, "file name ?"); fd = open(argv[1], O_RDWR); if (fd == -1) err(1, "open %s", argv[1]); error = fstat(fd, &st); if (error == -1) err(1, "stat"); len = round_page(st.st_size); p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ((void *)p1 == MAP_FAILED) err(1, "mmap"); error = mlock(p1, len); if (error == -1) err(1, "mlock"); p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ((void *)p2 == MAP_FAILED) err(1, "mmap"); error = msync(p2, len, MS_SYNC | MS_INVALIDATE); if (error == -1) err(1, "msync"); child = fork(); if (child == -1) err(1, "fork"); else if (child == 0) _exit(0); return (0); }