Whamcloud - gitweb
land b_md onto HEAD:
[fs/lustre-release.git] / lustre / tests / fsx.c
index e7c1495..717b8d4 100644 (file)
@@ -41,6 +41,7 @@
 # include <limits.h>
 # include <time.h>
 # include <strings.h>
+# include <sys/time.h>
 #endif
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -64,6 +65,7 @@
 
 struct log_entry {
        int     operation;
+       struct timeval tv;
        int     args[3];
 };
 
@@ -92,6 +94,8 @@ char  *original_buf;                  /* a pointer to the original data */
 char   *good_buf;                      /* a pointer to the correct data */
 char   *temp_buf;                      /* a pointer to the current data */
 char   *fname;                         /* name of our test file */
+char   logfile[1024];                  /* name of our log file */
+char   goodfile[1024];                 /* name of our test file */
 int    fd;                             /* fd for our test file */
 
 off_t          file_size = 0;
@@ -171,11 +175,12 @@ prterr(char *prefix)
 
 
 void
-log4(int operation, int arg0, int arg1, int arg2)
+log4(int operation, int arg0, int arg1, int arg2, struct timeval *tv)
 {
        struct log_entry *le;
 
        le = &oplog[logptr];
+       le->tv = *tv;
        le->operation = operation;
        if (closeopen)
                le->operation = ~ le->operation;
@@ -207,8 +212,9 @@ logdump(void)
                int opnum;
 
                opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
-               prt("%d(%d mod 256): ", opnum, opnum%256);
                lp = &oplog[i];
+               prt("%d(%d mod 256): %lu.%lu ", opnum, opnum%256,
+                   lp->tv.tv_sec, lp->tv.tv_usec);
                if ((closeopen = lp->operation < 0))
                        lp->operation = ~ lp->operation;
 
@@ -325,8 +331,8 @@ report_failure(int status)
                if (good_buf) {
                        save_buffer(good_buf, file_size, fsxgoodfd);
                        prt("Correct content saved for comparison\n");
-                       prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
-                           fname, fname);
+                       prt("(maybe hexdump \"%s\" vs \"%s\")\n",
+                           fname, goodfile);
                }
                close(fsxgoodfd);
        }
@@ -422,24 +428,26 @@ check_trunc_hack(void)
 void
 doread(unsigned offset, unsigned size)
 {
+       struct timeval t;
        off_t ret;
        unsigned iret;
 
        offset -= offset % readbdy;
+       gettimeofday(&t, NULL);
        if (size == 0) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping zero size read\n");
-               log4(OP_SKIPPED, OP_READ, offset, size);
+               log4(OP_SKIPPED, OP_READ, offset, size, &t);
                return;
        }
        if (size + offset > file_size) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping seek/read past end of file\n");
-               log4(OP_SKIPPED, OP_READ, offset, size);
+               log4(OP_SKIPPED, OP_READ, offset, size, &t);
                return;
        }
 
-       log4(OP_READ, offset, size, 0);
+       log4(OP_READ, offset, size, 0, &t);
 
        if (testcalls <= simulatedopcount)
                return;
@@ -450,8 +458,9 @@ doread(unsigned offset, unsigned size)
                        (monitorstart == -1 ||
                         (offset + size > monitorstart &&
                          (monitorend == -1 || offset <= monitorend))))))
-               prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
-                   offset, offset + size - 1, size);
+               prt("%lu %lu.%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n",
+                   testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
+                   size);
        ret = lseek(fd, (off_t)offset, SEEK_SET);
        if (ret == (off_t)-1) {
                prterr("doread: lseek");
@@ -473,25 +482,27 @@ doread(unsigned offset, unsigned size)
 void
 domapread(unsigned offset, unsigned size)
 {
+       struct timeval t;
        unsigned pg_offset;
        unsigned map_size;
        char    *p;
 
        offset -= offset % readbdy;
+       gettimeofday(&t, NULL);
        if (size == 0) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping zero size read\n");
-               log4(OP_SKIPPED, OP_MAPREAD, offset, size);
+               log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
                return;
        }
        if (size + offset > file_size) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping seek/read past end of file\n");
-               log4(OP_SKIPPED, OP_MAPREAD, offset, size);
+               log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t);
                return;
        }
 
-       log4(OP_MAPREAD, offset, size, 0);
+       log4(OP_MAPREAD, offset, size, 0, &t);
 
        if (testcalls <= simulatedopcount)
                return;
@@ -502,14 +513,14 @@ domapread(unsigned offset, unsigned size)
                        (monitorstart == -1 ||
                         (offset + size > monitorstart &&
                          (monitorend == -1 || offset <= monitorend))))))
-               prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
-                   offset, offset + size - 1, size);
+               prt("%lu %lu.%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n",
+                   testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
+                   size);
 
        pg_offset = offset & page_mask;
        map_size  = pg_offset + size;
 
-       if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE |
-MAP_SHARED, fd,
+       if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_FILE | MAP_SHARED, fd,
                              (off_t)(offset - pg_offset))) == (char *)-1) {
                prterr("domapread: mmap");
                report_failure(190);
@@ -539,18 +550,20 @@ gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
 void
 dowrite(unsigned offset, unsigned size)
 {
+       struct timeval t;
        off_t ret;
        unsigned iret;
 
        offset -= offset % writebdy;
+       gettimeofday(&t, NULL);
        if (size == 0) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping zero size write\n");
-               log4(OP_SKIPPED, OP_WRITE, offset, size);
+               log4(OP_SKIPPED, OP_WRITE, offset, size, &t);
                return;
        }
 
-       log4(OP_WRITE, offset, size, file_size);
+       log4(OP_WRITE, offset, size, file_size, &t);
 
        gendata(original_buf, good_buf, offset, size);
        if (file_size < offset + size) {
@@ -572,8 +585,9 @@ dowrite(unsigned offset, unsigned size)
                        (monitorstart == -1 ||
                         (offset + size > monitorstart &&
                          (monitorend == -1 || offset <= monitorend))))))
-               prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
-                   offset, offset + size - 1, size);
+               prt("%lu %lu.%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n",
+                   testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
+                   size);
        ret = lseek(fd, (off_t)offset, SEEK_SET);
        if (ret == (off_t)-1) {
                prterr("dowrite: lseek");
@@ -594,21 +608,23 @@ dowrite(unsigned offset, unsigned size)
 void
 domapwrite(unsigned offset, unsigned size)
 {
+       struct timeval t;
        unsigned pg_offset;
        unsigned map_size;
        off_t    cur_filesize;
        char    *p;
 
        offset -= offset % writebdy;
+       gettimeofday(&t, NULL);
        if (size == 0) {
                if (!quiet && testcalls > simulatedopcount)
                        prt("skipping zero size write\n");
-               log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
+               log4(OP_SKIPPED, OP_MAPWRITE, offset, size, &t);
                return;
        }
        cur_filesize = file_size;
 
-       log4(OP_MAPWRITE, offset, size, 0);
+       log4(OP_MAPWRITE, offset, size, 0, &t);
 
        gendata(original_buf, good_buf, offset, size);
        if (file_size < offset + size) {
@@ -630,8 +646,9 @@ domapwrite(unsigned offset, unsigned size)
                        (monitorstart == -1 ||
                         (offset + size > monitorstart &&
                          (monitorend == -1 || offset <= monitorend))))))
-               prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
-                   offset, offset + size - 1, size);
+               prt("%lu %lu.%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n",
+                   testcalls, t.tv_sec, t.tv_usec, offset, offset + size - 1,
+                   size);
 
        if (file_size > cur_filesize) {
                if (ftruncate(fd, file_size) == -1) {
@@ -663,16 +680,18 @@ domapwrite(unsigned offset, unsigned size)
 void
 dotruncate(unsigned size)
 {
+       struct timeval t;
        int oldsize = file_size;
 
        size -= size % truncbdy;
+       gettimeofday(&t, NULL);
        if (size > biggest) {
                biggest = size;
                if (!quiet && testcalls > simulatedopcount)
                        prt("truncating to largest ever: 0x%x\n", size);
        }
 
-       log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
+       log4(OP_TRUNCATE, size, (unsigned)file_size, 0, &t);
 
        if (size > file_size)
                memset(good_buf + file_size, '\0', size - file_size);
@@ -684,8 +703,8 @@ dotruncate(unsigned size)
        if ((progressinterval && testcalls % progressinterval == 0) ||
            (debug && (monitorstart == -1 || monitorend == -1 ||
                       size <= monitorend)))
-               prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize,
-size);
+               prt("%lu %lu.%lu trunc\tfrom 0x%x to 0x%x\n",
+                   testcalls, t.tv_sec, t.tv_usec, oldsize, size);
        if (ftruncate(fd, (off_t)size) == -1) {
                prt("ftruncate1: %x\n", size);
                prterr("dotruncate: ftruncate");
@@ -723,11 +742,16 @@ writefileimage()
 void
 docloseopen(void)
 {
+       struct timeval t;
+
        if (testcalls <= simulatedopcount)
                return;
 
+       log4(OP_CLOSEOPEN, file_size, (unsigned)file_size, 0, &t);
+
+       gettimeofday(&t, NULL);
        if (debug)
-               prt("%lu close/open\n", testcalls);
+               prt("%lu %lu.%lu close/open\n", testcalls, t.tv_sec, t.tv_usec);
        if (close(fd)) {
                prterr("docloseopen: close");
                report_failure(180);
@@ -892,13 +916,19 @@ getnum(char *s, char **e)
 }
 
 
+static const char *basename(const char *path)
+{
+       char *c = strrchr(path, '/');
+
+       return c ? c++ : path;
+}
+
 int
 main(int argc, char **argv)
 {
        int     i, style, ch;
        char    *endp;
-       char goodfile[1024];
-       char logfile[1024];
+       int  dirpath = 0;
 
        goodfile[0] = 0;
        logfile[0] = 0;
@@ -1007,6 +1037,7 @@ main(int argc, char **argv)
                        strcat(goodfile, "/");
                        strncpy(logfile, optarg, sizeof(logfile));
                        strcat(logfile, "/");
+                       dirpath = 1;
                        break;
                 case 'R':
                         mapped_reads = 0;
@@ -1054,14 +1085,14 @@ main(int argc, char **argv)
                prterr(fname);
                exit(91);
        }
-       strncat(goodfile, fname, 256);
+       strncat(goodfile, dirpath ? basename(fname) : fname, 256);
        strcat (goodfile, ".fsxgood");
        fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
        if (fsxgoodfd < 0) {
                prterr(goodfile);
                exit(92);
        }
-       strncat(logfile, fname, 256);
+       strncat(logfile, dirpath ? basename(fname) : fname, 256);
        strcat (logfile, ".fsxlog");
        fsxlogf = fopen(logfile, "w");
        if (fsxlogf == NULL) {