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# SU problem with "mkdir(d.008740.000987): Too many links" seen. 30 31[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 32 33. ../default.cfg 34 35here=`pwd` 36cd /tmp 37sed '1,/^EOF/d' < $here/$0 > rename11.c 38mycc -o rename11 -Wall -Wextra rename11.c || exit 1 39rm -f rename11.c 40 41mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint 42mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 43 44mdconfig -a -t swap -s 2g -u $mdstart || exit 1 45bsdlabel -w md$mdstart auto 46 47[ $# -eq 1 ] && newfs_flags=$1 # Problem only seen with SU 48echo newfs $newfs_flags md${mdstart}$part 49newfs $newfs_flags md${mdstart}$part > /dev/null 50mount /dev/md${mdstart}$part $mntpoint 51 52mkdir $mntpoint/dir 53( 54 cd $mntpoint/dir 55 /tmp/rename11 || echo FAIL 56) 57 58while mount | grep "on $mntpoint " | grep -q /dev/md; do 59 umount $mntpoint || sleep 1 60done 61 62checkfs /dev/md${mdstart}$part; s=$? 63mdconfig -d -u $mdstart 64rm -rf /tmp/rename11 65exit $s 66EOF 67#include <sys/types.h> 68#include <sys/stat.h> 69#include <sys/wait.h> 70#include <err.h> 71#include <fcntl.h> 72#include <libgen.h> 73#include <stdio.h> 74#include <stdlib.h> 75#include <string.h> 76#include <unistd.h> 77 78#define LOOPS 10 79#define PARALLEL 3 80#define ND 5000 81 82static void 83check(char *name) 84{ 85 struct stat sb; 86 87 if (stat(name, &sb) == -1) 88 warn("stat(%s)", name); 89 else 90 warnx("stat(%s) succeeded!", name); 91} 92 93static void 94dirs(void) 95{ 96 pid_t pid; 97 int i, j; 98 char name[80], to[80]; 99 100 pid = getpid(); 101 102 for (j = 0; j < LOOPS; j++) { 103 for (i = 0; i < ND; i++) { 104 snprintf(name, sizeof(name), "d.%06d.%06d", pid, i); 105 if (mkdir(name, 0700) == -1) 106 err(1, "mkdir(%s)", name); 107 snprintf(to , sizeof(to ), "d2.%06d.%06d", pid, i); 108 if (rename(name, to) == -1) 109 warn("rename(%s, %s)", name, to); 110 if (rename(to, name) == -1) 111 warn("rename(%s, %s)", to, name); 112 if (rmdir(name) == -1) { 113 check(name); 114 err(1, "rmdir(%s)", name); 115 } 116 } 117 } 118 119 _exit(0); 120} 121 122int 123main(void) 124{ 125 int i, r, s; 126 127 r = 0; 128 for (i = 0; i < PARALLEL; i++) { 129 if (fork() == 0) 130 dirs(); 131 } 132 133 for (i = 0; i < PARALLEL; i++) { 134 wait(&s); 135 r += WEXITSTATUS(s); 136 } 137 138 return (r); 139} 140