X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Ffsx.c;h=71711ab25948be728e008d743f5543dc70c601a7;hb=1bb7d66a574664c95c4933ee720f6a85ff13dddf;hp=49f476d0f09a11c834572e4809187e633e272a24;hpb=cbda7339018323d3469489a0d02bae785297dd2d;p=fs%2Flustre-release.git diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index 49f476d..71711ab 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -1,6 +1,8 @@ /* * Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved. * + * Copyright (c) 2012, Intel Corporation. + * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and @@ -33,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__) @@ -114,23 +115,23 @@ 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; char state[256]; unsigned long testcalls = 0; /* calls to function "test" */ -unsigned long simulatedopcount = 0; /* -b flag */ +long simulatedopcount = 0; /* -b flag */ int closeprob = 0; /* -c flag */ int debug = 0; /* -d flag */ -unsigned long debugstart = 0; /* -D flag */ -unsigned long maxfilelen = 256 * 1024; /* -l flag */ +long debugstart = 0; /* -D flag */ +long maxfilelen = 256 * 1024; /* -l flag */ int sizechecks = 1; /* -n flag disables them */ int maxoplen = 64 * 1024; /* -o flag */ int quiet = 0; /* -q flag */ -unsigned long progressinterval = 0; /* -p flag */ +long progressinterval = 0; /* -p flag */ int readbdy = 1; /* -r flag */ int style = 0; /* -s flag */ int truncbdy = 1; /* -t flag */ @@ -142,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; @@ -497,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); @@ -616,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; @@ -755,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; @@ -995,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); @@ -1116,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); } @@ -1174,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': @@ -1272,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; @@ -1295,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(); @@ -1355,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();