Whamcloud - gitweb
- fix iopentest*.c to produce error messages with filenames
[fs/lustre-release.git] / lustre / tests / iopentest1.c
index 25ad401..107970e 100644 (file)
@@ -1,3 +1,7 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -33,16 +37,24 @@ static char *get_iname(char *fname, const char *mtpt)
         CHECK_IT(iname, "malloc() failed");
 
         fd = open(fname, O_CREAT, 0644);
-        CHECK_IT(fd >= 0 || errno == EISDIR, "open(fname) failed");
+        if (fd < 0 && errno != EISDIR) {
+                fprintf(stderr, "%s:%d: open(%s) failed: %s\n", __FILE__,
+                        __LINE__, fname, strerror(errno));
+                exit(1);
+        }
 
         if (fd >= 0)
                 close(fd);
 
         rc = stat(fname, &buf);
-        CHECK_IT(rc == 0, "stat(fname) failed");
+        if (rc != 0) {
+                fprintf(stderr, "%s:%d: stat(%s) failed: %s\n", __FILE__,
+                        __LINE__, fname, strerror(errno));
+                exit(1);
+        }
 
         rc = snprintf(iname, INAME_LEN,
-                      "%s/__iopen__/%lu", mtpt, buf.st_ino);
+                      "%s/__iopen__/%lu", mtpt, (unsigned long)buf.st_ino);
         CHECK_SNPRINTF(rc, INAME_LEN);
 
         return iname;
@@ -67,16 +79,22 @@ int main(int argc, char *argv[])
         mtpt  = argv[2];
 
         iname = get_iname(fname, mtpt);
-        i=10000;
-        printf("%s:started...\n",argv[0]);
-        do {
+        printf("%s:started...\n", argv[0]);
+        for (i = 0; i < 10000; i++) {
                 rc = stat(fname, &buf);
-                CHECK_IT(rc == 0, "stat(fname) failed");
+                if (rc != 0) {
+                        fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
+                                __FILE__, __LINE__, fname, strerror(errno));
+                        exit(1);
+                }
                
                 rc = stat(iname, &buf);
-                CHECK_IT(rc == 0, "stat(iname) failed");
-                i--;
-        } while (i>=1);
+                if (rc != 0) {
+                        fprintf(stderr, "%s:%d: stat(%s) failed: %s\n",
+                                __FILE__, __LINE__, iname, strerror(errno));
+                        exit(1);
+                }
+        }
 
         return 0;
 }