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>
24 int main(int argc, char *argv[])
27 unsigned long count, i;
31 int fd, ioctl_flags = 0;
33 if (argc < 3 || argc > 4) {
34 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
39 count = strtoul(argv[2], NULL, 0);
41 threads = strtoul(argv[3], NULL, 0);
43 for (i = 1; i <= threads; i++) {
46 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
47 strerror(rc = errno));
54 printf("%s: thread #%ld (PID %d) started\n",
59 if (threads && thread == 0) { /* parent process */
60 int live_threads = threads;
62 while (live_threads > 0) {
66 ret = waitpid(0, &status, 0);
71 fprintf(stderr, "error: %s: wait - %s\n",
72 argv[0], strerror(errno));
77 * This is a hack. We _should_ be able to use
78 * WIFEXITED(status) to see if there was an
79 * error, but it appears to be broken and it
80 * always returns 1 (OK). See wait(2).
82 int err = WEXITSTATUS(status);
83 if (err || WIFSIGNALED(status))
85 "%s: PID %d had rc=%d\n",
94 sprintf(filename, "%s-%d", argv[1], thread);
96 strcpy(filename, argv[1]);
98 fd = open(filename, O_RDWR|O_CREAT, 0644);
100 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
105 fprintf(stderr, "close(): %s\n", strerror(errno));
110 for (i = 0; i < count; i++) {
111 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
113 fprintf(stderr, "open(%s, O_RDWR): %s\n",
114 filename, strerror(errno));
118 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
120 fprintf(stderr, "ioctl(): %s\n",
126 fprintf(stderr, "close(): %s\n",
133 if (unlink(filename) < 0) {
134 fprintf(stderr, "unlink(%s): %s\n", filename,
139 printf("Thread %d done: rc = %d\n", thread, rc);
141 printf("Done: rc = %d\n", rc);