1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
11 #include <sys/types.h>
17 #include <sys/ioctl.h>
19 #include <lustre/lustre_user.h>
21 int main(int argc, char *argv[])
24 unsigned long count, i;
28 int fd, ioctl_flags = 0;
30 if (argc < 3 || argc > 4) {
31 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
36 count = strtoul(argv[2], NULL, 0);
38 threads = strtoul(argv[3], NULL, 0);
40 for (i = 1; i <= threads; i++) {
43 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
44 strerror(rc = errno));
51 printf("%s: thread #%ld (PID %d) started\n",
56 if (threads && thread == 0) { /* parent process */
57 int live_threads = threads;
59 while (live_threads > 0) {
63 ret = waitpid(0, &status, 0);
68 fprintf(stderr, "error: %s: wait - %s\n",
69 argv[0], strerror(errno));
74 * This is a hack. We _should_ be able to use
75 * WIFEXITED(status) to see if there was an
76 * error, but it appears to be broken and it
77 * always returns 1 (OK). See wait(2).
79 int err = WEXITSTATUS(status);
80 if (err || WIFSIGNALED(status))
82 "%s: PID %d had rc=%d\n",
91 sprintf(filename, "%s-%d", argv[1], thread);
93 strcpy(filename, argv[1]);
95 fd = open(filename, O_RDWR|O_CREAT, 0644);
97 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
102 fprintf(stderr, "close(): %s\n", strerror(errno));
107 for (i = 0; i < count; i++) {
108 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
110 fprintf(stderr, "open(%s, O_RDWR): %s\n",
111 filename, strerror(errno));
115 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
117 fprintf(stderr, "ioctl(): %s\n",
123 fprintf(stderr, "close(): %s\n",
130 if (unlink(filename) < 0) {
131 fprintf(stderr, "unlink(%s): %s\n", filename,
136 printf("Thread %d done: rc = %d\n", thread, rc);
138 printf("Done: rc = %d\n", rc);