1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define PATH_LENGTH 35
42 #include <sys/types.h>
50 char from[PATH_LENGTH];
54 unsigned int loop_count = 500;
55 int file_count = 1000;
69 void usage(const char *progname)
71 fprintf(stderr, "usage: %s [-n numfiles] [-s seed] [-v] [-x] [dir]\n"
72 "\t-c: only do the create step of first loop\n"
73 "\t-f: number of files to create/rename/unlink per loop\n"
74 "\t-n: number of test loops (0 to run forever)\n"
75 "\t-r: only do the rename step of first loop\n"
76 "\t-s: starting seed (equals loop number by default)\n"
78 "\t-x: don't exit on error\n", progname);
81 void handler(int sig) {
82 static long last_time;
85 signal(SIGINT, handler);
86 signal(SIGALRM, handler);
87 printf("%6lds %8d iterations %d/%d/%d errors",
88 now - start, loops, creat_errors, rename_errors, unlink_errors);
90 printf(" - use SIGQUIT (^\\) or ^C^C to kill\n");
96 else if (sig == SIGINT) {
97 if (now - last_time < 2)
107 int main(int argc, char *argv[])
110 char msg[100], *end = NULL;
114 while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) {
120 i = strtoul(optarg, &end, 0);
121 if (i && end != NULL && *end == '\0') {
124 fprintf(stderr, "bad file count '%s'\n",optarg);
130 i = strtoul(optarg, &end, 0);
131 if (i && end != NULL && *end == '\0') {
134 fprintf(stderr, "bad loop count '%s'\n",optarg);
143 i = strtoul(optarg, &end, 0);
144 if (end && *end == '\0') {
148 fprintf(stderr, "using random seed %u\n", seed);
163 names = malloc(sizeof(struct names) * file_count);
169 h2 = sprintf(msg, "%x", file_count); /* just to figure length */
170 h1 = (PATH_LENGTH - h2 - 2) / 4;
172 n = (1ULL << h1 * 4) - 1;
174 //printf("h1 = %d, h2 = %d n = %lu\n", h1, h2, n);
178 signal(SIGQUIT, handler);
179 signal(SIGINT, handler);
180 signal(SIGALRM, handler);
181 signal(SIGUSR1, handler);
184 if (argc > optind + 1) {
185 fprintf(stderr, "too many extra args %d\n", argc - optind);
188 } else if (argv[optind] != NULL) {
189 if (chdir(argv[optind]) < 0) {
190 sprintf(msg, "chdir '%s'\n", argv[optind]);
196 while (!stop && loop_count != 0 && loops < loop_count) {
200 if (mkdir("tmp", S_IRWXU) == -1) {
204 if (chdir("tmp") == -1) {
209 for (i = 0; i < file_count ; i++) {
214 sprintf(names[i].from, "%0*x%0*x%0*x%0*x0%0*x",
215 h1, j, h1, k, h1, l, h1, m, h2, i);
216 sprintf(names[i].to, "%0*x%0*x%0*x%0*x1%0*x",
217 h1, j, h1, k, h1, l, h1, m, h2, i);
221 for (i = 0; i < file_count; i++) {
222 if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) {
223 sprintf(msg, "loop %d.%d: creat %s",
224 loops, i, names[i].from);
227 if (!opt_exit_on_err)
235 for (i = 0; i < file_count; i++) {
236 if (rename(names[i].from, names[i].to) == -1) {
237 sprintf(msg, "loop %d.%d: rename %s to %s",
238 loops, i, names[i].from, names[i].to);
241 if (!opt_exit_on_err)
249 for (i = 0; i < file_count; i++) {
250 if (unlink(names[i].to) == -1) {
251 sprintf(msg, "loop %d.%d: unlink %s",
252 loops, i, names[i].to);
255 if (!opt_exit_on_err)
260 if (chdir("..") == -1) {
265 if (rmdir("tmp") == -1) {
266 if (chdir("tmp") == -1) {
267 perror("chdir tmp 2");
270 for (i = 0; i < file_count; i++) {
271 if (unlink(names[i].from) != -1) {
272 fprintf(stderr, "loop %d.%d: "
273 "unexpected file %s\n",
274 loops, i, names[i].to);
276 if (!opt_exit_on_err)
280 if (chdir("..") == -1) {
281 perror("chdir .. 2");
284 if (rmdir("tmp") == -1) {