No need to use specific flag for io_u fill length
[fio.git] / verify.c
index a1479d12110beaf0ba2bb8840e54c166b98e096c..42ea462f0cf656d18a47e404e8d13a13a8dbd0ab 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -10,6 +10,7 @@
 #include "fio.h"
 #include "verify.h"
 #include "smalloc.h"
+#include "lib/rand.h"
 
 #include "crc/md5.h"
 #include "crc/crc64.h"
 #include "crc/sha512.h"
 #include "crc/sha1.h"
 
-static void fill_random_bytes(struct thread_data *td, void *p, unsigned int len)
-{
-       unsigned int todo;
-       int r;
-
-       while (len) {
-               r = os_random_long(&td->verify_state);
-
-               /*
-                * lrand48_r seems to be broken and only fill the bottom
-                * 32-bits, even on 64-bit archs with 64-bit longs
-                */
-               todo = sizeof(r);
-               if (todo > len)
-                       todo = len;
-
-               memcpy(p, &r, todo);
-
-               len -= todo;
-               p += todo;
-       }
-}
-
-static void fill_pattern(struct thread_data *td, void *p, unsigned int len)
+void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u)
 {
        switch (td->o.verify_pattern_bytes) {
        case 0:
                dprint(FD_VERIFY, "fill random bytes len=%u\n", len);
-               fill_random_bytes(td, p, len);
+               fill_random_buf(p, len);
                break;
        case 1:
+               if (io_u->buf_filled_len >= len) {
+                       dprint(FD_VERIFY, "using already filled verify pattern b=0 len=%u\n", len);
+                       return;
+               }
                dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);
                memset(p, td->o.verify_pattern[0], len);
+               io_u->buf_filled_len = len;
                break;
        default: {
                unsigned int i = 0, size = 0;
                unsigned char *b = p;
 
+               if (io_u->buf_filled_len >= len) {
+                       dprint(FD_VERIFY, "using already filled verify pattern b=%d len=%u\n",
+                                       td->o.verify_pattern_bytes, len);
+                       return;
+               }
                dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n",
                                        td->o.verify_pattern_bytes, len);
 
@@ -69,6 +57,7 @@ static void fill_pattern(struct thread_data *td, void *p, unsigned int len)
                        memcpy(b+i, td->o.verify_pattern, size);
                        i += size;
                }
+               io_u->buf_filled_len = len;
                break;
                }
        }
@@ -503,10 +492,9 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u)
                        .hdr_num        = hdr_num,
                };
 
-               if (ret && td->o.verify_fatal) {
-                       td->terminate = 1;
+               if (ret && td->o.verify_fatal)
                        break;
-               }
+
                hdr_size = __hdr_size(td->o.verify);
                if (td->o.verify_offset)
                        memswp(p, p + td->o.verify_offset, hdr_size);
@@ -582,6 +570,9 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u)
                }
        }
 
+       if (ret && td->o.verify_fatal)
+               td->terminate = 1;
+
        return ret;
 }
 
@@ -695,7 +686,7 @@ void populate_verify_io_u(struct thread_data *td, struct io_u *io_u)
        if (td->o.verify == VERIFY_NULL)
                return;
 
-       fill_pattern(td, p, io_u->buflen);
+       fill_pattern(td, p, io_u->buflen, io_u);
 
        hdr_inc = io_u->buflen;
        if (td->o.verify_interval)
@@ -879,7 +870,8 @@ static void *verify_async_thread(void *data)
 
        if (ret) {
                td_verror(td, ret, "async_verify");
-               td->terminate = 1;
+               if (td->o.verify_fatal)
+                       td->terminate = 1;
        }
 
 done: