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 52bsdlabel -w md$mdstart auto 53newfs $newfs_flags md${mdstart}$part > /dev/null 54mount /dev/md${mdstart}$part $mntpoint 55chmod 777 $mntpoint 56 57su $testuser -c "(cd $mntpoint; /tmp/kevent6)" 58 59while mount | grep -q $mntpoint; do 60 umount $mntpoint || sleep 1 61done 62mdconfig -d -u $mdstart 63 64mount -o size=1g -t tmpfs tmpfs $mntpoint 65chmod 777 $mntpoint 66su $testuser -c "(cd $mntpoint; /tmp/kevent6)" 67while mount | grep -q $mntpoint; do 68 umount $mntpoint || sleep 1 69done 70rm -f /tmp/kevent6 71 72exit 73EOF 74#include <sys/types.h> 75#include <sys/event.h> 76#include <sys/mman.h> 77#include <sys/wait.h> 78 79#include <err.h> 80#include <errno.h> 81#include <fcntl.h> 82#include <pthread.h> 83#include <sched.h> 84#include <signal.h> 85#include <stdio.h> 86#include <stdlib.h> 87#include <string.h> 88#include <unistd.h> 89 90#define LOOPS 500000 91#define PARALLEL 8 92 93static int fd; 94static char path[80]; 95 96static void * 97spin(void *arg __unused) 98{ 99 int i; 100 101 for (i= 0;; i++) { 102 snprintf(path, sizeof(path), "file.%06d.%d", getpid(), i); 103 if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == 104 -1) 105 err(1, "creat()"); 106 close(fd); 107 usleep(10000); 108 fd = 0; 109 unlink(path); 110 } 111 return (NULL); 112} 113 114static void * 115test(void *arg __unused) 116{ 117 int kq; 118 int i, n; 119 struct kevent ev; 120 struct timespec ts; 121 122 for (i = 0; i < LOOPS; i++) { 123 if ((kq = kqueue()) < 0) 124 err(1, "kqueue()"); 125 126 n = 0; 127 memset(&ev, 0, sizeof(ev)); 128 EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, 129 NOTE_DELETE|NOTE_RENAME|NOTE_EXTEND, 0, 0); 130 n++; 131 132 if (kevent(kq, &ev, n, NULL, 0, NULL) < 0) { 133 close(kq); 134 continue; 135 } 136 137 memset(&ev, 0, sizeof(ev)); 138 ts.tv_sec = 0; 139 ts.tv_nsec = 1000000; 140 if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) == -1) 141 err(1, "kevent()"); 142 143 close(kq); 144 } 145 return (NULL); 146} 147 148int 149main(void) 150{ 151 pthread_t cp[PARALLEL], sp; 152 int e, i; 153 154 if ((e = pthread_create(&sp, NULL, spin, NULL)) != 0) 155 errc(1, e, "pthread_create"); 156 157 for (i = 0; i < PARALLEL; i++) { 158 if ((e = pthread_create(&cp[i], NULL, test, NULL)) != 0) 159 errc(1, e, "pthread_create"); 160 } 161 162 for (i = 0; i < PARALLEL; i++) 163 pthread_join(cp[i], NULL); 164 165 close(fd); 166 167 return (0); 168} 169