4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
30 #define PATH_LENGTH 35
35 #include <sys/types.h>
43 char from[PATH_LENGTH];
47 unsigned int loop_count = 500;
48 int file_count = 1000;
62 static void usage(const char *progname)
64 fprintf(stderr, "usage: %s [-n numfiles] [-s seed] [-v] [-x] [dir]\n"
65 "\t-c: only do the create step of first loop\n"
66 "\t-f: number of files to create/rename/unlink per loop\n"
67 "\t-n: number of test loops (0 to run forever)\n"
68 "\t-r: only do the rename step of first loop\n"
69 "\t-s: starting seed (equals loop number by default)\n"
71 "\t-x: don't exit on error\n", progname);
74 static void handler(int sig)
76 static long last_time;
79 signal(SIGINT, handler);
80 signal(SIGALRM, handler);
81 printf("%6lds %8d iterations %d/%d/%d errors",
82 now - start, loops, creat_errors, rename_errors, unlink_errors);
84 printf(" - use SIGQUIT (^\\) or ^C^C to kill\n");
90 else if (sig == SIGINT) {
91 if (now - last_time < 2)
101 int main(int argc, char *argv[])
104 char msg[100], *end = NULL;
108 while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) {
114 i = strtoul(optarg, &end, 0);
115 if (i && end != NULL && *end == '\0') {
118 fprintf(stderr, "bad file count '%s'\n",optarg);
124 i = strtoul(optarg, &end, 0);
125 if (i && end != NULL && *end == '\0') {
128 fprintf(stderr, "bad loop count '%s'\n",optarg);
137 i = strtoul(optarg, &end, 0);
138 if (end && *end == '\0') {
142 fprintf(stderr, "using random seed %u\n", seed);
157 names = malloc(sizeof(struct names) * file_count);
163 h2 = sprintf(msg, "%x", file_count); /* just to figure length */
164 h1 = (PATH_LENGTH - h2 - 2) / 4;
166 n = (1ULL << h1 * 4) - 1;
168 //printf("h1 = %d, h2 = %d n = %lu\n", h1, h2, n);
172 signal(SIGQUIT, handler);
173 signal(SIGINT, handler);
174 signal(SIGALRM, handler);
175 signal(SIGUSR1, handler);
178 if (argc > optind + 1) {
179 fprintf(stderr, "too many extra args %d\n", argc - optind);
182 } else if (argv[optind] != NULL) {
183 if (chdir(argv[optind]) < 0) {
184 snprintf(msg, sizeof(msg),
185 "chdir '%s'\n", argv[optind]);
191 while (!stop && loop_count != 0 && loops < loop_count) {
195 if (mkdir("tmp", S_IRWXU) == -1) {
199 if (chdir("tmp") == -1) {
204 for (i = 0; i < file_count ; i++) {
209 sprintf(names[i].from, "%0*x%0*x%0*x%0*x0%0*x",
210 h1, j, h1, k, h1, l, h1, m, h2, i);
211 sprintf(names[i].to, "%0*x%0*x%0*x%0*x1%0*x",
212 h1, j, h1, k, h1, l, h1, m, h2, i);
216 for (i = 0; i < file_count; i++) {
217 if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) {
218 sprintf(msg, "loop %d.%d: creat %s",
219 loops, i, names[i].from);
222 if (!opt_exit_on_err)
230 for (i = 0; i < file_count; i++) {
231 if (rename(names[i].from, names[i].to) == -1) {
232 sprintf(msg, "loop %d.%d: rename %s to %s",
233 loops, i, names[i].from, names[i].to);
236 if (!opt_exit_on_err)
244 for (i = 0; i < file_count; i++) {
245 if (unlink(names[i].to) == -1) {
246 sprintf(msg, "loop %d.%d: unlink %s",
247 loops, i, names[i].to);
250 if (!opt_exit_on_err)
255 if (chdir("..") == -1) {
260 if (rmdir("tmp") == -1) {
261 if (chdir("tmp") == -1) {
262 perror("chdir tmp 2");
265 for (i = 0; i < file_count; i++) {
266 if (unlink(names[i].from) != -1) {
267 fprintf(stderr, "loop %d.%d: "
268 "unexpected file %s\n",
269 loops, i, names[i].to);
271 if (!opt_exit_on_err)
275 if (chdir("..") == -1) {
276 perror("chdir .. 2");
279 if (rmdir("tmp") == -1) {