X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Ffsx.c;h=49f476d0f09a11c834572e4809187e633e272a24;hb=b66f20c77d7501331d301ea61b62d0280bab677e;hp=ead1c8566efbedf9dc3df248e55f54dd96dadbfe;hpb=2dc9c16e770415d56839e1996015fec5fab93f29;p=fs%2Flustre-release.git diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index ead1c85..49f476d 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -60,16 +60,36 @@ #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */ /* + * Each test run will work with one or more separate file descriptors for the + * same file. This allows testing cache coherency across multiple mountpoints + * of the same network filesystem on a single client. + */ +struct test_file { + char *path; + int fd; +} *test_files = NULL; + +int num_test_files; +enum fd_iteration_policy { + FD_SINGLE, + FD_ROTATE, + FD_RANDOM, +}; +int fd_policy = FD_RANDOM; +int fd_last; + +/* * A log entry is an operation and a bunch of arguments. */ struct log_entry { - int operation; - struct timeval tv; - int args[3]; + int operation; + int args[3]; + struct timeval tv; + const struct test_file *tf; }; -#define LOGSIZE 1000 +#define LOGSIZE 100000 struct log_entry oplog[LOGSIZE]; /* the log */ int logptr = 0; /* current position in log */ @@ -178,22 +198,42 @@ prterr(char *prefix) void -log4(int operation, int arg0, int arg1, int arg2, struct timeval *tv) +log4(int operation, int arg0, int arg1, int arg2, struct timeval *tv, + const struct test_file *tf) { struct log_entry *le; le = &oplog[logptr]; - le->tv = *tv; le->operation = operation; le->args[0] = arg0; le->args[1] = arg1; le->args[2] = arg2; + le->tv = *tv; + le->tf = tf; logptr++; logcount++; if (logptr >= LOGSIZE) logptr = 0; } +const char * +fill_tf_buf(const struct test_file *tf) +{ + static int max_tf_len; + static char tf_buf[32]; + + if (fd_policy == FD_SINGLE) + return ""; + + if (max_tf_len == 0) + max_tf_len = snprintf(tf_buf, sizeof(tf_buf) - 1, + "%u", num_test_files - 1); + + sprintf(tf_buf, "[%0*lu]", max_tf_len, + (unsigned long)(tf - test_files)); + + return tf_buf; +} void logdump(void) @@ -214,7 +254,7 @@ logdump(void) opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE; lp = &oplog[i]; - prt("%d: %lu.%06lu ", opnum, + prt("%d%s: %lu.%06lu ", opnum, fill_tf_buf(lp->tf), lp->tv.tv_sec, lp->tv.tv_usec); switch (lp->operation) { @@ -299,7 +339,7 @@ save_buffer(char *buffer, off_t bufferlength, int fd) prterr("save_buffer: lseek eof"); else if (bufferlength > size_by_seek) { warn("save_buffer: .fsxgood file too short... will" - "save 0x%llx bytes instead of 0x%llx\n", + "save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek, (unsigned long long)bufferlength); bufferlength = size_by_seek; @@ -363,7 +403,7 @@ check_buffers(unsigned offset, unsigned size) if (c != t) { if (n == 0) { bad = short_at(&temp_buf[i]); - prt("0x%5x\t0x%04x\t0x%04x", offset, + prt("%#07x\t%#06x\t%#06x", offset, short_at(&good_buf[offset]), bad); op = temp_buf[offset & 1 ? i+1 : i]; } @@ -375,7 +415,7 @@ check_buffers(unsigned offset, unsigned size) size--; } if (n) { - prt("\t0x%5x\n", n); + prt("\t%#7x\n", n); if (bad) prt("operation# (mod 256) for the bad data" "may be %u\n", ((unsigned)op & 0xff)); @@ -388,21 +428,7 @@ check_buffers(unsigned offset, unsigned size) } } -struct test_file { - char *path; - int fd; -} *test_files = NULL; - -int num_test_files = 0; -enum fd_iteration_policy { - FD_SINGLE, - FD_ROTATE, - FD_RANDOM, -}; -int fd_policy = FD_RANDOM; -int fd_last = 0; - -struct test_file * +struct test_file * get_tf(void) { unsigned index = 0; @@ -438,21 +464,21 @@ assign_fd_policy(char *policy) } } -int +int get_fd(void) { struct test_file *tf = get_tf(); return tf->fd; } -static const char *basename(const char *path) +static const char *my_basename(const char *path) { char *c = strrchr(path, '/'); return c ? c++ : path; } -void +void open_test_files(char **argv, int argc) { struct test_file *tf; @@ -471,7 +497,7 @@ open_test_files(char **argv, int argc) for (i = 0, tf = test_files; i < num_test_files; i++, tf++) { tf->path = argv[i]; - tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC), + tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC), 0666); if (tf->fd < 0) { prterr(tf->path); @@ -529,65 +555,33 @@ check_trunc_hack(void) struct stat statbuf; int fd = get_fd(); - ftruncate(fd, (off_t)0); - ftruncate(fd, (off_t)100000); - fstat(fd, &statbuf); + /* should not ignore ftruncate(2)'s return value */ + if (ftruncate(fd, (off_t)0) < 0) { + prterr("trunc_hack: ftruncate(0)"); + exit(1); + } + if (ftruncate(fd, (off_t)100000) < 0) { + prterr("trunc_hack: ftruncate(100000)"); + exit(1); + } + if (fstat(fd, &statbuf)) { + prterr("trunc_hack: fstat"); + statbuf.st_size = -1; + } if (statbuf.st_size != (off_t)100000) { prt("no extend on truncate! not posix!\n"); exit(130); } - ftruncate(fd, 0); -} - -static char *tf_buf = NULL; -static int max_tf_len = 0; - -void -alloc_tf_buf(void) -{ - char dummy = '\0'; - int highest = num_test_files - 1; - int len; - - len = snprintf(&dummy, 0, "%u ", highest); - if (len < 1) { - prterr("finding max tf_buf"); - exit(1); - } - len++; - tf_buf = malloc(len); - if (tf_buf == NULL) { - prterr("allocating tf_buf"); - exit(1); - } - max_tf_len = snprintf(tf_buf, len, "%u ", highest); - if (max_tf_len < 1) { - prterr("fiding max_tv_len\n"); - exit(1); - } - if (max_tf_len != len - 1) { - warn("snprintf() gave %d instead of %d?\n", - max_tf_len, len - 1); - exit(1); - } -} - -char * -fill_tf_buf(struct test_file *tf) -{ - if (tf_buf == NULL) - alloc_tf_buf(); - - sprintf(tf_buf,"%lu ", (unsigned long)(tf - test_files)); - return tf_buf; + if (ftruncate(fd, 0) < 0) { + prterr("trunc_hack: ftruncate(0) (2nd call)"); + exit(1); + } } void -output_line(struct test_file *tf, int op, unsigned offset, +output_line(struct test_file *tf, int op, unsigned offset, unsigned size, struct timeval *tv) { - char *tf_num = ""; - char *ops[] = { [OP_READ] = "read", [OP_WRITE] = "write", @@ -596,9 +590,6 @@ output_line(struct test_file *tf, int op, unsigned offset, [OP_MAPWRITE] = "mapwrite", }; - if (fd_policy != FD_SINGLE) - tf_num = fill_tf_buf(tf); - /* W. */ if (!(!quiet && ((progressinterval && testcalls % progressinterval == 0) || @@ -608,9 +599,9 @@ output_line(struct test_file *tf, int op, unsigned offset, (monitorend == -1 || offset <= monitorend))))))) return; - prt("%06lu %lu.%06lu %*s%-10s %#08x %s %#08x\t(0x%x bytes)\n", - testcalls, tv->tv_sec, tv->tv_usec, max_tf_len, - tf_num, ops[op], + prt("%06lu%s %lu.%06lu %-10s %#08x %s %#08x\t(0x%x bytes)\n", + testcalls, fill_tf_buf(tf), tv->tv_sec, tv->tv_usec, + ops[op], offset, op == OP_TRUNCATE ? " to " : "thru", offset + size - 1, size); } @@ -629,17 +620,17 @@ doread(unsigned offset, unsigned size) if (size == 0) { if (!quiet && testcalls > simulatedopcount) prt("skipping zero size read\n"); - log4(OP_SKIPPED, OP_READ, offset, size, &t); + log4(OP_SKIPPED, OP_READ, offset, size, &t, tf); 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, &t); + log4(OP_SKIPPED, OP_READ, offset, size, &t, tf); return; } - log4(OP_READ, offset, size, 0, &t); + log4(OP_READ, offset, size, 0, &t, tf); if (testcalls <= simulatedopcount) return; @@ -686,17 +677,17 @@ domapread(unsigned offset, unsigned size) if (size == 0) { if (!quiet && testcalls > simulatedopcount) prt("skipping zero size read\n"); - log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t); + log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t, tf); 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, &t); + log4(OP_SKIPPED, OP_MAPREAD, offset, size, &t, tf); return; } - log4(OP_MAPREAD, offset, size, 0, &t); + log4(OP_MAPREAD, offset, size, 0, &t, tf); if (testcalls <= simulatedopcount) return; @@ -768,11 +759,11 @@ dowrite(unsigned offset, unsigned size) if (size == 0) { if (!quiet && testcalls > simulatedopcount) prt("skipping zero size write\n"); - log4(OP_SKIPPED, OP_WRITE, offset, size, &t); + log4(OP_SKIPPED, OP_WRITE, offset, size, &t, tf); return; } - log4(OP_WRITE, offset, size, file_size, &t); + log4(OP_WRITE, offset, size, file_size, &t, tf); gendata(original_buf, good_buf, offset, size); if (file_size < offset + size) { @@ -830,12 +821,12 @@ domapwrite(unsigned offset, unsigned size) if (size == 0) { if (!quiet && testcalls > simulatedopcount) prt("skipping zero size write\n"); - log4(OP_SKIPPED, OP_MAPWRITE, offset, size, &t); + log4(OP_SKIPPED, OP_MAPWRITE, offset, size, &t, tf); return; } cur_filesize = file_size; - log4(OP_MAPWRITE, offset, size, 0, &t); + log4(OP_MAPWRITE, offset, size, 0, &t, tf); gendata(original_buf, good_buf, offset, size); if (file_size < offset + size) { @@ -930,7 +921,7 @@ dotruncate(unsigned size) prt("truncating to largest ever: 0x%x\n", size); } - log4(OP_TRUNCATE, size, (unsigned)file_size, 0, &t); + log4(OP_TRUNCATE, size, (unsigned)file_size, 0, &t, tf); if (size > file_size) memset(good_buf + file_size, '\0', size - file_size); @@ -969,7 +960,7 @@ writefileimage() prterr("writefileimage: write"); else prt("short write: 0x%lx bytes instead of 0x%llx\n", - (unsigned long)iret, + (unsigned long)iret, (unsigned long long)file_size); report_failure(172); } @@ -991,7 +982,7 @@ docloseopen(void) return; gettimeofday(&t, NULL); - log4(OP_CLOSEOPEN, file_size, (unsigned)file_size, 0, &t); + log4(OP_CLOSEOPEN, file_size, (unsigned)file_size, 0, &t, tf); if (debug) prt("%06lu %lu.%06lu close/open\n", testcalls, t.tv_sec, @@ -1182,7 +1173,7 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ - while ((ch = getopt(argc, argv, + while ((ch = getopt(argc, argv, "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:W")) != EOF) switch (ch) { @@ -1331,14 +1322,14 @@ main(int argc, char **argv) open_test_files(argv, argc); - strncat(goodfile, dirpath ? basename(fname) : fname, 256); + strncat(goodfile, dirpath ? my_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, dirpath ? basename(fname) : fname, 256); + strncat(logfile, dirpath ? my_basename(fname) : fname, 256); strcat (logfile, ".fsxlog"); fsxlogf = fopen(logfile, "w"); if (fsxlogf == NULL) {