1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
13 #include <sys/types.h>
19 #include <sys/ioctl.h>
21 #include <lustre/lustre_user.h>
26 int main(int argc, char *argv[])
29 unsigned long count, i;
33 int fd, ioctl_flags = 0;
35 if (argc < 3 || argc > 4) {
36 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
41 count = strtoul(argv[2], NULL, 0);
43 threads = strtoul(argv[3], NULL, 0);
45 for (i = 1; i <= threads; i++) {
48 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
49 strerror(rc = errno));
56 printf("%s: thread #%ld (PID %d) started\n",
61 if (threads && thread == 0) { /* parent process */
62 int live_threads = threads;
64 while (live_threads > 0) {
68 ret = waitpid(0, &status, 0);
75 fprintf(stderr, "error: %s: wait - %s\n",
76 argv[0], strerror(rc));
79 * This is a hack. We _should_ be able to use
80 * WIFEXITED(status) to see if there was an
81 * error, but it appears to be broken and it
82 * always returns 1 (OK). See wait(2).
84 int err = WEXITSTATUS(status);
85 if (err || WIFSIGNALED(status))
87 "%s: PID %d had rc=%d\n",
96 sprintf(filename, "%s-%d", argv[1], thread);
98 strcpy(filename, argv[1]);
100 fd = open(filename, O_RDWR|O_CREAT, 0644);
103 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
109 fprintf(stderr, "close(): %s\n", strerror(rc));
113 for (i = 0; i < count; i++) {
114 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
117 fprintf(stderr, "open(%s, O_RDWR): %s\n",
118 filename, strerror(rc));
121 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
124 fprintf(stderr, "ioctl(): %s\n", strerror(rc));
129 fprintf(stderr, "close(): %s\n", strerror(rc));
134 if (unlink(filename) < 0) {
136 fprintf(stderr, "unlink(%s): %s\n", filename,
140 printf("Thread %d done: rc = %d\n", thread, rc);
142 printf("Done: rc = %d\n", rc);