12 #include <sys/ioctl.h>
15 #include <linux/extN_fs.h>
17 #include <liblustre.h>
18 #include <linux/lustre_lib.h>
19 #include <linux/obd.h>
21 struct option longopts[] = {
23 {"lookup", 0, 0, 'l'},
24 {"random", 0, 0, 'r'},
28 char *shortopts = "ehlr:s0123456789";
30 static int usage(char *prog, FILE *out)
33 "Usage: %s [-r rand_seed] {-s|-e|-l} filenamebase total_files iterations\n"
35 "-s : regular stat() calls\n"
36 "-e : open then GET_EA ioctl\n"
37 "-l : lookup ioctl only\n", prog);
42 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
45 int main(int argc, char ** argv)
47 long i, count, iter = LONG_MAX, mode = 0, offset;
48 long int start, length = LONG_MAX, last, rc = 0;
49 char parent[4096], *t;
50 char c, *prog = argv[0], *base;
54 while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
58 seed = strtoul(optarg, &e, 0);
60 fprintf(stderr, "bad -r option %s\n", optarg);
79 if (length == LONG_MAX)
82 length = length * 10 + (c - '0');
92 fprintf(stderr, "one of '-l', '-e', or '-s' must be supplied.\n");
96 if (optind + 2 + (length == LONG_MAX) != argc) {
97 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
102 if (strlen(base) > 4080) {
103 fprintf(stderr, "filenamebase too long\n");
108 int f = open("/dev/urandom", O_RDONLY);
110 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
116 printf("using seed %u\n", seed);
119 count = strtoul(argv[optind + 1], NULL, 0);
120 if (length == LONG_MAX) {
121 iter = strtoul(argv[optind + 2], NULL, 0);
122 printf("running for %lu iterations\n", iter);
124 printf("running for %lu seconds\n", length);
126 start = last = time(0);
128 t = strrchr(base, '/');
133 strncpy(parent, base, t - base);
134 offset = t - base + 1;
138 fd = open(parent, O_RDONLY);
140 printf("open(%s) error: %s\n", parent,
146 for (i = 0; i < iter && time(0) - start < length; i++) {
150 tmp = random() % count;
151 sprintf(filename, "%s%d", base, tmp);
155 fd = open(filename, O_RDWR|O_LARGEFILE);
157 printf("open(%s) error: %s\n", filename,
161 rc = ioctl(fd, EXTN_IOC_GETEA, NULL);
163 printf("ioctl(%s) error: %s\n", filename,
170 } else if (mode == 's') {
173 rc = stat(filename, &buf);
175 printf("stat(%s) error: %s\n", filename,
179 } else if (mode == 'l') {
180 struct obd_ioctl_data data;
183 int max = sizeof(rawbuf);
185 memset(&data, 0, sizeof(data));
186 data.ioc_version = OBD_IOCTL_VERSION;
187 data.ioc_len = sizeof(data);
189 data.ioc_inlbuf1 = filename + offset;
191 data.ioc_inlbuf1 = filename;
192 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
194 if (obd_ioctl_pack(&data, &buf, max)) {
195 printf("ioctl_pack failed.\n");
199 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
201 printf("ioctl(%s) error: %s\n", filename,
206 if ((i % 10000) == 0) {
207 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
208 i, time(0), time(0) - start, time(0) - last);
216 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
217 time(0) - start, ((float)i / (time(0) - start)));