- /* if we're not measuring creation rates then precreate
- * the files we're operating on. */
- if ((mode != CREATE) && (mode != MKNOD) && !ignore &&
- (mode != UNLINK || recreate)) {
- /* create the files in reverse order. When we encounter
- * a file that already exists, assume the remainder of
- * the files exist to save time. The timed performance
- * test scripts make use of this behavior. */
- for (i = end, j = 0; i >= begin; i -= dirthreads) {
- sprintf(filename, filefmt, i);
- fd = open(filename, openflags, 0644);
- if (fd < 0) {
- if (errno == EEXIST)
- break;
- rc = errno;
- fatal(myrank, "precreate open(%s) error: %s\n",
- filename, strerror(rc));
- }
- j++;
- close(fd);
- }
- dmesg("%d: %s pre-created %d files.\n",myrank,hostname,j);
-
- rc = MPI_Barrier(MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS)
- fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
- }
-
- if (order == READDIR) {
- directory = opendir(dir);
- if (directory == NULL) {
- rc = errno;
- fatal(myrank, "opendir(%s) error: %s\n",
- dir, strerror(rc));
- }
-
- timestamp = time(0);
- j = random() % nfiles;
- dmesg("%d: %s initializing dir offset %u: %s",
- myrank, hostname, j, ctime(×tamp));
-
- for (i = 0; i <= j; i++) {
- if ((dir_entry = readdir(directory)) == NULL) {
- fatal(myrank, "could not read entry number %d "
- "in directory %s.\n", i, dir);
- }
- }
-
- timestamp = time(0);
- dmesg("%d: index %d, filename %s, offset %ld: "
- "%s initialization complete: %s",
- myrank, i, dir_entry->d_name, telldir(directory),
- hostname, ctime(×tamp));
- }
-
- if (seconds) {
- act.sa_handler = sigalrm_handler;
- (void)sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- sigaction(SIGALRM, &act, NULL);
- alarm(seconds);
- }
-
- rc = MPI_Barrier(MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS)
- fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
-
- startTime = lastTime = MPI_Wtime();
- nops = lastOps = 0;
-
- switch (mode) {
- case CREATE:
- for (; begin <= end && !alarm_caught; begin += dirthreads) {
- sprintf(filename, filefmt, begin);
- if ((fd = open(filename, openflags, 0644)) < 0) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- fatal(myrank, "open(%s) error: %s\n",
- filename, strerror(rc));
- }
-
- close(fd);
- nops++;
- DISPLAY_PROGRESS();
- }
-
- dmesg("%d: created %d files, last file '%s'.\n",
- myrank, nops, filename);
- break;
-#ifdef HAVE_MDC_LOOKUP
- case LOOKUP:
- fd = open(dir, O_RDONLY);
- if (fd < 0) {
- fatal(myrank, "open(dir == '%s') error: %s\n",
- dir, strerror(errno));
- }
-
- for (; nops < iters && !alarm_caught;) {
- char *filename = next_file();
- rc = llapi_file_lookup(fd, filename);
- if (rc < 0) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- fatal(myrank, "llapi_file_lookup(%s) "
- "error: %s\n", filename, strerror(rc));
- }
-
- nops++;
- DISPLAY_PROGRESS();
- }
- break;
-#endif
- case MKNOD:
- for (; begin <= end && !alarm_caught; begin += dirthreads) {
- sprintf(filename, filefmt, begin);
- rc = mknod(filename, S_IFREG| 0644, 0);
- if (rc) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- fatal(myrank, "mknod(%s) error: %s\n",
- filename, strerror(rc));
- }
-
- nops++;
- DISPLAY_PROGRESS();
- }
- break;
- case OPEN:
- for (; nops < iters && !alarm_caught;) {
- file = next_file();
- if ((fd = open(file, openflags, 0644)) < 0) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- fatal(myrank, "open(%s) error: %s\n",
- file, strerror(rc));
- }
-
- close(fd);
-
- nops++;
- DISPLAY_PROGRESS();
- }
- break;
- case STAT:
- for (; begin <= end && !alarm_caught; begin += dirthreads) {
- sprintf(filename, filefmt, begin);
- rc = stat(filename, &statbuf);
- if (rc) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- if (((rc = errno) == ENOENT) && ignore)
- continue;
- fatal(myrank, "stat(%s) error: %s\n",
- filename, strerror(rc));
- }
-
- nops++;
- DISPLAY_PROGRESS();
- }
- break;
- case UNLINK:
- for (; begin <= end && !alarm_caught; begin += dirthreads) {
- sprintf(filename, filefmt, begin);
- rc = unlink(filename);
- if (rc) {
- if (((rc = errno) == EINTR) && alarm_caught)
- break;
- if ((rc = errno) == ENOENT) {
- if (ignore)
- continue;
- /* no more files to unlink */
- break;
- }
- fatal(myrank, "unlink(%s) error: %s\n",
- filename, strerror(rc));
- }
-
- nops++;
- DISPLAY_PROGRESS();
- }
- break;
- }
-
- rc = MPI_Barrier(MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS)
- fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
- curTime = MPI_Wtime();
- interval = curTime - startTime;
- rate = (double) (nops) / interval;
-
- rc = MPI_Reduce(&nops, &ag_ops, 1, MPI_INT, MPI_SUM, 0,
- MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS) {
- fatal(myrank, "Failure in MPI_Reduce of total ops.\n");
- }
-
- rc = MPI_Reduce(&interval, &ag_interval, 1, MPI_DOUBLE, MPI_SUM, 0,
- MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS) {
- fatal(myrank, "Failure in MPI_Reduce of total interval.\n");
- }
-
- rc = MPI_Reduce(&rate, &ag_rate, 1, MPI_DOUBLE, MPI_SUM, 0,
- MPI_COMM_WORLD);
- if (rc != MPI_SUCCESS) {
- fatal(myrank, "Failure in MPI_Reduce of aggregated rate.\n");
- }
-
- if (myrank == 0) {
-
- curTime = MPI_Wtime();
- interval = curTime - startTime;
- effective_rate = (double) ag_ops / interval;
- avg_rate = (double) ag_ops / ag_interval;
-
- printf("Rate: %.2f eff %.2f aggr %.2f avg client %ss/sec "
- "(total: %d threads %d %ss %d dirs %d threads/dir %.2f secs)\n",
- effective_rate, ag_rate, avg_rate, cmd, nthreads, ag_ops,
- cmd, ndirs, dirthreads, interval);
- if (mode == UNLINK && !recreate && !ignore && ag_ops != nfiles)
- printf("Warning: only unlinked %d files instead of %d"
- "\n", ag_ops, nfiles);
- }
-
- if (recreate) {
- for (begin = beginsave; begin <= end; begin += dirthreads) {
- sprintf(filename, filefmt, begin);
- if ((fd = open(filename, openflags, 0644)) < 0) {
- rc = errno;
+ /*
+ * if we're not measuring creation rates then precreate
+ * the files we're operating on.
+ */
+ if ((mode != CREATE) && (mode != MKNOD) && !ignore &&
+ (mode != UNLINK || recreate)) {
+ /*
+ * create the files in reverse order. When we encounter
+ * a file that already exists, assume the remainder of
+ * the files exist to save time. The timed performance
+ * test scripts make use of this behavior.
+ */
+ for (i = end, j = 0; i >= begin; i -= dirthreads) {
+ sprintf(filename, filefmt, i);
+ fd = open(filename, openflags, 0644);
+ if (fd < 0) {
+ if (errno == EEXIST)
+ break;
+ rc = errno;
+ fatal(myrank, "precreate open(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+ j++;
+ close(fd);
+ }
+ dmesg("%d: %s pre-created %d files.\n", myrank, hostname, j);
+
+ rc = MPI_Barrier(MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
+ }
+
+ if (order == READDIR) {
+ directory = opendir(dir);
+ if (!directory) {
+ rc = errno;
+ fatal(myrank, "opendir(%s) error: %s\n",
+ dir, strerror(rc));
+ }
+
+ timestamp = time(0);
+ j = random() % nfiles;
+ dmesg("%d: %s initializing dir offset %u: %s",
+ myrank, hostname, j, ctime(×tamp));
+
+ for (i = 0; i <= j; i++) {
+ if ((dir_entry = readdir(directory)) == NULL) {
+ fatal(myrank,
+ "could not read entry number %d in directory %s.\n",
+ i, dir);
+ }
+ }
+
+ timestamp = time(0);
+ dmesg("%d: index %d, filename %s, offset %ld: %s initialization complete: %s",
+ myrank, i, dir_entry->d_name, telldir(directory),
+ hostname, ctime(×tamp));
+ }
+
+ if (seconds) {
+ act.sa_handler = sigalrm_handler;
+ (void)sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ sigaction(SIGALRM, &act, NULL);
+ alarm(seconds);
+ }
+
+ rc = MPI_Barrier(MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
+
+ startTime = MPI_Wtime();
+ lastTime = MPI_Wtime();
+ nops = 0;
+ lastOps = 0;
+
+ switch (mode) {
+ case CREATE:
+ for (; begin <= end && !alarm_caught; begin += dirthreads) {
+ snprintf(filename, sizeof(filename), filefmt, begin);
+ fd = open(filename, openflags, 0644);
+ if (fd < 0) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ fatal(myrank, "open(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ if (with_xattr) {
+ rc = fsetxattr(fd, xattrname, xattrbuf,
+ xattrlen, XATTR_CREATE);
+ if (rc) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ fatal(myrank,
+ "setxattr(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+ }
+ if (smallwrite) {
+ rc = write(fd, xattrbuf, xattrlen);
+ if (rc < 0) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ fatal(myrank,
+ "write(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+ }
+
+ close(fd);
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+
+ dmesg("%d: created %d files, last file '%s'.\n",
+ myrank, nops, filename);
+ break;
+ case LOOKUP:
+ fd = open(dir, O_RDONLY);
+ if (fd < 0) {
+ fatal(myrank, "open(dir == '%s') error: %s\n",
+ dir, strerror(errno));
+ }
+
+ for (; nops < iters && !alarm_caught;) {
+ char *filename = next_file();
+
+ rc = llapi_file_lookup(fd, filename);
+ if (rc < 0) {
+ if (((rc = errno) == EINTR) && alarm_caught)
+ break;
+ fatal(myrank,
+ "llapi_file_lookup(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ case MKNOD:
+ for (; begin <= end && !alarm_caught; begin += dirthreads) {
+ snprintf(filename, sizeof(filename), filefmt, begin);
+ rc = mknod(filename, S_IFREG | 0644, 0);
+ if (rc) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ fatal(myrank, "mknod(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ if (with_xattr) {
+ rc = setxattr(filename, xattrname, xattrbuf,
+ xattrlen, XATTR_CREATE);
+ if (rc) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ fatal(myrank,
+ "setxattr(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+ }
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ case OPEN:
+ for (; nops < iters && !alarm_caught;) {
+ file = next_file();
+ if ((fd = open(file, openflags, 0644)) < 0) {
+ if (((rc = errno) == EINTR) && alarm_caught)
+ break;
+ fatal(myrank, "open(%s) error: %s\n",
+ file, strerror(rc));
+ }
+
+ close(fd);
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ case STAT:
+ for (; begin <= end && !alarm_caught; begin += dirthreads) {
+ sprintf(filename, filefmt, begin);
+ rc = stat(filename, &statbuf);
+ if (rc) {
+ if (((rc = errno) == EINTR) && alarm_caught)
+ break;
+ if (((rc = errno) == ENOENT) && ignore)
+ continue;
+ fatal(myrank, "stat(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ case UNLINK:
+ for (; begin <= end && !alarm_caught; begin += dirthreads) {
+ sprintf(filename, filefmt, begin);
+ rc = unlink(filename);
+ if (rc) {
+ if (((rc = errno) == EINTR) && alarm_caught)
+ break;
+ if ((rc = errno) == ENOENT) {
+ if (ignore)
+ continue;
+ /* no more files to unlink */
+ break;
+ }
+ fatal(myrank, "unlink(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ case SETXATTR:
+ for (; begin <= end && !alarm_caught; begin += dirthreads) {
+ snprintf(filename, sizeof(filename), filefmt, begin);
+ rc = setxattr(filename, xattrname, xattrbuf, xattrlen,
+ XATTR_CREATE);
+ if (rc) {
+ rc = errno;
+ if (rc == EINTR && alarm_caught)
+ break;
+ if (rc == ENOENT && ignore)
+ continue;
+ fatal(myrank, "setxattr(%s) error: %s\n",
+ filename, strerror(rc));
+ }
+
+ nops++;
+ DISPLAY_PROGRESS();
+ }
+ break;
+ }
+
+ rc = MPI_Barrier(MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
+ curTime = MPI_Wtime();
+ interval = curTime - startTime;
+ rate = (double)(nops) / interval;
+
+ rc = MPI_Reduce(&nops, &ag_ops, 1, MPI_INT, MPI_SUM, 0,
+ MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "Failure in MPI_Reduce of total ops.\n");
+
+ rc = MPI_Reduce(&interval, &ag_interval, 1, MPI_DOUBLE, MPI_SUM, 0,
+ MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "Failure in MPI_Reduce of total interval.\n");
+
+ rc = MPI_Reduce(&rate, &ag_rate, 1, MPI_DOUBLE, MPI_SUM, 0,
+ MPI_COMM_WORLD);
+ if (rc != MPI_SUCCESS)
+ fatal(myrank, "Failure in MPI_Reduce of aggregated rate.\n");
+
+ if (myrank == 0) {
+ curTime = MPI_Wtime();
+ interval = curTime - startTime;
+ effective_rate = (double)ag_ops / interval;
+ avg_rate = (double)ag_ops / ag_interval;
+
+ printf("Rate: %.2f eff %.2f aggr %.2f avg client %ss/sec (total: %d threads %d %ss %d dirs %d threads/dir %.2f secs)\n",
+ effective_rate, ag_rate, avg_rate, cmd, nthreads, ag_ops,
+ cmd, ndirs, dirthreads, interval);
+ if (mode == UNLINK && !recreate && !ignore && ag_ops != nfiles)
+ printf("Warning: only unlinked %d files instead of %d\n",
+ ag_ops, nfiles);
+ }
+
+ if (recreate) {
+ for (begin = beginsave; begin <= end; begin += dirthreads) {
+ sprintf(filename, filefmt, begin);
+ if ((fd = open(filename, openflags, 0644)) < 0) {
+ rc = errno;