12 #include <sys/ioctl.h>
15 #include <linux/extN_fs.h>
17 #include <linux/lustre_lib.h>
18 #include <linux/obd.h>
20 struct option longopts[] = {
22 {"lookup", 0, 0, 'l'},
23 {"random", 0, 0, 'r'},
27 char *shortopts = "ehlr:s0123456789";
29 static int usage(char *prog, FILE *out)
32 "Usage: %s [-r rand_seed] {-s|-e|-l} filenamebase total_files iterations\n"
34 "-s : regular stat() calls\n"
35 "-e : open then GET_EA ioctl\n"
36 "-l : lookup ioctl only\n", prog);
41 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
44 int main(int argc, char ** argv)
46 long i, count, iter = LONG_MAX, mode, offset;
47 long int start, length = LONG_MAX, last, rc = 0;
48 char parent[4096], *t;
49 char c, *prog = argv[0], *base;
53 while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
57 seed = strtoul(optarg, &e, 0);
59 fprintf(stderr, "bad -r option %s\n", optarg);
78 if (length == LONG_MAX)
81 length = length * 10 + (c - '0');
90 if (optind + 2 + (length == LONG_MAX) != argc) {
91 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
96 if (strlen(base) > 4080) {
97 fprintf(stderr, "filenamebase too long\n");
102 int f = open("/dev/urandom", O_RDONLY);
104 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
110 printf("using seed %u\n", seed);
113 count = strtoul(argv[optind + 1], NULL, 0);
114 if (length == LONG_MAX) {
115 iter = strtoul(argv[optind + 2], NULL, 0);
116 printf("running for %lu iterations\n", iter);
118 printf("running for %lu seconds\n", length);
120 start = last = time(0);
122 t = strrchr(base, '/');
127 strncpy(parent, base, t - base);
128 offset = t - base + 1;
132 fd = open(parent, O_RDONLY);
134 printf("open(%s) error: %s\n", parent,
140 for (i = 0; i < iter && time(0) - start < length; i++) {
144 tmp = random() % count;
145 sprintf(filename, "%s%d", base, tmp);
149 fd = open(filename, O_RDWR|O_LARGEFILE);
151 printf("open(%s) error: %s\n", filename,
155 rc = ioctl(fd, EXTN_IOC_GETEA, NULL);
157 printf("ioctl(%s) error: %s\n", filename,
164 } else if (mode == 's') {
167 rc = stat(filename, &buf);
169 printf("stat(%s) error: %s\n", filename,
173 } else if (mode == 'l') {
174 struct obd_ioctl_data data;
177 int max = sizeof(rawbuf);
179 memset(&data, 0, sizeof(data));
180 data.ioc_version = OBD_IOCTL_VERSION;
181 data.ioc_len = sizeof(data);
183 data.ioc_inlbuf1 = filename + offset;
185 data.ioc_inlbuf1 = filename;
186 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
188 if (obd_ioctl_pack(&data, &buf, max)) {
189 printf("ioctl_pack failed.\n");
193 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
195 printf("ioctl(%s) error: %s\n", filename,
200 if ((i % 10000) == 0) {
201 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
202 i, time(0), time(0) - start, time(0) - last);
210 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
211 time(0) - start, ((float)i / (time(0) - start)));