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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <sys/types.h>
46 #include <sys/ioctl.h>
48 #include <liblustre.h>
49 #include <lustre_ioctl.h>
51 struct option longopts[] = {
53 {"lookup", 0, 0, 'l'},
54 {"random", 0, 0, 'r'},
58 char *shortopts = "ehlr:s0123456789";
60 static int usage(char *prog, FILE *out)
63 "Usage: %s [-r rand_seed] {-s|-e|-l} filenamebase total_files iterations\n"
65 "-s : regular stat() calls\n"
66 "-e : open then GET_EA ioctl\n"
67 "-l : lookup ioctl only\n", prog);
72 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
75 int main(int argc, char ** argv)
77 long i, count, iter = LONG_MAX, mode = 0, offset;
78 long int start, length = LONG_MAX, last;
79 char parent[4096], *t;
80 char *prog = argv[0], *base;
84 while ((rc = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
88 seed = strtoul(optarg, &e, 0);
90 fprintf(stderr, "bad -r option %s\n", optarg);
109 if (length == LONG_MAX)
112 length = length * 10 + (rc - '0');
121 if (optind + 2 + (length == LONG_MAX) != argc) {
122 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
127 if (strlen(base) > 4080) {
128 fprintf(stderr, "filenamebase too long\n");
133 int f = open("/dev/urandom", O_RDONLY);
135 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
141 printf("using seed %u\n", seed);
144 count = strtoul(argv[optind + 1], NULL, 0);
145 if (length == LONG_MAX) {
146 iter = strtoul(argv[optind + 2], NULL, 0);
147 printf("running for %lu iterations\n", iter);
149 printf("running for %lu seconds\n", length);
151 start = last = time(0);
153 t = strrchr(base, '/');
158 strncpy(parent, base, t - base);
159 offset = t - base + 1;
163 fd = open(parent, O_RDONLY);
165 printf("open(%s) error: %s\n", parent,
171 for (i = 0; i < iter && time(0) - start < length; i++) {
175 tmp = random() % count;
176 sprintf(filename, "%s%d", base, tmp);
180 fd = open(filename, O_RDWR|O_LARGEFILE);
182 printf("open(%s) error: %s\n", filename,
186 rc = ioctl(fd, LDISKFS_IOC_GETEA, NULL);
188 printf("ioctl(%s) error: %s\n", filename,
195 } else if (mode == 's') {
198 rc = stat(filename, &buf);
200 printf("stat(%s) error: %s\n", filename,
204 } else if (mode == 'l') {
205 struct obd_ioctl_data data;
208 int max = sizeof(rawbuf);
210 memset(&data, 0, sizeof(data));
211 data.ioc_version = OBD_IOCTL_VERSION;
212 data.ioc_len = sizeof(data);
214 data.ioc_inlbuf1 = filename + offset;
216 data.ioc_inlbuf1 = filename;
217 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
219 if (obd_ioctl_pack(&data, &buf, max)) {
220 printf("ioctl_pack failed.\n");
224 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
226 printf("ioctl(%s) error: %s\n", filename,
231 if ((i % 10000) == 0) {
232 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
233 i, time(0), time(0) - start, time(0) - last);
241 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
242 time(0) - start, ((float)i / (time(0) - start)));