Whamcloud - gitweb
LU-7129 tests: fsx with directio 57/16357/6
authorParinay Kondekar <parinay.kondekar@seagate.com>
Thu, 6 Oct 2016 17:00:35 +0000 (22:30 +0530)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 22 Jul 2017 02:54:52 +0000 (02:54 +0000)
This change adds O_DIRECT support to the existing fsx in lustre/tests.
It also add sanityn test_16 to excercise this option to fsx.

Upstream Xfstest-commit cad234da750aceb563992d95a0b14379740aedc6

Test-Parameters: trivial testlist=sanityn
Signed-off-by: Vitaly Fertman <vitaly.fertman@seagate.com>
Signed-off-by: Parinay Kondekar <parinay.kondekar@seagate.com>
Change-Id: Ibd6a8dfeff8afaf08eeb3f2f8bddd7cdb688e8cf
Seagate-bug-id: MRP-852
Reviewed-by: Vladimir Saveliev <vladimir.saveliev@seagate.com>
Reviewed-by: Elena V. Gryaznova <elena.gryaznova@seagate.com>
Tested-by: Elena V. Gryaznova <elena.gryaznova@seagate.com>
Reviewed-on: https://review.whamcloud.com/16357
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/fsx.c
lustre/tests/sanityn.sh

index 3139866..aa8aaee 100644 (file)
@@ -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 $
  */
  *     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 <sys/types.h>
 #include <sys/stat.h>
 #if defined(_UWIN) || defined(__linux__)
 #include <sys/types.h>
 #include <sys/stat.h>
 #if defined(_UWIN) || defined(__linux__)
@@ -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    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    fsxgoodfd = 0;
+int    o_direct;                       /* -Z */
 FILE * fsxlogf = NULL;
 int badoff = -1;
 
 FILE * fsxlogf = NULL;
 int badoff = -1;
 
-
 void
 vwarnc(code, fmt, ap)
        int code;
 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];
        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);
                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;
        int fd = tf->fd;
 
        offset -= offset % readbdy;
+       if (o_direct)
+               size -= size % readbdy;
        gettimeofday(&t, NULL);
        if (size == 0) {
        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;
                        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;
        int fd = tf->fd;
 
        offset -= offset % writebdy;
+       if (o_direct)
+               size -= size % writebdy;
        gettimeofday(&t, NULL);
        if (size == 0) {
        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;
                        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);
        }
                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);
        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"
 "      -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);
 }
 "      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,
        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':
               != EOF)
                switch (ch) {
                case 'b':
@@ -1297,6 +1301,9 @@ main(int argc, char **argv)
                        if (!quiet)
                                fprintf(stdout, "mapped writes DISABLED\n");
                        break;
                        if (!quiet)
                                fprintf(stdout, "mapped writes DISABLED\n");
                        break;
+               case 'Z':
+                       o_direct = O_DIRECT;
+                       break;
 
                default:
                        usage();
 
                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;
        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();
        if (lite) {     /* zero entire existing file */
                ssize_t written;
                int fd = get_fd();
index f5c7fe5..546932d 100755 (executable)
@@ -378,13 +378,19 @@ test_16() {
        local file2=$DIR2/$tfile
 
        # to allocate grant because it may run out due to test_15.
        local file2=$DIR2/$tfile
 
        # to allocate grant because it may run out due to test_15.
-       lfs setstripe -c -1 $file1
+       $LFS setstripe -c -1 $file1
        dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
        dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
        rm -f $file1
 
        dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
        dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
        rm -f $file1
 
-       lfs setstripe -c -1 $file1 # b=10919
-       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2
+       $LFS setstripe -c -1 $file1 # b=10919
+       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 \
+               || error "fsx failed"
+       rm -f $file1
+
+       # O_DIRECT reads and writes must be aligned to the device block size.
+       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r 4096 \
+               -w 4096 $file1 $file2 || error "fsx with O_DIRECT failed."
 }
 run_test 16 "$FSXNUM iterations of dual-mount fsx"
 
 }
 run_test 16 "$FSXNUM iterations of dual-mount fsx"