X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Ffsx.c;h=71711ab25948be728e008d743f5543dc70c601a7;hb=7e0cba246a7f2408c8266574a657e4459f691570;hp=3139866798276f7850c50146bae1f88b26baa957;hpb=2b294992edce5af7b79d4300ed3aa1ea6a8db850;p=fs%2Flustre-release.git diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index 3139866..71711ab 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -35,7 +35,6 @@ * Sundry porting patches from Guy Harris 12/2001 * $FreeBSD: src/tools/regression/fsx/fsx.c,v 1.1 2001/12/20 04:15:57 jkh Exp $ */ - #include #include #if defined(_UWIN) || defined(__linux__) @@ -116,8 +115,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 */ +char logfile[PATH_MAX]; /* name of our log file */ +char goodfile[PATH_MAX]; /* name of our test file */ off_t file_size = 0; off_t biggest = 0; @@ -144,12 +143,12 @@ long numops = -1; /* -N flag */ int randomoplen = 1; /* -O flag disables it */ int seed = 1; /* -S flag */ int mapped_writes = 1; /* -W flag disables */ -int mapped_reads = 1; /* -R flag disables it */ +int mapped_reads = 1; /* -R flag disables it */ int fsxgoodfd = 0; +int o_direct; /* -Z */ FILE * fsxlogf = NULL; int badoff = -1; - void vwarnc(code, fmt, ap) int code; @@ -499,8 +498,8 @@ 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), - 0666); + tf->fd = open(tf->path, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)| + o_direct, 0666); if (tf->fd < 0) { prterr(tf->path); exit(91); @@ -618,9 +617,11 @@ doread(unsigned offset, unsigned size) int fd = tf->fd; offset -= offset % readbdy; + if (o_direct) + size -= size % readbdy; gettimeofday(&t, NULL); if (size == 0) { - if (!quiet && testcalls > simulatedopcount) + if (!quiet && testcalls > simulatedopcount && !o_direct) prt("skipping zero size read\n"); log4(OP_SKIPPED, OP_READ, offset, size, &t, tf); return; @@ -757,9 +758,11 @@ dowrite(unsigned offset, unsigned size) int fd = tf->fd; offset -= offset % writebdy; + if (o_direct) + size -= size % writebdy; gettimeofday(&t, NULL); if (size == 0) { - if (!quiet && testcalls > simulatedopcount) + if (!quiet && testcalls > simulatedopcount && !o_direct) prt("skipping zero size write\n"); log4(OP_SKIPPED, OP_WRITE, offset, size, &t, tf); return; @@ -997,7 +1000,7 @@ docloseopen(void) gettimeofday(&t, NULL); prt(" %lu.%06lu close done\n", t.tv_sec, t.tv_usec); } - tf->fd = open(tf->path, O_RDWR, 0); + tf->fd = open(tf->path, O_RDWR|o_direct, 0); if (tf->fd < 0) { prterr("docloseopen: open"); report_failure(181); @@ -1118,10 +1121,11 @@ usage(void) " -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n" " -S seed: for random # generator (default 1) 0 gets timestamp\n" " -W: mapped write operations DISabled\n" -" -R: read() system calls only (mapped reads disabled)\n" -" -I: When multiple paths to the file are given each operation uses" -" a different path. Iterate through them in order with 'rotate'" -" or chose then at 'random'. (defaults to random)\n" +" -R: read() system calls only (mapped reads disabled)\n" +" -Z: O_DIRECT (use -R, -W, -r and -w too)\n" +" -I: When multiple paths to the file are given each operation uses\n" +" a different path. Iterate through them in order with 'rotate'\n" +" or chose then at 'random'. (defaults to random)\n" " fname: this filename is REQUIRED (no default)\n"); exit(90); } @@ -1176,7 +1180,7 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ while ((ch = getopt(argc, argv, - "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:W")) + "b:c:dl:m:no:p:qr:s:t:w:D:I:LN:OP:RS:WZ")) != EOF) switch (ch) { case 'b': @@ -1274,9 +1278,9 @@ main(int argc, char **argv) randomoplen = 0; break; case 'P': - strncpy(goodfile, optarg, sizeof(goodfile)); + strncpy(goodfile, optarg, sizeof(goodfile) - 1); strcat(goodfile, "/"); - strncpy(logfile, optarg, sizeof(logfile)); + strncpy(logfile, optarg, sizeof(logfile) - 1); strcat(logfile, "/"); dirpath = 1; break; @@ -1297,6 +1301,9 @@ main(int argc, char **argv) if (!quiet) fprintf(stdout, "mapped writes DISABLED\n"); break; + case 'Z': + o_direct = O_DIRECT; + break; default: usage(); @@ -1357,10 +1364,36 @@ main(int argc, char **argv) original_buf = (char *) malloc(maxfilelen); for (i = 0; i < maxfilelen; i++) original_buf[i] = random() % 256; - good_buf = (char *) malloc(maxfilelen); - memset(good_buf, '\0', maxfilelen); - temp_buf = (char *) malloc(maxoplen); - memset(temp_buf, '\0', maxoplen); + if (o_direct) { + int ret; + + ret = posix_memalign((void **)&good_buf, writebdy, maxfilelen); + if (ret) { + prt("main: posix_memalign failed: %s\n", strerror(ret)); + exit(96); + } + + ret = posix_memalign((void **)&temp_buf, readbdy, maxoplen); + if (ret) { + prt("main: posix_memalign failed: %s\n", strerror(ret)); + exit(97); + } + } else { + good_buf = malloc(maxfilelen); + if (!good_buf) { + prt("malloc failed.\n"); + exit(98); + } + + temp_buf = malloc(maxoplen); + if (!temp_buf) { + prt("malloc failed.\n"); + exit(99); + } + } + memset(good_buf, 0, maxfilelen); + memset(temp_buf, 0, maxoplen); + if (lite) { /* zero entire existing file */ ssize_t written; int fd = get_fd();