18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# 48a272653SPeter Holm# Copyright (c) 2014 EMC Corp. 58a272653SPeter Holm# All rights reserved. 68a272653SPeter Holm# 78a272653SPeter Holm# Redistribution and use in source and binary forms, with or without 88a272653SPeter Holm# modification, are permitted provided that the following conditions 98a272653SPeter Holm# are met: 108a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright 118a272653SPeter Holm# notice, this list of conditions and the following disclaimer. 128a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 138a272653SPeter Holm# notice, this list of conditions and the following disclaimer in the 148a272653SPeter Holm# documentation and/or other materials provided with the distribution. 158a272653SPeter Holm# 168a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 178a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 188a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 198a272653SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 208a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 218a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 228a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 238a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 248a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268a272653SPeter Holm# SUCH DAMAGE. 278a272653SPeter Holm# 288a272653SPeter Holm 298a272653SPeter Holm# Test multiple (parallel) core dumps and mount / umount. 308a272653SPeter Holm# mount(8) stuck in "ufs" or "tmpfs". 318a272653SPeter Holm# http://people.freebsd.org/~pho/stress/log/kostik724.txt 328a272653SPeter Holm# Fixed by r272535. 338a272653SPeter Holm# On i386 pgrep(1) loops. Fixed by r272566. 348a272653SPeter Holm 358a272653SPeter Holm# "Sleeping on "pmapdi" with the following non-sleepable locks held:" 368a272653SPeter Holm# https://people.freebsd.org/~pho/stress/log/kostik883.txt 378a272653SPeter Holm 388a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 398a272653SPeter Holm. ../default.cfg 408a272653SPeter Holm 418a272653SPeter Holmodir=`pwd` 428a272653SPeter Holm 438a272653SPeter Holmcd /tmp 448a272653SPeter Holmsed '1,/^EOF/d' < $odir/$0 > core3.c 458a272653SPeter Holmmycc -o core3 -Wall -Wextra -O2 core3.c || exit 1 468a272653SPeter Holmrm -f core3.c 478a272653SPeter Holmcd $odir 488a272653SPeter Holm 498a272653SPeter Holmmount | grep -q "on $mntpoint " && umount $mntpoint 508a272653SPeter Holm[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 518a272653SPeter Holmmdconfig -a -t swap -s 1g -u $mdstart 52*608c97bfSPeter Holmnewfs $newfs_flags md$mdstart > /dev/null 53*608c97bfSPeter Holmmount /dev/md$mdstart $mntpoint 548a272653SPeter Holmmkdir $mntpoint/d 558a272653SPeter Holmchmod 777 $mntpoint/d 568a272653SPeter Holm 578a272653SPeter Holmsu $testuser -c "/tmp/core3 $mntpoint/d" & 588a272653SPeter Holmpid=$! 598a272653SPeter Holmsleep 1 608a272653SPeter Holm 618a272653SPeter Holmwhile pgrep -q core3; do 628a272653SPeter Holm [ -d $mntpoint/d ] && 638a272653SPeter Holm umount -f $mntpoint 648a272653SPeter Holmdone > /dev/null 2>&1 & 658a272653SPeter Holmwhile pgrep -q core3; do 668a272653SPeter Holm [ -d $mntpoint/d ] || 67*608c97bfSPeter Holm mount /dev/md$mdstart $mntpoint 688a272653SPeter Holmdone > /dev/null 2>&1 698a272653SPeter Holmwait $pid 708a272653SPeter Holmstatus=$? 718a272653SPeter Holmmount | grep -q "on $mntpoint " && 728a272653SPeter Holm umount -f $mntpoint 738a272653SPeter Holmmdconfig -d -u $mdstart 748a272653SPeter Holm[ $status -ne 0 ] && exit $status 758a272653SPeter Holm 768a272653SPeter Holm# tmpfs 778a272653SPeter Holmmount -o size=1g -t tmpfs tmpfs $mntpoint 788a272653SPeter Holmsu $testuser -c "/tmp/core3 $mntpoint/d" & 798a272653SPeter Holmpid=$! 808a272653SPeter Holmsleep 1 818a272653SPeter Holm 828a272653SPeter Holmwhile pgrep -q core3; do 838a272653SPeter Holm [ -d $mntpoint/d ] && 848a272653SPeter Holm umount -f $mntpoint 858a272653SPeter Holmdone > /dev/null & 868a272653SPeter Holmwhile pgrep -q core3; do 878a272653SPeter Holm if [ ! -d $mntpoint/d ]; then 888a272653SPeter Holm mount -t tmpfs tmpfs $mntpoint 898a272653SPeter Holm mkdir $mntpoint/d 908a272653SPeter Holm fi 918a272653SPeter Holmdone 928a272653SPeter Holmwait $pid 938a272653SPeter Holmstatus=$? 948a272653SPeter Holmfor i in `jot 5` ; do 958a272653SPeter Holm mount | grep -q "on $mntpoint " || break 968a272653SPeter Holm umount -f $mntpoint 978a272653SPeter Holm sleep 1 988a272653SPeter Holmdone 998a272653SPeter Holmrm -f /tmp/core3 1008a272653SPeter Holmexit $status 1018a272653SPeter HolmEOF 1028a272653SPeter Holm#include <sys/mman.h> 1038a272653SPeter Holm#include <sys/wait.h> 1048a272653SPeter Holm 1058a272653SPeter Holm#include <err.h> 1068a272653SPeter Holm#include <signal.h> 1078a272653SPeter Holm#include <stdio.h> 1088a272653SPeter Holm#include <stdlib.h> 1098a272653SPeter Holm#include <string.h> 1108a272653SPeter Holm#include <time.h> 1118a272653SPeter Holm#include <unistd.h> 1128a272653SPeter Holm 1138a272653SPeter Holm#define PARALLEL 64 1148a272653SPeter Holm#define SIZ (4 * 1024 * 1024) 1158a272653SPeter Holm#define TIMEDOUT 22 1168a272653SPeter Holm 1178a272653SPeter Holmvoid *p; 1188a272653SPeter Holm 1198a272653SPeter Holmstatic void 1208a272653SPeter Holmhand(int i __unused) { /* handler */ 1218a272653SPeter Holm _exit(TIMEDOUT); 1228a272653SPeter Holm} 1238a272653SPeter Holm 1248a272653SPeter Holmvoid 1258a272653SPeter Holmtest(char *argv[]) 1268a272653SPeter Holm{ 1278a272653SPeter Holm size_t len; 1288a272653SPeter Holm 1298a272653SPeter Holm len = SIZ; 1308a272653SPeter Holm p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); 1318a272653SPeter Holm 1328a272653SPeter Holm /* 1338a272653SPeter Holm * This loop caused mount to wait in "ufs". 1348a272653SPeter Holm * Adding a usleep(200) would remove the hang. 1358a272653SPeter Holm */ 1368a272653SPeter Holm signal(SIGALRM, hand); 1378a272653SPeter Holm alarm(600); 1388a272653SPeter Holm while (chdir(argv[1]) == -1) 1398a272653SPeter Holm ; 1408a272653SPeter Holm 1418a272653SPeter Holm raise(SIGSEGV); 1428a272653SPeter Holm 1438a272653SPeter Holm _exit(0); 1448a272653SPeter Holm} 1458a272653SPeter Holm 1468a272653SPeter Holmint 1478a272653SPeter Holmmain(int argc, char *argv[]) 1488a272653SPeter Holm{ 1498a272653SPeter Holm time_t start; 1508a272653SPeter Holm int i, s, status; 1518a272653SPeter Holm 1528a272653SPeter Holm if (argc != 2) 1538a272653SPeter Holm errx(1, "Usage: %s <path>", argv[0]); 1548a272653SPeter Holm 1558a272653SPeter Holm status = 0; 1568a272653SPeter Holm start = time(NULL); 1578a272653SPeter Holm while (time(NULL) - start < 600 && status == 0) { 1588a272653SPeter Holm for (i = 0; i < PARALLEL; i++) { 1598a272653SPeter Holm if (fork() == 0) 1608a272653SPeter Holm test(argv); 1618a272653SPeter Holm } 1628a272653SPeter Holm for (i = 0; i < PARALLEL; i++) { 1638a272653SPeter Holm wait(&s); 1648a272653SPeter Holm if (WEXITSTATUS(s) == TIMEDOUT) 1658a272653SPeter Holm status = 1; 1668a272653SPeter Holm } 1678a272653SPeter Holm } 1688a272653SPeter Holm 1698a272653SPeter Holm return (status); 1708a272653SPeter Holm} 171