1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
14 #include <sys/ioctl.h>
16 #include <linux/lustre_lite.h>
19 # define O_DIRECT 040000 /* direct disk access hint */
22 int main(int argc, char *argv[])
25 unsigned long count, i;
29 int fd, ioctl_flags = 0;
31 if (argc < 3 || argc > 4) {
32 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
37 count = strtoul(argv[2], NULL, 0);
39 threads = strtoul(argv[3], NULL, 0);
41 for (i = 1; i <= threads; i++) {
44 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
45 strerror(rc = errno));
52 printf("%s: thread #%ld (PID %d) started\n",
57 if (threads && thread == 0) { /* parent process */
58 int live_threads = threads;
60 while (live_threads > 0) {
64 ret = waitpid(0, &status, 0);
69 fprintf(stderr, "error: %s: wait - %s\n",
70 argv[0], strerror(errno));
75 * This is a hack. We _should_ be able to use
76 * WIFEXITED(status) to see if there was an
77 * error, but it appears to be broken and it
78 * always returns 1 (OK). See wait(2).
80 int err = WEXITSTATUS(status);
81 if (err || WIFSIGNALED(status))
83 "%s: PID %d had rc=%d\n",
92 sprintf(filename, "%s-%d", argv[1], thread);
94 strcpy(filename, argv[1]);
96 fd = open(filename, O_RDWR|O_CREAT, 0644);
98 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
103 fprintf(stderr, "close(): %s\n", strerror(errno));
108 for (i = 0; i < count; i++) {
109 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
111 fprintf(stderr, "open(%s, O_RDWR): %s\n",
112 filename, strerror(errno));
116 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
118 fprintf(stderr, "ioctl(): %s\n",
124 fprintf(stderr, "close(): %s\n",
131 if (unlink(filename) < 0) {
132 fprintf(stderr, "unlink(%s): %s\n", filename,
137 printf("Thread %d done: rc = %d\n", thread, rc);
139 printf("Done: rc = %d\n", rc);