+static int check_get_trim(struct thread_data *td, struct io_u *io_u)
+{
+ if (!(td->flags & TD_F_TRIM_BACKLOG))
+ return 0;
+
+ if (td->trim_entries) {
+ int get_trim = 0;
+
+ if (td->trim_batch) {
+ td->trim_batch--;
+ get_trim = 1;
+ } else if (!(td->io_hist_len % td->o.trim_backlog) &&
+ td->last_ddir != DDIR_READ) {
+ td->trim_batch = td->o.trim_batch;
+ if (!td->trim_batch)
+ td->trim_batch = td->o.trim_backlog;
+ get_trim = 1;
+ }
+
+ if (get_trim && !get_next_trim(td, io_u))
+ return 1;
+ }
+
+ return 0;
+}
+
+static int check_get_verify(struct thread_data *td, struct io_u *io_u)
+{
+ if (!(td->flags & TD_F_VER_BACKLOG))
+ return 0;
+
+ if (td->io_hist_len) {
+ int get_verify = 0;
+
+ if (td->verify_batch)
+ get_verify = 1;
+ else if (!(td->io_hist_len % td->o.verify_backlog) &&
+ td->last_ddir != DDIR_READ) {
+ td->verify_batch = td->o.verify_batch;
+ if (!td->verify_batch)
+ td->verify_batch = td->o.verify_backlog;
+ get_verify = 1;
+ }
+
+ if (get_verify && !get_next_verify(td, io_u)) {
+ td->verify_batch--;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Fill offset and start time into the buffer content, to prevent too
+ * easy compressible data for simple de-dupe attempts. Do this for every
+ * 512b block in the range, since that should be the smallest block size
+ * we can expect from a device.
+ */
+static void small_content_scramble(struct io_u *io_u)
+{
+ unsigned int i, nr_blocks = io_u->buflen / 512;
+ uint64_t boffset;
+ unsigned int offset;
+ void *p, *end;
+
+ if (!nr_blocks)
+ return;
+
+ p = io_u->xfer_buf;
+ boffset = io_u->offset;
+ io_u->buf_filled_len = 0;
+
+ for (i = 0; i < nr_blocks; i++) {
+ /*
+ * Fill the byte offset into a "random" start offset of
+ * the buffer, given by the product of the usec time
+ * and the actual offset.
+ */
+ offset = (io_u->start_time.tv_usec ^ boffset) & 511;
+ offset &= ~(sizeof(uint64_t) - 1);
+ if (offset >= 512 - sizeof(uint64_t))
+ offset -= sizeof(uint64_t);
+ memcpy(p + offset, &boffset, sizeof(boffset));
+
+ end = p + 512 - sizeof(io_u->start_time);
+ memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
+ p += 512;
+ boffset += 512;
+ }
+}
+