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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <sys/types.h>
44 #include <sys/ioctl.h>
46 #include <lustre_ioctl.h>
48 struct option longopts[] = {
49 { .name = "lookup", .has_arg = no_argument, .val = 'l' },
50 { .name = "random", .has_arg = no_argument, .val = 'r' },
51 { .name = "stat", .has_arg = no_argument, .val = 's' },
54 char *shortopts = "hlr:s0123456789";
56 static int usage(char *prog, FILE *out)
59 "Usage: %s [-r rand_seed] {-s|-l} filenamebase total_files iterations\n"
61 "-s : regular stat() calls\n"
62 "-l : lookup ioctl only\n", prog);
67 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
70 int main(int argc, char ** argv)
72 long i, count, iter = LONG_MAX, mode = 0, offset;
73 long int start, length = LONG_MAX, last;
74 char parent[4096], *t;
75 char *prog = argv[0], *base;
79 while ((rc = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
83 seed = strtoul(optarg, &e, 0);
85 fprintf(stderr, "bad -r option %s\n", optarg);
103 if (length == LONG_MAX)
106 length = length * 10 + (rc - '0');
115 if (optind + 2 + (length == LONG_MAX) != argc) {
116 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
121 if (strlen(base) > 4080) {
122 fprintf(stderr, "filenamebase too long\n");
127 int f = open("/dev/urandom", O_RDONLY);
129 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
135 printf("using seed %u\n", seed);
138 count = strtoul(argv[optind + 1], NULL, 0);
139 if (length == LONG_MAX) {
140 iter = strtoul(argv[optind + 2], NULL, 0);
141 printf("running for %lu iterations\n", iter);
143 printf("running for %lu seconds\n", length);
145 start = last = time(0);
147 t = strrchr(base, '/');
152 strncpy(parent, base, t - base);
153 offset = t - base + 1;
157 fd = open(parent, O_RDONLY);
159 printf("open(%s) error: %s\n", parent,
165 for (i = 0; i < iter && time(0) - start < length; i++) {
169 tmp = random() % count;
170 sprintf(filename, "%s%d", base, tmp);
175 rc = stat(filename, &buf);
177 printf("stat(%s) error: %s\n", filename,
181 } else if (mode == 'l') {
182 struct obd_ioctl_data data;
185 int max = sizeof(rawbuf);
187 memset(&data, 0, sizeof(data));
188 data.ioc_version = OBD_IOCTL_VERSION;
189 data.ioc_len = sizeof(data);
191 data.ioc_inlbuf1 = filename + offset;
193 data.ioc_inlbuf1 = filename;
194 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
196 if (obd_ioctl_pack(&data, &buf, max)) {
197 printf("ioctl_pack failed.\n");
201 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
203 printf("ioctl(%s) error: %s\n", filename,
208 if ((i % 10000) == 0) {
209 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
210 i, time(0), time(0) - start, time(0) - last);
218 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
219 time(0) - start, ((float)i / (time(0) - start)));