12 #include <sys/ioctl.h>
14 #include <liblustre.h>
15 #include <lustre_lib.h>
18 struct option longopts[] = {
20 {"lookup", 0, 0, 'l'},
21 {"random", 0, 0, 'r'},
25 char *shortopts = "ehlr:s0123456789";
27 static int usage(char *prog, FILE *out)
30 "Usage: %s [-r rand_seed] {-s|-e|-l} filenamebase total_files iterations\n"
32 "-s : regular stat() calls\n"
33 "-e : open then GET_EA ioctl\n"
34 "-l : lookup ioctl only\n", prog);
39 #define LONG_MAX (1 << ((8 * sizeof(long)) - 1))
42 int main(int argc, char ** argv)
44 long i, c, count, iter = LONG_MAX, mode = 0, offset;
45 long int start, length = LONG_MAX, last, rc = 0;
46 char parent[4096], *t;
47 char *prog = argv[0], *base;
51 while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
55 seed = strtoul(optarg, &e, 0);
57 fprintf(stderr, "bad -r option %s\n", optarg);
76 if (length == LONG_MAX)
79 length = length * 10 + (c - '0');
88 if (optind + 2 + (length == LONG_MAX) != argc) {
89 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
94 if (strlen(base) > 4080) {
95 fprintf(stderr, "filenamebase too long\n");
100 int f = open("/dev/urandom", O_RDONLY);
102 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
108 printf("using seed %u\n", seed);
111 count = strtoul(argv[optind + 1], NULL, 0);
112 if (length == LONG_MAX) {
113 iter = strtoul(argv[optind + 2], NULL, 0);
114 printf("running for %lu iterations\n", iter);
116 printf("running for %lu seconds\n", length);
118 start = last = time(0);
120 t = strrchr(base, '/');
125 strncpy(parent, base, t - base);
126 offset = t - base + 1;
130 fd = open(parent, O_RDONLY);
132 printf("open(%s) error: %s\n", parent,
138 for (i = 0; i < iter && time(0) - start < length; i++) {
142 tmp = random() % count;
143 sprintf(filename, "%s%d", base, tmp);
147 fd = open(filename, O_RDWR|O_LARGEFILE);
149 printf("open(%s) error: %s\n", filename,
153 rc = ioctl(fd, LDISKFS_IOC_GETEA, NULL);
155 printf("ioctl(%s) error: %s\n", filename,
162 } else if (mode == 's') {
165 rc = stat(filename, &buf);
167 printf("stat(%s) error: %s\n", filename,
171 } else if (mode == 'l') {
172 struct obd_ioctl_data data;
175 int max = sizeof(rawbuf);
177 memset(&data, 0, sizeof(data));
178 data.ioc_version = OBD_IOCTL_VERSION;
179 data.ioc_len = sizeof(data);
181 data.ioc_inlbuf1 = filename + offset;
183 data.ioc_inlbuf1 = filename;
184 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
186 if (obd_ioctl_pack(&data, &buf, max)) {
187 printf("ioctl_pack failed.\n");
191 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
193 printf("ioctl(%s) error: %s\n", filename,
198 if ((i % 10000) == 0) {
199 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
200 i, time(0), time(0) - start, time(0) - last);
208 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
209 time(0) - start, ((float)i / (time(0) - start)));