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 <libcfs/libcfs.h>
54 #include <lustre/lustre_user.h>
59 int main(int argc, char *argv[])
62 unsigned long count, i;
66 int fd, ioctl_flags = 0;
68 if (argc < 3 || argc > 4) {
69 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
74 count = strtoul(argv[2], NULL, 0);
76 threads = strtoul(argv[3], NULL, 0);
78 for (i = 1; i <= threads; i++) {
81 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
82 strerror(rc = errno));
89 printf("%s: thread #%ld (PID %d) started\n",
94 if (threads && thread == 0) { /* parent process */
95 int live_threads = threads;
97 while (live_threads > 0) {
101 ret = waitpid(0, &status, 0);
108 fprintf(stderr, "error: %s: wait - %s\n",
109 argv[0], strerror(rc));
112 * This is a hack. We _should_ be able to use
113 * WIFEXITED(status) to see if there was an
114 * error, but it appears to be broken and it
115 * always returns 1 (OK). See wait(2).
117 int err = WEXITSTATUS(status);
118 if (err || WIFSIGNALED(status))
120 "%s: PID %d had rc=%d\n",
129 sprintf(filename, "%s-%d", argv[1], thread);
131 strcpy(filename, argv[1]);
133 fd = open(filename, O_RDWR|O_CREAT, 0644);
136 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
142 fprintf(stderr, "close(): %s\n", strerror(rc));
146 for (i = 0; i < count; i++) {
147 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
150 fprintf(stderr, "open(%s, O_RDWR): %s\n",
151 filename, strerror(rc));
154 if (ioctl(fd, LL_IOC_SETFLAGS, &ioctl_flags) < 0 &&
157 fprintf(stderr, "ioctl(): %s\n", strerror(rc));
162 fprintf(stderr, "close(): %s\n", strerror(rc));
167 if (unlink(filename) < 0) {
169 fprintf(stderr, "unlink(%s): %s\n", filename,
173 printf("Thread %d done: rc = %d\n", thread, rc);
175 printf("Done: rc = %d\n", rc);