X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=verify.c;h=dc107087cefbabc5630a0f2cdcfec8e199743b4f;hp=bb0aba77f96400f66e7729a202773a905c944d2c;hb=03e20d687566753b90383571e5e152c5142bdffd;hpb=32c17adf7f75da1f0957d4691633fea60259910f diff --git a/verify.c b/verify.c index bb0aba77..dc107087 100644 --- a/verify.c +++ b/verify.c @@ -10,6 +10,8 @@ #include "fio.h" #include "verify.h" #include "smalloc.h" +#include "trim.h" +#include "lib/rand.h" #include "crc/md5.h" #include "crc/crc64.h" @@ -21,44 +23,31 @@ #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 +58,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; } } @@ -100,7 +90,7 @@ static void hexdump(void *buffer, int len) */ static inline unsigned int __hdr_size(int verify_type) { - unsigned int len = len; + unsigned int len = 0; switch (verify_type) { case VERIFY_NONE: @@ -481,6 +471,40 @@ int verify_io_u_async(struct thread_data *td, struct io_u *io_u) return 0; } +static int verify_trimmed_io_u(struct thread_data *td, struct io_u *io_u) +{ + static char zero_buf[1024]; + unsigned int this_len, len; + int ret = 0; + void *p; + + if (!td->o.trim_zero) + return 0; + + len = io_u->buflen; + p = io_u->buf; + do { + this_len = sizeof(zero_buf); + if (this_len > len) + this_len = len; + if (memcmp(p, zero_buf, this_len)) { + ret = EILSEQ; + break; + } + len -= this_len; + p += this_len; + } while (len); + + if (!ret) + return 0; + + log_err("trim: verify failed at file %s offset %llu, length %lu" + ", block offset %lu\n", + io_u->file->file_name, io_u->offset, io_u->buflen, + (unsigned long) (p - io_u->buf)); + return ret; +} + int verify_io_u(struct thread_data *td, struct io_u *io_u) { struct verify_header *hdr; @@ -490,6 +514,10 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u) if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ) return 0; + if (io_u->flags & IO_U_F_TRIMMED) { + ret = verify_trimmed_io_u(td, io_u); + goto done; + } hdr_inc = io_u->buflen; if (td->o.verify_interval) @@ -503,19 +531,19 @@ 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); hdr = p; if (hdr->fio_magic != FIO_HDR_MAGIC) { - log_err("Bad verify header %x at %llu\n", - hdr->fio_magic, - io_u->offset + hdr_num * hdr->len); + log_err("verify: bad magic header %x, wanted %x at file %s offset %llu, length %u\n", + hdr->fio_magic, FIO_HDR_MAGIC, + io_u->file->file_name, + io_u->offset + hdr_num * hdr->len, hdr->len); return EILSEQ; } @@ -527,16 +555,19 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u) p + hdr_size, hdr_inc - hdr_size, hdr_size % td->o.verify_pattern_bytes); + + if (ret) { + log_err("pattern: verify failed at file %s offset %llu, length %u\n", + io_u->file->file_name, + io_u->offset + hdr_num * hdr->len, + hdr->len); + } + /* * Also verify the meta data, if applicable */ if (hdr->verify_type == VERIFY_META) ret |= verify_io_u_meta(hdr, td, &vc); - - if (ret) - log_err("fio: verify failed at %llu/%u\n", - io_u->offset + hdr_num * hdr->len, - hdr->len); continue; } @@ -578,6 +609,10 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u) } } +done: + if (ret && td->o.verify_fatal) + td->terminate = 1; + return ret; } @@ -691,7 +726,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) @@ -783,18 +818,25 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u) ipo = rb_entry(n, struct io_piece, rb_node); rb_erase(n, &td->io_hist_tree); - td->io_hist_len--; + assert(ipo->flags & IP_F_ONRB); + ipo->flags &= ~IP_F_ONRB; } else if (!flist_empty(&td->io_hist_list)) { ipo = flist_entry(td->io_hist_list.next, struct io_piece, list); - td->io_hist_len--; flist_del(&ipo->list); + assert(ipo->flags & IP_F_ONLIST); + ipo->flags &= ~IP_F_ONLIST; } if (ipo) { + td->io_hist_len--; + io_u->offset = ipo->offset; io_u->buflen = ipo->len; io_u->file = ipo->file; + if (ipo->flags & IP_F_TRIMMED) + io_u->flags |= IO_U_F_TRIMMED; + if (!fio_file_open(io_u->file)) { int r = td_io_open_file(td, io_u->file); @@ -810,6 +852,8 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u) io_u->ddir = DDIR_READ; io_u->xfer_buf = io_u->buf; io_u->xfer_buflen = io_u->buflen; + + remove_trim_entry(td, ipo); free(ipo); dprint(FD_VERIFY, "get_next_verify: ret io_u %p\n", io_u); return 0; @@ -875,7 +919,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: @@ -890,12 +935,16 @@ done: int verify_async_init(struct thread_data *td) { int i, ret; + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); td->verify_thread_exit = 0; td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async); for (i = 0; i < td->o.verify_async; i++) { - ret = pthread_create(&td->verify_threads[i], NULL, + ret = pthread_create(&td->verify_threads[i], &attr, verify_async_thread, td); if (ret) { log_err("fio: async verify creation failed: %s\n", @@ -911,6 +960,8 @@ int verify_async_init(struct thread_data *td) td->nr_verify_threads++; } + pthread_attr_destroy(&attr); + if (i != td->o.verify_async) { log_err("fio: only %d verify threads started, exiting\n", i); td->verify_thread_exit = 1;