2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * This is mostly a "crash & burn" test. -v turns on verbosity
35 * and -c actually fails on errors - but expected errors aren't
48 static int dirstress(char *dirname, int dirnum, int nfiles, int keep);
49 static int create_entries(int nfiles);
50 static int scramble_entries(int nfiles);
51 static int remove_entries(int nfiles);
80 while ((c = getopt(argc, argv, "d:p:f:s:n:kvc")) != EOF) {
83 nprocs = atoi(optarg);
86 nfiles = atoi(optarg);
89 nprocs_per_dir = atoi(optarg);
95 seed = strtol(optarg, NULL, 0);
111 if (errflg || (dirname == NULL)) {
112 printf("Usage: dirstress [-d dir] [-p nprocs] [-f nfiles] [-n procs per dir]\n"
113 " [-v] [-s seed] [-k] [-c]\n");
117 printf("** [%d] Using seed %ld\n", pid, seed);
120 for (i = 0; i < nprocs; i++) {
121 if (verbose) fprintf(stderr,"** [%d] fork\n", pid);
124 perror("Fork failed");
132 if (verbose) fprintf(stderr,"** [%d] forked\n", pid);
133 r=dirstress(dirname, i / nprocs_per_dir, nfiles, keep);
134 if (verbose) fprintf(stderr,"** [%d] exit\n", pid);
138 if (verbose) fprintf(stderr,"** [%d] wait\n", pid);
141 /* wait & reap children, accumulating error results */
142 while (wait(&status) != -1)
145 printf("INFO: Dirstress complete\n");
146 if (verbose) fprintf(stderr,"** [%d] exit %d\n", pid, istatus);
163 sprintf(buf, "%s/stressdir", dirname);
164 if (verbose) fprintf(stderr,"** [%d] mkdir %s 0777\n", pid, buf);
165 error = mkdir(buf, 0777);
166 if (error && (errno != EEXIST)) {
167 perror("Create stressdir directory failed");
171 if (verbose) fprintf(stderr,"** [%d] chdir %s\n", pid, buf);
174 perror("Cannot chdir to main directory");
178 sprintf(buf, "stress.%d", dirnum);
179 if (verbose) fprintf(stderr,"** [%d] mkdir %s 0777\n", pid, buf);
180 error = mkdir(buf, 0777);
181 if (error && (errno != EEXIST)) {
182 perror("Create pid directory failed");
186 if (verbose) fprintf(stderr,"** [%d] chdir %s\n", pid, buf);
189 perror("Cannot chdir to dirnum directory");
193 r=1; /* assume failure */
194 if (verbose) fprintf(stderr,"** [%d] create entries\n", pid);
195 if (create_entries(nfiles)) {
196 printf("!! [%d] create failed\n", pid);
198 if (verbose) fprintf(stderr,"** [%d] scramble entries\n", pid);
199 if (scramble_entries(nfiles)) {
200 printf("!! [%d] scramble failed\n", pid);
203 if (verbose) fprintf(stderr,"** [%d] keep entries\n", pid);
206 if (verbose) fprintf(stderr,"** [%d] remove entries\n", pid);
207 if (remove_entries(nfiles)) {
208 printf("!! [%d] remove failed\n", pid);
216 if (verbose) fprintf(stderr,"** [%d] chdir ..\n", pid);
219 perror("Cannot chdir out of pid directory");
224 sprintf(buf, "stress.%d", dirnum);
225 if (verbose) fprintf(stderr,"** [%d] rmdir %s\n", pid, buf);
228 if (checkflag) return 1;
232 if (verbose) fprintf(stderr,"** [%d] chdir ..\n", pid);
235 perror("Cannot chdir out of working directory");
240 if (verbose) fprintf(stderr,"** [%d] rmdir stressdir\n", pid);
241 if (rmdir("stressdir")) {
243 if (checkflag) return 1;
258 for (i = 0; i < nfiles; i++) {
259 sprintf(buf, "XXXXXXXXXXXX.%d", i);
265 if (verbose) fprintf(stderr,"** [%d] creat %s\n", pid, buf);
266 fd = creat(buf, 0666);
268 if (verbose) fprintf(stderr,"** [%d] close %s\n", pid, buf);
271 fprintf(stderr,"!! [%d] close %s failed\n", pid, buf);
273 if (checkflag) return 1;
281 if (verbose) fprintf(stderr,"** [%d] mkdir %s 0777\n", pid, buf);
282 if (mkdir(buf, 0777)) {
283 fprintf(stderr,"!! [%d] mkdir %s 0777 failed\n", pid, buf);
285 if (checkflag) return 1;
293 if (verbose) fprintf(stderr,"** [%d] symlink %s %s\n", pid, buf, buf);
294 if (symlink(buf, buf)) {
295 fprintf(stderr,"!! [%d] symlink %s %s failed\n", pid, buf, buf);
297 if (checkflag) return 1;
305 if (verbose) fprintf(stderr,"** [%d] mknod %s 0x%x\n", pid, buf, MKNOD_DEV);
306 if (mknod(buf, S_IFCHR | 0666, MKNOD_DEV)) {
307 fprintf(stderr,"!! [%d] mknod %s 0x%x failed\n", pid, buf, MKNOD_DEV);
309 if (checkflag) return 1;
331 for (i = 0; i < nfiles * 2; i++) {
335 * rename two random entries
337 r = random() % nfiles;
338 sprintf(buf, "XXXXXXXXXXXX.%ld", r);
339 r = random() % nfiles;
340 sprintf(buf1, "XXXXXXXXXXXX.%ld", r);
342 if (verbose) fprintf(stderr,"** [%d] rename %s %s\n", pid, buf, buf1);
343 if (rename(buf, buf1)) {
345 if (checkflag) return 1;
350 * unlink a random entry
352 r = random() % nfiles;
353 sprintf(buf, "XXXXXXXXXXXX.%ld", r);
354 if (verbose) fprintf(stderr,"** [%d] unlink %s\n", pid, buf);
356 fprintf(stderr,"!! [%d] unlink %s failed\n", pid, buf);
358 if (checkflag) return 1;
363 * rmdir a random entry
365 r = random() % nfiles;
366 sprintf(buf, "XXXXXXXXXXXX.%ld", r);
367 if (verbose) fprintf(stderr,"** [%d] rmdir %s\n", pid, buf);
369 fprintf(stderr,"!! [%d] rmdir %s failed\n", pid, buf);
371 if (checkflag) return 1;
376 * create a random entry
378 r = random() % nfiles;
379 sprintf(buf, "XXXXXXXXXXXX.%ld", r);
381 if (verbose) fprintf(stderr,"** [%d] creat %s 0666\n", pid, buf);
382 fd = creat(buf, 0666);
384 if (verbose) fprintf(stderr,"** [%d] close %s\n", pid, buf);
386 fprintf(stderr,"!! [%d] close %s failed\n", pid, buf);
388 if (checkflag) return 1;
391 fprintf(stderr,"!! [%d] creat %s 0666 failed\n", pid, buf);
393 if (checkflag) return 1;
398 * mkdir a random entry
400 r = random() % nfiles;
401 sprintf(buf, "XXXXXXXXXXXX.%ld", r);
402 if (verbose) fprintf(stderr,"** [%d] mkdir %s\n", pid, buf);
403 if (mkdir(buf, 0777)) {
404 fprintf(stderr,"!! [%d] mkdir %s failed\n", pid, buf);
406 if (checkflag) return 1;
425 for (i = 0; i < nfiles; i++) {
426 sprintf(buf, "XXXXXXXXXXXX.%d", i);
427 error = lstat(buf, &statb);
429 /* ignore this one */
432 if (S_ISDIR(statb.st_mode)) {
433 if (verbose) fprintf(stderr,"** [%d] rmdir %s\n", pid, buf);
435 fprintf(stderr,"!! [%d] rmdir %s failed\n", pid, buf);
437 if (checkflag) return 1;
440 if (verbose) fprintf(stderr,"** [%d] unlink %s\n", pid, buf);
442 fprintf(stderr,"!! [%d] unlink %s failed\n", pid, buf);
444 if (checkflag) return 1;