1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
45 #include <sys/types.h>
51 #include <sys/ioctl.h>
53 #include <lustre/lustre_user.h>
58 int main(int argc, char *argv[])
61 unsigned long count, i;
65 int fd, ioctl_flags = 0;
67 if (argc < 3 || argc > 4) {
68 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
73 count = strtoul(argv[2], NULL, 0);
75 threads = strtoul(argv[3], NULL, 0);
77 for (i = 1; i <= threads; i++) {
80 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
81 strerror(rc = errno));
88 printf("%s: thread #%ld (PID %d) started\n",
93 if (threads && thread == 0) { /* parent process */
94 int live_threads = threads;
96 while (live_threads > 0) {
100 ret = waitpid(0, &status, 0);
107 fprintf(stderr, "error: %s: wait - %s\n",
108 argv[0], strerror(rc));
111 * This is a hack. We _should_ be able to use
112 * WIFEXITED(status) to see if there was an
113 * error, but it appears to be broken and it
114 * always returns 1 (OK). See wait(2).
116 int err = WEXITSTATUS(status);
117 if (err || WIFSIGNALED(status))
119 "%s: PID %d had rc=%d\n",
128 sprintf(filename, "%s-%d", argv[1], thread);
130 strcpy(filename, argv[1]);
132 fd = open(filename, O_RDWR|O_CREAT, 0644);
135 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
141 fprintf(stderr, "close(): %s\n", strerror(rc));
145 for (i = 0; i < count; i++) {
146 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
149 fprintf(stderr, "open(%s, O_RDWR): %s\n",
150 filename, strerror(rc));
153 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
156 fprintf(stderr, "ioctl(): %s\n", strerror(rc));
161 fprintf(stderr, "close(): %s\n", strerror(rc));
166 if (unlink(filename) < 0) {
168 fprintf(stderr, "unlink(%s): %s\n", filename,
172 printf("Thread %d done: rc = %d\n", thread, rc);
174 printf("Done: rc = %d\n", rc);