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# Cross mount test of mkdir(2). 308a272653SPeter Holm# Page fault seen: 318a272653SPeter Holm# http://people.freebsd.org/~pho/stress/log/cmp.txt 328a272653SPeter Holm# Fixed by r275347 338a272653SPeter Holm 348a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 358a272653SPeter Holm 368a272653SPeter Holm. ../default.cfg 378a272653SPeter Holm 388a272653SPeter Holmhere=`pwd` 398a272653SPeter Holmcd /tmp 408a272653SPeter Holmsed '1,/^EOF/d' < $here/$0 > cmp.c 418a272653SPeter Holmmycc -o cmp -Wall -Wextra -O2 -g cmp.c || exit 1 428a272653SPeter Holmrm -f cmp.c 438a272653SPeter Holm 448a272653SPeter Holmmount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 458a272653SPeter Holm[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 468a272653SPeter Holm 478a272653SPeter Holmmdconfig -a -t swap -s 2g -u $mdstart || exit 1 488a272653SPeter Holm# Don't use SU due to bogus "out of inodes" messages. 49*608c97bfSPeter Holmnewfs md$mdstart > /dev/null 50*608c97bfSPeter Holmmount /dev/md$mdstart $mntpoint 518a272653SPeter Holmchmod 777 $mntpoint 528a272653SPeter Holm 538a272653SPeter Holmdaemon sh -c "(cd $here/../testcases/swap; ./swap -t 5m -i 20 -h -l 100)" \ 548a272653SPeter Holm > /dev/null 2>&1 558a272653SPeter Holmsleep 1 568a272653SPeter Holmsu $testuser -c "/tmp/cmp $mntpoint" & 578a272653SPeter Holm 588a272653SPeter Holmwhile kill -0 $! 2>/dev/null; do 598a272653SPeter Holm umount -f $mntpoint && 60*608c97bfSPeter Holm mount /dev/md$mdstart $mntpoint 618a272653SPeter Holm chmod 777 $mntpoint 628a272653SPeter Holm sleep .1 638a272653SPeter Holmdone 648a272653SPeter Holmwait 658a272653SPeter Holm 668a272653SPeter Holmwhile mount | grep $mntpoint | grep -q /dev/md; do 678a272653SPeter Holm umount $mntpoint || sleep 1 688a272653SPeter Holmdone 698a272653SPeter Holmmdconfig -d -u $mdstart 708a272653SPeter Holm[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) 718a272653SPeter Holm 728a272653SPeter Holm# tmpfs 738a272653SPeter Holmmount -t tmpfs tmpfs $mntpoint 748a272653SPeter Holmchmod 777 $mntpoint 758a272653SPeter Holm 768a272653SPeter Holmsu $testuser -c "/tmp/cmp $mntpoint" & 778a272653SPeter Holm 788a272653SPeter Holmwhile kill -0 $! 2>/dev/null; do 798a272653SPeter Holm umount -f $mntpoint && 808a272653SPeter Holm mount -t tmpfs tmpfs $mntpoint 818a272653SPeter Holm chmod 777 $mntpoint 828a272653SPeter Holm sleep .1 838a272653SPeter Holmdone 848a272653SPeter Holmpkill -9 swap 858a272653SPeter Holmwait 868a272653SPeter Holm 878a272653SPeter Holmwhile pkill -9 swap; do 888a272653SPeter Holm : 898a272653SPeter Holmdone > /dev/null 2>&1 908a272653SPeter Holmwhile mount | grep $mntpoint | grep -q tmpfs; do 918a272653SPeter Holm umount $mntpoint || sleep 1 928a272653SPeter Holmdone 938a272653SPeter Holm[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete) 948a272653SPeter Holmrm -f /tmp/cmp 958a272653SPeter Holmexit 0 968a272653SPeter HolmEOF 978a272653SPeter Holm#include <sys/param.h> 988a272653SPeter Holm#include <sys/stat.h> 998a272653SPeter Holm#include <sys/wait.h> 1008a272653SPeter Holm 1018a272653SPeter Holm#include <err.h> 1028a272653SPeter Holm#include <errno.h> 1038a272653SPeter Holm#include <fcntl.h> 1048a272653SPeter Holm#include <stdio.h> 1058a272653SPeter Holm#include <stdlib.h> 1068a272653SPeter Holm#include <string.h> 1078a272653SPeter Holm#include <unistd.h> 1088a272653SPeter Holm 1098a272653SPeter Holm#define LOOPS 160 1108a272653SPeter Holm#define PARALLEL 16 1118a272653SPeter Holm 1128a272653SPeter Holmint nbc, nbd; 1138a272653SPeter Holmchar *dir; 1148a272653SPeter Holm 1158a272653SPeter Holmvoid 1168a272653SPeter Holmtmkdir(void) 1178a272653SPeter Holm{ 1188a272653SPeter Holm int i, j; 1198a272653SPeter Holm char d[MAXPATHLEN + 1], name[MAXPATHLEN + 1]; 1208a272653SPeter Holm 1218a272653SPeter Holm setproctitle(__func__); 1228a272653SPeter Holm 1238a272653SPeter Holm i = 0; 1248a272653SPeter Holm snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); 1258a272653SPeter Holm if (mkdir(name, 0755) == -1) { 1268a272653SPeter Holm if (errno != ENAMETOOLONG && errno != ENOENT && 1278a272653SPeter Holm errno != EBUSY && errno != EACCES && errno != EPERM) 1288a272653SPeter Holm warn("mkdir(%s)", name); 1298a272653SPeter Holm _exit(0); 1308a272653SPeter Holm } 1318a272653SPeter Holm for (;;) { 1328a272653SPeter Holm snprintf(d, sizeof(d), "/%d", i++); 1338a272653SPeter Holm strncat(name, d, sizeof(name) - 1); 1348a272653SPeter Holm if (mkdir(name, 0755) == -1) { 1358a272653SPeter Holm if (errno != ENAMETOOLONG && errno != ENOENT && 1368a272653SPeter Holm errno != EBUSY && errno != EACCES && errno != EPERM) 1378a272653SPeter Holm warn("mkdir(%s)", name); 1388a272653SPeter Holm i--; 1398a272653SPeter Holm break; 1408a272653SPeter Holm } 1418a272653SPeter Holm nbc++; 1428a272653SPeter Holm } 1438a272653SPeter Holm 1448a272653SPeter Holm while (i >= 0) { 1458a272653SPeter Holm snprintf(name, sizeof(name), "%s/d1.%05d", dir, getpid()); 1468a272653SPeter Holm for (j = 0; j < i; j++) { 1478a272653SPeter Holm snprintf(d, sizeof(d), "/%d", j); 1488a272653SPeter Holm strncat(name, d, sizeof(name) - 1); 1498a272653SPeter Holm } 1508a272653SPeter Holm if (rmdir(name) == -1) { 1518a272653SPeter Holm if (errno != ENOTEMPTY && errno != ENOENT && errno != 1528a272653SPeter Holm EBUSY) 1538a272653SPeter Holm warn("rmdir(%s)", name); 1548a272653SPeter Holm } else 1558a272653SPeter Holm nbd++; 1568a272653SPeter Holm i--; 1578a272653SPeter Holm } 1588a272653SPeter Holm#if defined(TEST) 1598a272653SPeter Holm if (nbc == 0) 1608a272653SPeter Holm fprintf(stderr, "FAIL nbc = %d, nbd = %d\n", nbc, nbd); 1618a272653SPeter Holm#endif 1628a272653SPeter Holm _exit(0); 1638a272653SPeter Holm} 1648a272653SPeter Holm 1658a272653SPeter Holmint 1668a272653SPeter Holmmain(int argc, char **argv) 1678a272653SPeter Holm{ 1688a272653SPeter Holm int i, j; 1698a272653SPeter Holm 1708a272653SPeter Holm if (argc != 2) { 1718a272653SPeter Holm fprintf(stderr, "Usage: %s <full path to dir>", argv[0]); 1728a272653SPeter Holm exit(1); 1738a272653SPeter Holm } 1748a272653SPeter Holm dir = argv[1]; 1758a272653SPeter Holm 1768a272653SPeter Holm for (j = 0; j < LOOPS; j++) { 1778a272653SPeter Holm for (i = 0; i < PARALLEL; i++) { 1788a272653SPeter Holm if (fork() == 0) 1798a272653SPeter Holm tmkdir(); 1808a272653SPeter Holm } 1818a272653SPeter Holm for (i = 0; i < PARALLEL; i++) 1828a272653SPeter Holm wait(NULL); 1838a272653SPeter Holm } 1848a272653SPeter Holm 1858a272653SPeter Holm return(0); 1868a272653SPeter Holm} 187