X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=verify.c;h=268c0603aa7dba88a5698577ff8738abb996350e;hp=ee9160c673c3fa4efab1a48dea8eedbe7f939473;hb=2466096336bd0fbc1a94811aa338926af6baf42f;hpb=b638d82f882bd8c15cc933ee0b8fa684308e7855 diff --git a/verify.c b/verify.c index ee9160c6..268c0603 100644 --- a/verify.c +++ b/verify.c @@ -661,38 +661,63 @@ int verify_io_u_async(struct thread_data *td, struct io_u **io_u_ptr) return 0; } +/* + * Thanks Rusty, for spending the time so I don't have to. + * + * http://rusty.ozlabs.org/?p=560 + */ +static int mem_is_zero(const void *data, size_t length) +{ + const unsigned char *p = data; + size_t len; + + /* Check first 16 bytes manually */ + for (len = 0; len < 16; len++) { + if (!length) + return 1; + if (*p) + return 0; + p++; + length--; + } + + /* Now we know that's zero, memcmp with self. */ + return memcmp(data, p, length) == 0; +} + +static int mem_is_zero_slow(const void *data, size_t length, size_t *offset) +{ + const unsigned char *p = data; + + *offset = 0; + while (length) { + if (*p) + break; + (*offset)++; + length--; + p++; + } + + return !length; +} + 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; + size_t offset; 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) + if (mem_is_zero(io_u->buf, io_u->buflen)) return 0; + mem_is_zero_slow(io_u->buf, io_u->buflen, &offset); + 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; + (unsigned long) offset); + return EILSEQ; } static int verify_header(struct io_u *io_u, struct thread_data *td, @@ -1578,7 +1603,7 @@ int verify_state_hdr(struct verify_state_hdr *hdr, struct thread_io_list *s, hdr->size = le64_to_cpu(hdr->size); hdr->crc = le64_to_cpu(hdr->crc); - if (hdr->version != VSTATE_HDR_VERSION || + if (hdr->version != VSTATE_HDR_VERSION && hdr->version != VSTATE_HDR_VERSION_V1) return 1;