Mutex fixes
[fio.git] / verify.c
index fc207cf635bc731fbdbb788d4f791bb9bba4124b..eb8eddc78906f4b0dcaa13a9899495e5a8670dca 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -36,41 +36,27 @@ void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u
                if (use_seed)
                        __fill_random_buf(p, len, seed);
                else
-                       io_u->rand_seed = fill_random_buf(p, len);
+                       io_u->rand_seed = fill_random_buf(&td->buf_state, p, len);
                break;
        case 1:
-               /*
-                * See below write barrier comment
-                */
-#if 0
-               read_barrier();
                if (io_u->buf_filled_len >= len) {
                        dprint(FD_VERIFY, "using already filled verify pattern b=0 len=%u\n", len);
                        return;
                }
-#endif
                dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);
                memset(p, td->o.verify_pattern[0], len);
-               /*
-                * We need to ensure that the pattern stores are seen before
-                * the fill length store, or we could observe headers that
-                * aren't valid to the extent notified by the fill length
-                */
-               write_barrier();
                io_u->buf_filled_len = len;
                break;
        default: {
                unsigned int i = 0, size = 0;
                unsigned char *b = p;
 
-#if 0
-               read_barrier();
                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;
                }
-#endif
+
                dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n",
                                        td->o.verify_pattern_bytes, len);
 
@@ -81,7 +67,6 @@ void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u
                        memcpy(b+i, td->o.verify_pattern, size);
                        i += size;
                }
-               write_barrier();
                io_u->buf_filled_len = len;
                break;
                }
@@ -269,6 +254,9 @@ static void dump_verify_buffers(struct verify_header *hdr, struct vcont *vc)
        struct io_u dummy;
        void *buf;
 
+       if (!td->o.verify_dump)
+               return;
+
        /*
         * Dump the contents we just read off disk
         */
@@ -334,14 +322,27 @@ static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc)
        struct io_u *io_u = vc->io_u;
        char *buf, *pattern;
        unsigned int header_size = __hdr_size(td->o.verify);
-       unsigned int len, mod, i;
+       unsigned int len, mod, i, size, pattern_size;
 
        pattern = td->o.verify_pattern;
+       pattern_size = td->o.verify_pattern_bytes;
+       if (pattern_size <= 1)
+               pattern_size = MAX_PATTERN_SIZE;
        buf = (void *) hdr + header_size;
        len = get_hdr_inc(td, io_u) - header_size;
-       mod = header_size % td->o.verify_pattern_bytes;
+       mod = header_size % pattern_size;
+
+       for (i = 0; i < len; i += size) {
+               size = pattern_size - mod;
+               if (size > (len - i))
+                       size = len - i;
+               if (memcmp(buf + i, pattern + mod, size))
+                       // Let the slow compare find the first mismatch byte.
+                       break;
+               mod = 0;
+       }
 
-       for (i = 0; i < len; i++) {
+       for (; i < len; i++) {
                if (buf[i] != pattern[mod]) {
                        unsigned int bits;
 
@@ -599,10 +600,8 @@ int verify_io_u_async(struct thread_data *td, struct io_u *io_u)
        if (io_u->file)
                put_file_log(td, io_u->file);
 
-       io_u->file = NULL;
-
        pthread_mutex_lock(&td->io_u_lock);
-       
+
        if (io_u->flags & IO_U_F_IN_CUR_DEPTH) {
                td->cur_depth--;
                io_u->flags &= ~IO_U_F_IN_CUR_DEPTH;
@@ -1032,7 +1031,7 @@ static void *verify_async_thread(void *data)
                        put_io_u(td, io_u);
                        if (!ret)
                                continue;
-                       if (td->o.continue_on_error &&
+                       if (td->o.continue_on_error & ERROR_TYPE_VERIFY &&
                            td_non_fatal_error(ret)) {
                                update_error_count(td, ret);
                                td_clear_error(td);