1#!/bin/sh 2 3# 4# Copyright (c) 2013 EMC Corp. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28 29# "Sleeping thread (tid 101094, pid 13104) owns a non-sleepable lock" seen. 30# Fixed in r255798. 31 32# panic: Memory modified after free: 33# https://people.freebsd.org/~pho/stress/log/alan011.txt 34# https://people.freebsd.org/~pho/stress/log/kevent6.txt 35# Fixed by: r286921 36 37[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 38. ../default.cfg 39 40odir=`pwd` 41 42cd /tmp 43sed '1,/^EOF/d' < $odir/$0 > kevent6.c 44mycc -o kevent6 -Wall -Wextra -O2 -g kevent6.c -lpthread || exit 1 45rm -f kevent6.c 46cd $odir 47 48mount | grep "on $mntpoint " | grep -q md$mdstart && umount -f $mntpoint 49mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart 50 51mdconfig -a -t swap -s 2g -u $mdstart 52newfs $newfs_flags md$mdstart > /dev/null 53mount /dev/md$mdstart $mntpoint 54chmod 777 $mntpoint 55 56su $testuser -c "(cd $mntpoint; /tmp/kevent6)" 57 58while mount | grep -q $mntpoint; do 59 umount $mntpoint || sleep 1 60done 61mdconfig -d -u $mdstart 62 63mount -o size=1g -t tmpfs tmpfs $mntpoint 64chmod 777 $mntpoint 65su $testuser -c "(cd $mntpoint; /tmp/kevent6)" 66while mount | grep -q $mntpoint; do 67 umount $mntpoint || sleep 1 68done 69rm -f /tmp/kevent6 70 71exit 72EOF 73#include <sys/types.h> 74#include <sys/event.h> 75#include <sys/mman.h> 76#include <sys/wait.h> 77 78#include <err.h> 79#include <errno.h> 80#include <fcntl.h> 81#include <pthread.h> 82#include <sched.h> 83#include <signal.h> 84#include <stdio.h> 85#include <stdlib.h> 86#include <string.h> 87#include <unistd.h> 88 89#define LOOPS 500000 90#define PARALLEL 8 91 92static int fd; 93static char path[80]; 94 95static void * 96spin(void *arg __unused) 97{ 98 int i; 99 100 for (i= 0;; i++) { 101 snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); 102 if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == 103 -1) 104 err(1, "creat()"); 105 close(fd); 106 usleep(10000); 107 fd = 0; 108 unlink(path); 109 } 110 return (NULL); 111} 112 113static void * 114test(void *arg __unused) 115{ 116 int kq; 117 int i, n; 118 struct kevent ev; 119 struct timespec ts; 120 121 for (i = 0; i < LOOPS; i++) { 122 if ((kq = kqueue()) < 0) 123 err(1, "kqueue()"); 124 125 n = 0; 126 memset(&ev, 0, sizeof(ev)); 127 EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, 128 NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); 129 n++; 130 131 if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) { 132 close(kq); 133 continue; 134 } 135 136 memset(&ev, 0, sizeof(ev)); 137 ts.tv_sec = 0; 138 ts.tv_nsec = 1000000; 139 if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) 140 err(1, "kevent()"); 141 142 close(kq); 143 } 144 return (NULL); 145} 146 147int 148main(void) 149{ 150 pthread_t cp[PARALLEL], sp; 151 int e, i; 152 153 if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0) 154 errc(1, e, "pthread_create"); 155 156 for (i = 0; i < PARALLEL; i++) { 157 if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0) 158 errc(1, e, "pthread_create"); 159 } 160 161 for (i = 0; i < PARALLEL; i++) 162 pthread_join(cp[i], NULL); 163 164 close(fd); 165 166 return (0); 167} 168