18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# 48a272653SPeter Holm# Copyright (c) 2011 Peter Holm <pho@FreeBSD.org> 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# Scenario from kern/159971 308a272653SPeter Holm# bstg0003.c by Kirk Russell <kirk ba23 org> 318a272653SPeter Holm 328a272653SPeter Holm# panic: ino 0xc84c9b00(0x3C8209) 65554, 32780 != 65570 338a272653SPeter Holm# https://people.freebsd.org/~pho/stress/log/suj23.txt 348a272653SPeter Holm 358a272653SPeter Holm# panic: first_unlinked_inodedep: prev != next. inodedep = 0xcadf9e00 368a272653SPeter Holm# https://people.freebsd.org/~pho/stress/log/jeff091.txt 378a272653SPeter Holm 388a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 398a272653SPeter Holm 408a272653SPeter Holm. ../default.cfg 418a272653SPeter Holm 428a272653SPeter Holmhere=`pwd` 438a272653SPeter Holmcd /tmp 448a272653SPeter Holmsed '1,/^EOF/d' < $here/$0 > suj23.c 458a272653SPeter Holmmycc -o suj23 -Wall -Wextra -O2 suj23.c 468a272653SPeter Holmrm -f suj23.c 478a272653SPeter Holm 488a272653SPeter Holmmount | grep "on $mntpoint " | grep -q md$mdstart && umount $mntpoint 498a272653SPeter Holm[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 508a272653SPeter Holm 518a272653SPeter Holmmdconfig -a -t swap -s 1g -u $mdstart 52*608c97bfSPeter Holmnewfs -j md$mdstart > /dev/null 53*608c97bfSPeter Holmmount /dev/md$mdstart $mntpoint 548a272653SPeter Holmchmod 777 $mntpoint 558a272653SPeter Holm 568a272653SPeter Holmsu $testuser -c '/tmp/suj23' 578a272653SPeter Holm 588a272653SPeter Holmwhile mount | grep -q "on $mntpoint "; do 598a272653SPeter Holm umount $mntpoint || sleep 1 608a272653SPeter Holmdone 618a272653SPeter Holmmdconfig -d -u $mdstart 628a272653SPeter Holmrm -f /tmp/suj23 638a272653SPeter Holmexit 0 648a272653SPeter HolmEOF 658a272653SPeter Holm/* 668a272653SPeter Holm * Copyright 2011 Kirk J. Russell 678a272653SPeter Holm * 688a272653SPeter Holm * Licensed under the Apache License, Version 2.0 (the "License"); you may not 698a272653SPeter Holm * use this file except in compliance with the License. You may obtain a copy 708a272653SPeter Holm * of the License at http://www.apache.org/licenses/LICENSE-2.0 718a272653SPeter Holm * 728a272653SPeter Holm * Unless required by applicable law or agreed to in writing, software 738a272653SPeter Holm * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 748a272653SPeter Holm * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 758a272653SPeter Holm * License for the specific language governing permissions and limitations 768a272653SPeter Holm * under the License. 778a272653SPeter Holm */ 788a272653SPeter Holm 798a272653SPeter Holm#include <unistd.h> 808a272653SPeter Holm#include <assert.h> 818a272653SPeter Holm#include <err.h> 828a272653SPeter Holm#include <fcntl.h> 838a272653SPeter Holm#include <signal.h> 848a272653SPeter Holm#include <stdio.h> 858a272653SPeter Holm#include <stdlib.h> 868a272653SPeter Holm#include <string.h> 878a272653SPeter Holm#include <time.h> 888a272653SPeter Holm#include <sys/stat.h> 898a272653SPeter Holm#include <sys/uio.h> 908a272653SPeter Holm#include <sys/wait.h> 918a272653SPeter Holm 928a272653SPeter Holm#define RUNTIME 600 938a272653SPeter Holm 948a272653SPeter Holmstatic char *bstg_pathstore[] = { 958a272653SPeter Holm "/mnt/111/z", 968a272653SPeter Holm "/mnt/111/aaaa", 978a272653SPeter Holm "/mnt/111/bbbbb", 988a272653SPeter Holm "/mnt/111/ccccc", 998a272653SPeter Holm "/mnt/111/d", 1008a272653SPeter Holm "/mnt/111/e", 1018a272653SPeter Holm "/mnt/111/ffffff.fff.f", 1028a272653SPeter Holm "/mnt/111/gggggggggggg", 1038a272653SPeter Holm "/mnt/111/hhhh", 1048a272653SPeter Holm "/mnt/111/iiiii.ii", 1058a272653SPeter Holm "/mnt/111/jjjj.jj.jjjjjjjj", 1068a272653SPeter Holm "/mnt/111/kkkk.kkkkkkkk", 1078a272653SPeter Holm "/mnt/111/lllll", 1088a272653SPeter Holm "/mnt/222/z", 1098a272653SPeter Holm "/mnt/222/aaaa", 1108a272653SPeter Holm "/mnt/222/bbbbb", 1118a272653SPeter Holm "/mnt/222/ccccc", 1128a272653SPeter Holm "/mnt/222/d", 1138a272653SPeter Holm "/mnt/222/e", 1148a272653SPeter Holm "/mnt/222/ffffff.fff.f", 1158a272653SPeter Holm "/mnt/222/gggggggggggg", 1168a272653SPeter Holm "/mnt/222/hhhh", 1178a272653SPeter Holm "/mnt/222/iiiii.ii", 1188a272653SPeter Holm "/mnt/222/jjjj.jj.jjjjjjjj", 1198a272653SPeter Holm "/mnt/222/kkkk.kkkkkkkk", 1208a272653SPeter Holm "/mnt/222/lllll", 1218a272653SPeter Holm "/mnt/333/z", 1228a272653SPeter Holm "/mnt/333/aaaa", 1238a272653SPeter Holm "/mnt/333/bbbbb", 1248a272653SPeter Holm "/mnt/333/ccccc", 1258a272653SPeter Holm "/mnt/333/d", 1268a272653SPeter Holm "/mnt/333/e", 1278a272653SPeter Holm "/mnt/333/ffffff.fff.f", 1288a272653SPeter Holm "/mnt/333/gggggggggggg", 1298a272653SPeter Holm "/mnt/333/hhhh", 1308a272653SPeter Holm "/mnt/333/iiiii.ii", 1318a272653SPeter Holm "/mnt/333/jjjj.jj.jjjjjjjj", 1328a272653SPeter Holm "/mnt/333/kkkk.kkkkkkkk", 1338a272653SPeter Holm "/mnt/333/lllll", 1348a272653SPeter Holm "/mnt/444/z", 1358a272653SPeter Holm "/mnt/444/aaaa", 1368a272653SPeter Holm "/mnt/444/bbbbb", 1378a272653SPeter Holm "/mnt/444/ccccc", 1388a272653SPeter Holm "/mnt/444/d", 1398a272653SPeter Holm "/mnt/444/e", 1408a272653SPeter Holm "/mnt/444/ffffff.fff.f", 1418a272653SPeter Holm "/mnt/444/gggggggggggg", 1428a272653SPeter Holm "/mnt/444/hhhh", 1438a272653SPeter Holm "/mnt/444/iiiii.ii", 1448a272653SPeter Holm "/mnt/444/jjjj.jj.jjjjjjjj", 1458a272653SPeter Holm "/mnt/444/kkkk.kkkkkkkk", 1468a272653SPeter Holm "/mnt/444/lllll", 1478a272653SPeter Holm "/mnt/555/z", 1488a272653SPeter Holm "/mnt/555/aaaa", 1498a272653SPeter Holm "/mnt/555/bbbbb", 1508a272653SPeter Holm "/mnt/555/ccccc", 1518a272653SPeter Holm "/mnt/555/d", 1528a272653SPeter Holm "/mnt/555/e", 1538a272653SPeter Holm "/mnt/555/ffffff.fff.f", 1548a272653SPeter Holm "/mnt/555/gggggggggggg", 1558a272653SPeter Holm "/mnt/555/hhhh", 1568a272653SPeter Holm "/mnt/555/iiiii.ii", 1578a272653SPeter Holm "/mnt/555/jjjj.jj.jjjjjjjj", 1588a272653SPeter Holm "/mnt/555/kkkk.kkkkkkkk", 1598a272653SPeter Holm "/mnt/555/lllll", 1608a272653SPeter Holm "/mnt/666/z", 1618a272653SPeter Holm "/mnt/666/aaaa", 1628a272653SPeter Holm "/mnt/666/bbbbb", 1638a272653SPeter Holm "/mnt/666/ccccc", 1648a272653SPeter Holm "/mnt/666/d", 1658a272653SPeter Holm "/mnt/666/e", 1668a272653SPeter Holm "/mnt/666/ffffff.fff.f", 1678a272653SPeter Holm "/mnt/666/gggggggggggg", 1688a272653SPeter Holm "/mnt/666/hhhh", 1698a272653SPeter Holm "/mnt/666/iiiii.ii", 1708a272653SPeter Holm "/mnt/666/jjjj.jj.jjjjjjjj", 1718a272653SPeter Holm "/mnt/666/kkkk.kkkkkkkk", 1728a272653SPeter Holm "/mnt/666/lllll", 1738a272653SPeter Holm "/mnt/777/z", 1748a272653SPeter Holm "/mnt/777/aaaa", 1758a272653SPeter Holm "/mnt/777/bbbbb", 1768a272653SPeter Holm "/mnt/777/ccccc", 1778a272653SPeter Holm "/mnt/777/d", 1788a272653SPeter Holm "/mnt/777/e", 1798a272653SPeter Holm "/mnt/777/ffffff.fff.f", 1808a272653SPeter Holm "/mnt/777/gggggggggggg", 1818a272653SPeter Holm "/mnt/777/hhhh", 1828a272653SPeter Holm "/mnt/777/iiiii.ii", 1838a272653SPeter Holm "/mnt/777/jjjj.jj.jjjjjjjj", 1848a272653SPeter Holm "/mnt/777/kkkk.kkkkkkkk", 1858a272653SPeter Holm "/mnt/777/lllll", 1868a272653SPeter Holm "/mnt/888/z", 1878a272653SPeter Holm "/mnt/888/aaaa", 1888a272653SPeter Holm "/mnt/888/bbbbb", 1898a272653SPeter Holm "/mnt/888/ccccc", 1908a272653SPeter Holm "/mnt/888/d", 1918a272653SPeter Holm "/mnt/888/e", 1928a272653SPeter Holm "/mnt/888/ffffff.fff.f", 1938a272653SPeter Holm "/mnt/888/gggggggggggg", 1948a272653SPeter Holm "/mnt/888/hhhh", 1958a272653SPeter Holm "/mnt/888/iiiii.ii", 1968a272653SPeter Holm "/mnt/888/jjjj.jj.jjjjjjjj", 1978a272653SPeter Holm "/mnt/888/kkkk.kkkkkkkk", 1988a272653SPeter Holm "/mnt/888/lllll", 1998a272653SPeter Holm "/mnt/999/z", 2008a272653SPeter Holm "/mnt/999/aaaa", 2018a272653SPeter Holm "/mnt/999/bbbbb", 2028a272653SPeter Holm "/mnt/999/ccccc", 2038a272653SPeter Holm "/mnt/999/d", 2048a272653SPeter Holm "/mnt/999/e", 2058a272653SPeter Holm "/mnt/999/ffffff.fff.f", 2068a272653SPeter Holm "/mnt/999/gggggggggggg", 2078a272653SPeter Holm "/mnt/999/hhhh", 2088a272653SPeter Holm "/mnt/999/iiiii.ii", 2098a272653SPeter Holm "/mnt/999/jjjj.jj.jjjjjjjj", 2108a272653SPeter Holm "/mnt/999/kkkk.kkkkkkkk", 2118a272653SPeter Holm "/mnt/999/lllll", 2128a272653SPeter Holm "/mnt/aaa/z", 2138a272653SPeter Holm "/mnt/aaa/aaaa", 2148a272653SPeter Holm "/mnt/aaa/bbbbb", 2158a272653SPeter Holm "/mnt/aaa/ccccc", 2168a272653SPeter Holm "/mnt/aaa/d", 2178a272653SPeter Holm "/mnt/aaa/e", 2188a272653SPeter Holm "/mnt/aaa/ffffff.fff.f", 2198a272653SPeter Holm "/mnt/aaa/gggggggggggg", 2208a272653SPeter Holm "/mnt/aaa/hhhh", 2218a272653SPeter Holm "/mnt/aaa/iiiii.ii", 2228a272653SPeter Holm "/mnt/aaa/jjjj.jj.jjjjjjjj", 2238a272653SPeter Holm "/mnt/aaa/kkkk.kkkkkkkk", 2248a272653SPeter Holm "/mnt/aaa/lllll", 2258a272653SPeter Holm "/mnt/bbb/z", 2268a272653SPeter Holm "/mnt/bbb/aaaa", 2278a272653SPeter Holm "/mnt/bbb/bbbbb", 2288a272653SPeter Holm "/mnt/bbb/ccccc", 2298a272653SPeter Holm "/mnt/bbb/d", 2308a272653SPeter Holm "/mnt/bbb/e", 2318a272653SPeter Holm "/mnt/bbb/ffffff.fff.f", 2328a272653SPeter Holm "/mnt/bbb/gggggggggggg", 2338a272653SPeter Holm "/mnt/bbb/hhhh", 2348a272653SPeter Holm "/mnt/bbb/iiiii.ii", 2358a272653SPeter Holm "/mnt/bbb/jjjj.jj.jjjjjjjj", 2368a272653SPeter Holm "/mnt/bbb/kkkk.kkkkkkkk", 2378a272653SPeter Holm "/mnt/bbb/lllll", 2388a272653SPeter Holm "/mnt/ccc/z", 2398a272653SPeter Holm "/mnt/ccc/aaaa", 2408a272653SPeter Holm "/mnt/ccc/bbbbb", 2418a272653SPeter Holm "/mnt/ccc/ccccc", 2428a272653SPeter Holm "/mnt/ccc/d", 2438a272653SPeter Holm "/mnt/ccc/e", 2448a272653SPeter Holm "/mnt/ccc/ffffff.fff.f", 2458a272653SPeter Holm "/mnt/ccc/gggggggggggg", 2468a272653SPeter Holm "/mnt/ccc/hhhh", 2478a272653SPeter Holm "/mnt/ccc/iiiii.ii", 2488a272653SPeter Holm "/mnt/ccc/jjjj.jj.jjjjjjjj", 2498a272653SPeter Holm "/mnt/ccc/kkkk.kkkkkkkk", 2508a272653SPeter Holm "/mnt/ccc/lllll", 2518a272653SPeter Holm "/mnt/ddd/z", 2528a272653SPeter Holm "/mnt/ddd/aaaa", 2538a272653SPeter Holm "/mnt/ddd/bbbbb", 2548a272653SPeter Holm "/mnt/ddd/ccccc", 2558a272653SPeter Holm "/mnt/ddd/d", 2568a272653SPeter Holm "/mnt/ddd/e", 2578a272653SPeter Holm "/mnt/ddd/ffffff.fff.f", 2588a272653SPeter Holm "/mnt/ddd/gggggggggggg", 2598a272653SPeter Holm "/mnt/ddd/hhhh", 2608a272653SPeter Holm "/mnt/ddd/iiiii.ii", 2618a272653SPeter Holm "/mnt/ddd/jjjj.jj.jjjjjjjj", 2628a272653SPeter Holm "/mnt/ddd/kkkk.kkkkkkkk", 2638a272653SPeter Holm "/mnt/ddd/lllll", 2648a272653SPeter Holm "/mnt/eee/z", 2658a272653SPeter Holm "/mnt/eee/aaaa", 2668a272653SPeter Holm "/mnt/eee/bbbbb", 2678a272653SPeter Holm "/mnt/eee/ccccc", 2688a272653SPeter Holm "/mnt/eee/d", 2698a272653SPeter Holm "/mnt/eee/e", 2708a272653SPeter Holm "/mnt/eee/ffffff.fff.f", 2718a272653SPeter Holm "/mnt/eee/gggggggggggg", 2728a272653SPeter Holm "/mnt/eee/hhhh", 2738a272653SPeter Holm "/mnt/eee/iiiii.ii", 2748a272653SPeter Holm "/mnt/eee/jjjj.jj.jjjjjjjj", 2758a272653SPeter Holm "/mnt/eee/kkkk.kkkkkkkk", 2768a272653SPeter Holm "/mnt/eee/lllll", 2778a272653SPeter Holm "/mnt/fff/z", 2788a272653SPeter Holm "/mnt/fff/aaaa", 2798a272653SPeter Holm "/mnt/fff/bbbbb", 2808a272653SPeter Holm "/mnt/fff/ccccc", 2818a272653SPeter Holm "/mnt/fff/d", 2828a272653SPeter Holm "/mnt/fff/e", 2838a272653SPeter Holm "/mnt/fff/ffffff.fff.f", 2848a272653SPeter Holm "/mnt/fff/gggggggggggg", 2858a272653SPeter Holm "/mnt/fff/hhhh", 2868a272653SPeter Holm "/mnt/fff/iiiii.ii", 2878a272653SPeter Holm "/mnt/fff/jjjj.jj.jjjjjjjj", 2888a272653SPeter Holm "/mnt/fff/kkkk.kkkkkkkk", 2898a272653SPeter Holm "/mnt/fff/lllll" 2908a272653SPeter Holm}; 2918a272653SPeter Holm 2928a272653SPeter Holmchar * 2938a272653SPeter Holmbstg_pathstore_get() 2948a272653SPeter Holm{ 2958a272653SPeter Holm return bstg_pathstore[rand() % 2968a272653SPeter Holm ((sizeof(bstg_pathstore) / sizeof(bstg_pathstore[0])))]; 2978a272653SPeter Holm} 2988a272653SPeter Holm 2998a272653SPeter Holmvoid 3008a272653SPeter Holmdogcore() 3018a272653SPeter Holm{ 3028a272653SPeter Holm pid_t sleepchild, gcorechild; 3038a272653SPeter Holm extern char **environ; 3048a272653SPeter Holm 3058a272653SPeter Holm /* create a child for the gcore target */ 3068a272653SPeter Holm if ((sleepchild = fork()) == 0) { 3078a272653SPeter Holm sleep(30); 3088a272653SPeter Holm _exit(1); 3098a272653SPeter Holm } else if (sleepchild > 0) { 3108a272653SPeter Holm char *token[] = {NULL, NULL, NULL, NULL, NULL}; 3118a272653SPeter Holm char buf[64]; 3128a272653SPeter Holm int status; 3138a272653SPeter Holm 3148a272653SPeter Holm /* use the first process as the target */ 3158a272653SPeter Holm snprintf(buf, sizeof(buf), "%d", sleepchild); 3168a272653SPeter Holm token[0] = "gcore"; 3178a272653SPeter Holm token[1] = "-c"; 3188a272653SPeter Holm token[2] = bstg_pathstore_get(); 3198a272653SPeter Holm token[3] = buf; 3208a272653SPeter Holm assert(token[4] == NULL); 3218a272653SPeter Holm 3228a272653SPeter Holm if ((gcorechild = fork()) > 0) { 3238a272653SPeter Holm waitpid(gcorechild, &status, 0); 3248a272653SPeter Holm } else if (gcorechild == 0) { 3258a272653SPeter Holm execve("/usr/bin/gcore", token, environ); 3268a272653SPeter Holm _exit(1); 3278a272653SPeter Holm } 3288a272653SPeter Holm kill(sleepchild, SIGKILL); 3298a272653SPeter Holm waitpid(sleepchild, &status, 0); 3308a272653SPeter Holm } 3318a272653SPeter Holm} 3328a272653SPeter Holm 3338a272653SPeter Holmvoid 3348a272653SPeter Holmdowrite() 3358a272653SPeter Holm{ 3368a272653SPeter Holm struct iovec data[] = { 3378a272653SPeter Holm {"12", 2}, 3388a272653SPeter Holm {NULL, 0}, 3398a272653SPeter Holm {"12345678", 8}, 3408a272653SPeter Holm }; 3418a272653SPeter Holm static int fd = -1; 3428a272653SPeter Holm 3438a272653SPeter Holm if (fd == -1) { 3448a272653SPeter Holm /* keep existing file open during life of this process */ 3458a272653SPeter Holm fd = open(bstg_pathstore_get(), O_RDWR | O_NONBLOCK | O_NOCTTY); 3468a272653SPeter Holm } 3478a272653SPeter Holm data[1].iov_base = bstg_pathstore_get(); 3488a272653SPeter Holm data[1].iov_len = strlen((char *)data[1].iov_base); 3498a272653SPeter Holm ftruncate(fd, 0); 3508a272653SPeter Holm pwritev(fd, data, 3, 0); 3518a272653SPeter Holm} 3528a272653SPeter Holm 3538a272653SPeter Holmvoid 3548a272653SPeter Holmdounlink() 3558a272653SPeter Holm{ 3568a272653SPeter Holm unlink(bstg_pathstore_get()); 3578a272653SPeter Holm} 3588a272653SPeter Holm 3598a272653SPeter Holmvoid 3608a272653SPeter Holmdolink() 3618a272653SPeter Holm{ 3628a272653SPeter Holm link(bstg_pathstore_get(), bstg_pathstore_get()); 3638a272653SPeter Holm} 3648a272653SPeter Holm 3658a272653SPeter Holmvoid 3668a272653SPeter Holmdomkdir() 3678a272653SPeter Holm{ 3688a272653SPeter Holm char **pdir; 3698a272653SPeter Holm static char *bstg_dirs[] = { 3708a272653SPeter Holm "/mnt/111", "/mnt/222", "/mnt/333", "/mnt/444", 3718a272653SPeter Holm "/mnt/555", "/mnt/666", "/mnt/777", "/mnt/888", 3728a272653SPeter Holm "/mnt/999", "/mnt/aaa", "/mnt/bbb", "/mnt/ccc", 3738a272653SPeter Holm "/mnt/ddd", "/mnt/eee", "/mnt/fff", NULL 3748a272653SPeter Holm }; 3758a272653SPeter Holm 3768a272653SPeter Holm for (pdir = bstg_dirs; *pdir; pdir++) { 3778a272653SPeter Holm if (mkdir(*pdir, 0777) == -1) 3788a272653SPeter Holm err(1, "mkdir(%s)", *pdir); 3798a272653SPeter Holm } 3808a272653SPeter Holm} 3818a272653SPeter Holm 3828a272653SPeter Holmvoid 3838a272653SPeter Holmdosync() 3848a272653SPeter Holm{ 3858a272653SPeter Holm sync(); 3868a272653SPeter Holm} 3878a272653SPeter Holm 3888a272653SPeter Holmint 3898a272653SPeter Holmmain() 3908a272653SPeter Holm{ 3918a272653SPeter Holm time_t start; 3928a272653SPeter Holm unsigned x; 3938a272653SPeter Holm int i, status; 3948a272653SPeter Holm void (*funcs[]) () = { 3958a272653SPeter Holm dogcore, 3968a272653SPeter Holm dowrite, 3978a272653SPeter Holm dounlink, 3988a272653SPeter Holm dolink, 3998a272653SPeter Holm dowrite, 4008a272653SPeter Holm dounlink, 4018a272653SPeter Holm dolink, 4028a272653SPeter Holm dowrite, 4038a272653SPeter Holm dosync, 4048a272653SPeter Holm dowrite, 4058a272653SPeter Holm dounlink, 4068a272653SPeter Holm dolink, 4078a272653SPeter Holm dowrite, 4088a272653SPeter Holm dounlink, 4098a272653SPeter Holm dolink, 4108a272653SPeter Holm dowrite, 4118a272653SPeter Holm }; 4128a272653SPeter Holm 4138a272653SPeter Holm /* we only can domkdir() once at startup */ 4148a272653SPeter Holm domkdir(); 4158a272653SPeter Holm 4168a272653SPeter Holm /* create 128 children that loop forever running 4 operations */ 4178a272653SPeter Holm dosync(); 4188a272653SPeter Holm for (x = 0; x < 128; x++) { 4198a272653SPeter Holm if (fork() == 0) { 4208a272653SPeter Holm /* give child a new seed for the pathname selection */ 4218a272653SPeter Holm srand(x); 4228a272653SPeter Holm 4238a272653SPeter Holm start = time(NULL); 4248a272653SPeter Holm for (i = 0; i < 1000; i++) { 4258a272653SPeter Holm /* each child will start looping at different 4268a272653SPeter Holm * function */ 4278a272653SPeter Holm (*funcs[x++ % 16]) (); 4288a272653SPeter Holm if (time(NULL) - start > RUNTIME) 4298a272653SPeter Holm break; 4308a272653SPeter Holm } 4318a272653SPeter Holm /* we never expect this code to run */ 4328a272653SPeter Holm _exit(1); 4338a272653SPeter Holm } 4348a272653SPeter Holm } 4358a272653SPeter Holm 4368a272653SPeter Holm /* block forever for all our children */ 4378a272653SPeter Holm while (wait(&status) > 0); 4388a272653SPeter Holm return 0; 4398a272653SPeter Holm} 440