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.
38 #include <sys/types.h>
48 static void usage(char *prog)
50 printf("usage: %s {-o|-m|-d|-l<tgt>} [-r altpath ] filenamefmt count\n", prog);
51 printf(" %s {-o|-m|-d|-l<tgt>} [-r altpath ] filenamefmt ] -seconds\n", prog);
52 printf(" %s {-o|-m|-d|-l<tgt>} [-r altpath ] filenamefmt start count\n", prog);
56 static char *get_file_name(const char *fmt, long n, int has_fmt_spec)
58 static char filename[4096];
61 bytes = has_fmt_spec ? snprintf(filename, 4095, fmt, n) :
62 snprintf(filename, 4095, "%s%ld", fmt, n);
64 printf("file name too long\n");
70 int main(int argc, char ** argv)
73 int rc = 0, do_open = 0, do_link = 0, do_mkdir = 0;
74 int do_unlink = 0, do_mknod = 0;
76 char *fmt = NULL, *fmt_unlink = NULL, *tgt = NULL;
77 long start, last, end = ~0UL >> 1;
78 long begin = 0, count = ~0UL >> 1;
79 int c, has_fmt_spec = 0, unlink_has_fmt_spec = 0;
81 /* Handle the last argument in form of "-seconds" */
82 if (argc > 1 && argv[argc - 1][0] == '-') {
86 end = strtol(argv[argc] + 1, &endp, 0);
87 if (end <= 0 || *endp != '\0')
89 end = end + time(NULL);
92 while ((c = getopt(argc, argv, "omdl:r:")) != -1) {
112 printf("Unknown option '%c'\n", optopt);
117 if (do_open + do_mkdir + do_link + do_mknod != 1 ||
121 switch (argc - optind) {
123 begin = strtol(argv[argc - 2], NULL, 0);
125 count = strtol(argv[argc - 1], NULL, 0);
126 if (end != ~0UL >> 1)
135 start = last = time(NULL);
137 has_fmt_spec = strchr(fmt, '%') != NULL;
139 unlink_has_fmt_spec = strchr(fmt_unlink, '%') != NULL;
141 for (i = 0; i < count && time(NULL) < end; i++, begin++) {
142 filename = get_file_name(fmt, begin, has_fmt_spec);
144 int fd = open(filename, O_CREAT|O_RDWR, 0644);
146 printf("open(%s) error: %s\n", filename,
152 } else if (do_link) {
153 rc = link(tgt, filename);
155 printf("link(%s, %s) error: %s\n",
156 tgt, filename, strerror(errno));
160 } else if (do_mkdir) {
161 rc = mkdir(filename, 0755);
163 printf("mkdir(%s) error: %s\n",
164 filename, strerror(errno));
169 rc = mknod(filename, S_IFREG| 0444, 0);
171 printf("mknod(%s) error: %s\n",
172 filename, strerror(errno));
178 filename = get_file_name(fmt_unlink, begin,
179 unlink_has_fmt_spec);
180 rc = do_mkdir ? rmdir(filename) : unlink(filename);
182 printf("unlink(%s) error: %s\n",
183 filename, strerror(errno));
189 if ((i % 10000) == 0) {
190 printf(" - created %ld (time %ld total %ld last %ld)\n",
191 i, time(0), time(0) - start, time(0) - last);
195 printf("total: %ld creates%s in %ld seconds: %f creates/second\n", i,
196 do_unlink ? "/deletions" : "",
197 time(NULL) - start, ((float)i / (time(0) - start)));