#include "fio.h"
#include "verify.h"
#include "smalloc.h"
+#include "trim.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);
memcpy(b+i, td->o.verify_pattern, size);
i += size;
}
+ io_u->buf_filled_len = len;
break;
}
}
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("trims: verify failed at file %s offset %llu, length %lu\n",
+ io_u->file->file_name, io_u->offset, io_u->buflen);
+ return ret;
+}
+
int verify_io_u(struct thread_data *td, struct io_u *io_u)
{
struct verify_header *hdr;
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)
.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);
}
}
+done:
+ if (ret && td->o.verify_fatal)
+ td->terminate = 1;
+
return ret;
}
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)
ipo = rb_entry(n, struct io_piece, rb_node);
rb_erase(n, &td->io_hist_tree);
- td->io_hist_len--;
} 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);
}
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);
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;
if (ret) {
td_verror(td, ret, "async_verify");
- td->terminate = 1;
+ if (td->o.verify_fatal)
+ td->terminate = 1;
}
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",
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;