Whamcloud - gitweb
b=18551 cleanup lnet_selftest module after test
[fs/lustre-release.git] / lustre / tests / mpi / write_disjoint.c
index 9b28d60..f5b3454 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -77,17 +77,18 @@ void rprintf(int rank, int loop, const char *fmt, ...)
 #define CHUNK_SIZE(n) chunk_size[(n) % 2]
 
 int main (int argc, char *argv[]) {
-        int i, n, fd;
+        int i, n, fd, c;
         unsigned long chunk_size[2];
         int rank, noProcessors, done;
         int error;
         off_t offset;
         char **chunk_buf;
-        char *read_buf, c;
+        char *read_buf;
         struct stat stat_buf;
         ssize_t ret;
         char *filename = "/mnt/lustre/write_disjoint";
         int numloops = 1000;
+        int random = 0;
 
         error = MPI_Init(&argc, &argv);
         if (error != MPI_SUCCESS)
@@ -133,12 +134,23 @@ int main (int argc, char *argv[]) {
                         if (ret != 0)
                                 rprintf(rank, n, "truncate() returned %s\n",
                                         strerror(errno) );
+                        random = rand();
                 }
-                CHUNK_SIZE(n) = rand() % CHUNK_MAX_SIZE;
+                MPI_Bcast(&random, 1, MPI_INT, 0, MPI_COMM_WORLD);
+                CHUNK_SIZE(n) = random % CHUNK_MAX_SIZE;
 
                 if (n % 1000 == 0 && rank == 0)
                         printf("loop %d: chunk_size %lu\n", n, CHUNK_SIZE(n));
 
+                if (stat(filename, &stat_buf) < 0)
+                        rprintf(rank, n, "error stating %s: %s\n",
+                                filename, strerror(errno));
+
+                if (stat_buf.st_size != 0)
+                        rprintf(rank, n, "filesize = %lu. "
+                                "Should be zero after truncate\n",
+                                stat_buf.st_size);
+
                 MPI_Barrier(MPI_COMM_WORLD);
 
                 /* Do the race */
@@ -149,10 +161,11 @@ int main (int argc, char *argv[]) {
                 do {
                         ret = write(fd, chunk_buf[rank] + done,
                                     CHUNK_SIZE(n) - done);
-                        if (ret < 0)
+                        if (ret < 0 && errno != EINTR)
                                 rprintf(rank, n, "write() returned %s\n",
                                         strerror(errno));
-                        done += ret;
+                        if (ret > 0)
+                                done += ret;
                 } while (done != CHUNK_SIZE(n));
 
                 MPI_Barrier(MPI_COMM_WORLD);
@@ -222,6 +235,7 @@ int main (int argc, char *argv[]) {
                                 rprintf(0, n, "data check error - exiting\n");
                         }
                 }
+                MPI_Barrier(MPI_COMM_WORLD);
         }
 
         printf("Finished after %d loops\n", n);