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.
39 #include <sys/types.h>
48 #include <sys/ioctl.h>
50 #include <liblustre.h>
51 #include <lustre_lib.h>
54 struct option longopts[] = {
56 {"lookup", 0, 0, 'l'},
57 {"random", 0, 0, 'r'},
61 char *shortopts = "ehlr:s0123456789";
63 static int usage(char *prog, FILE *out)
66 "Usage: %s [-r rand_seed] {-s|-e|-l} filenamebase total_files iterations\n"
68 "-s : regular stat() calls\n"
69 "-e : open then GET_EA ioctl\n"
70 "-l : lookup ioctl only\n", prog);
75 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
78 int main(int argc, char ** argv)
80 long i, c, count, iter = LONG_MAX, mode = 0, offset;
81 long int start, length = LONG_MAX, last, rc = 0;
82 char parent[4096], *t;
83 char *prog = argv[0], *base;
87 while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
91 seed = strtoul(optarg, &e, 0);
93 fprintf(stderr, "bad -r option %s\n", optarg);
112 if (length == LONG_MAX)
115 length = length * 10 + (c - '0');
124 if (optind + 2 + (length == LONG_MAX) != argc) {
125 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
130 if (strlen(base) > 4080) {
131 fprintf(stderr, "filenamebase too long\n");
136 int f = open("/dev/urandom", O_RDONLY);
138 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
144 printf("using seed %u\n", seed);
147 count = strtoul(argv[optind + 1], NULL, 0);
148 if (length == LONG_MAX) {
149 iter = strtoul(argv[optind + 2], NULL, 0);
150 printf("running for %lu iterations\n", iter);
152 printf("running for %lu seconds\n", length);
154 start = last = time(0);
156 t = strrchr(base, '/');
161 strncpy(parent, base, t - base);
162 offset = t - base + 1;
166 fd = open(parent, O_RDONLY);
168 printf("open(%s) error: %s\n", parent,
174 for (i = 0; i < iter && time(0) - start < length; i++) {
178 tmp = random() % count;
179 sprintf(filename, "%s%d", base, tmp);
183 fd = open(filename, O_RDWR|O_LARGEFILE);
185 printf("open(%s) error: %s\n", filename,
189 rc = ioctl(fd, LDISKFS_IOC_GETEA, NULL);
191 printf("ioctl(%s) error: %s\n", filename,
198 } else if (mode == 's') {
201 rc = stat(filename, &buf);
203 printf("stat(%s) error: %s\n", filename,
207 } else if (mode == 'l') {
208 struct obd_ioctl_data data;
211 int max = sizeof(rawbuf);
213 memset(&data, 0, sizeof(data));
214 data.ioc_version = OBD_IOCTL_VERSION;
215 data.ioc_len = sizeof(data);
217 data.ioc_inlbuf1 = filename + offset;
219 data.ioc_inlbuf1 = filename;
220 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
222 if (obd_ioctl_pack(&data, &buf, max)) {
223 printf("ioctl_pack failed.\n");
227 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
229 printf("ioctl(%s) error: %s\n", filename,
234 if ((i % 10000) == 0) {
235 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
236 i, time(0), time(0) - start, time(0) - last);
244 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
245 time(0) - start, ((float)i / (time(0) - start)));