12 #include <sys/ioctl.h>
15 #include <linux/ldiskfs_fs.h>
17 #include <liblustre.h>
18 #include <lustre_lib.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, c, count, iter = LONG_MAX, mode = 0, offset;
48 long int start, length = LONG_MAX, last, rc = 0;
49 char parent[4096], *t;
50 char *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');
91 if (optind + 2 + (length == LONG_MAX) != argc) {
92 fprintf(stderr, "missing filenamebase, total_files, or iterations\n");
97 if (strlen(base) > 4080) {
98 fprintf(stderr, "filenamebase too long\n");
103 int f = open("/dev/urandom", O_RDONLY);
105 if (f < 0 || read(f, &seed, sizeof(seed)) < sizeof(seed))
111 printf("using seed %u\n", seed);
114 count = strtoul(argv[optind + 1], NULL, 0);
115 if (length == LONG_MAX) {
116 iter = strtoul(argv[optind + 2], NULL, 0);
117 printf("running for %lu iterations\n", iter);
119 printf("running for %lu seconds\n", length);
121 start = last = time(0);
123 t = strrchr(base, '/');
128 strncpy(parent, base, t - base);
129 offset = t - base + 1;
133 fd = open(parent, O_RDONLY);
135 printf("open(%s) error: %s\n", parent,
141 for (i = 0; i < iter && time(0) - start < length; i++) {
145 tmp = random() % count;
146 sprintf(filename, "%s%d", base, tmp);
150 fd = open(filename, O_RDWR|O_LARGEFILE);
152 printf("open(%s) error: %s\n", filename,
156 rc = ioctl(fd, LDISKFS_IOC_GETEA, NULL);
158 printf("ioctl(%s) error: %s\n", filename,
165 } else if (mode == 's') {
168 rc = stat(filename, &buf);
170 printf("stat(%s) error: %s\n", filename,
174 } else if (mode == 'l') {
175 struct obd_ioctl_data data;
178 int max = sizeof(rawbuf);
180 memset(&data, 0, sizeof(data));
181 data.ioc_version = OBD_IOCTL_VERSION;
182 data.ioc_len = sizeof(data);
184 data.ioc_inlbuf1 = filename + offset;
186 data.ioc_inlbuf1 = filename;
187 data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
189 if (obd_ioctl_pack(&data, &buf, max)) {
190 printf("ioctl_pack failed.\n");
194 rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
196 printf("ioctl(%s) error: %s\n", filename,
201 if ((i % 10000) == 0) {
202 printf(" - stat %lu (time %ld ; total %ld ; last %ld)\n",
203 i, time(0), time(0) - start, time(0) - last);
211 printf("total: %lu stats in %ld seconds: %f stats/second\n", i,
212 time(0) - start, ((float)i / (time(0) - start)));