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.
37 #include <sys/types.h>
50 const char usage_fmt[] = "Usage: %s <mountpoint>\n";
51 #define INAME_LEN (PATH_MAX + 1)
53 #define CHECK_IT(exp, pstr) \
55 fprintf(stderr, "%s: at %s:%d: ", progname, __FILE__, __LINE__); \
60 #define CHECK_SNPRINTF(rc, len) \
61 CHECK_IT((rc) > 0 && (rc) <= (len), "snprintf() failed")
63 static char *get_iname(char *fname, const char *mtpt)
69 iname = malloc(INAME_LEN);
70 CHECK_IT(iname, "malloc() failed");
72 fd = open(fname, O_CREAT, 0644);
73 if (fd < 0 && errno != EISDIR) {
74 fprintf(stderr, "%s:%d: open(%s) failed: %s\n", __FILE__,
75 __LINE__, fname, strerror(errno));
82 rc = stat(fname, &buf);
84 fprintf(stderr, "%s:%d: stat(%s) failed: %s\n", __FILE__,
85 __LINE__, fname, strerror(errno));
89 rc = snprintf(iname, INAME_LEN,
90 "%s/__iopen__/%lu", mtpt, (unsigned long)buf.st_ino);
91 CHECK_SNPRINTF(rc, INAME_LEN);
96 int main(int argc, char *argv[])
99 char *fname_iname, *dir;
100 char *dir_iname = NULL, *foo = NULL, *bar = NULL;
101 int rc, fd, i, thread = 0;
104 progname = basename(argv[0]);
107 fprintf(stderr, usage_fmt, progname);
111 for (i = 1; i <= 10; i++) {
114 fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
115 strerror(rc = errno));
117 } else if (rc == 0) {
121 printf("%s: thread #%d (PID %d) started\n", argv[0], i, rc);
128 fname = malloc(INAME_LEN);
129 CHECK_IT(fname, "malloc() failed");
131 rc = snprintf(fname, INAME_LEN,
132 "%s/%d", mtpt, getpid());
133 CHECK_SNPRINTF(rc, INAME_LEN);
135 rc = mkdir(fname, 0644);
137 fprintf(stderr, "%s:%d: mkdir(%s) failed: %s\n",
138 __FILE__, __LINE__, fname, strerror(errno));
142 fname_iname = get_iname(fname, mtpt);
144 dir = malloc(INAME_LEN);
145 CHECK_IT(dir, "malloc() failed");
147 rc = snprintf(dir, INAME_LEN, "%s/dir", fname_iname);
148 CHECK_SNPRINTF(rc, INAME_LEN);
150 foo = malloc(INAME_LEN);
151 CHECK_IT(foo, "malloc() failed");
153 bar = malloc(INAME_LEN);
154 CHECK_IT(bar, "malloc() failed");
156 for (i = 0; i < 1000; i++) {
157 rc = mkdir(dir, 0644);
159 fprintf(stderr, "%s:%d: mkdir(%s) failed: %s\n",
160 __FILE__, __LINE__, dir,
165 dir_iname = get_iname(dir, mtpt);
167 rc = snprintf(foo, INAME_LEN, "%s/bar", dir_iname);
168 CHECK_SNPRINTF(rc, INAME_LEN);
170 rc = snprintf(bar, INAME_LEN, "%s/bar", dir_iname);
171 CHECK_SNPRINTF(rc, INAME_LEN);
173 fd = open(foo, O_CREAT, 0644);
175 fprintf(stderr, "%s:%d: open(%s) failed: %s\n",
176 __FILE__, __LINE__, foo,
182 fprintf(stderr, "%s:%d: close() failed: %s\n",
183 __FILE__, __LINE__, strerror(errno));
187 rc = rename(foo, bar);
189 fprintf(stderr, "%s:%d: rename(%s, %s) failed: "
190 "%s\n", __FILE__, __LINE__, foo, bar,
197 fprintf(stderr, "%s:%d: unlink(%s) failed: "
198 "%s\n", __FILE__, __LINE__, bar,
204 fprintf(stderr, "%s:%d: rmdir(%s) failed: %s\n",
205 __FILE__, __LINE__, dir,
213 for ( i=0; i<10; i++)
214 waitpid(pidlist[i], NULL, 0);