Scramble on a 512b boundary

Instead of just scrambling the full block at the beginning at the
end, make it a bit more clever by:

- Doing it at 512b intervals to ensure full 512b de-dupe attemts, and
- Do it at a "random" offset into that block.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/io_u.c b/io_u.c
index af2d05f..f4c4aa2 100644
--- a/io_u.c
+++ b/io_u.c
@@ -1122,15 +1122,35 @@
 
 /*
  * Fill offset and start time into the buffer content, to prevent too
- * easy compressible data for simple de-dupe attempts.
+ * 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)
 {
-	void *end;
+	unsigned int i, nr_blocks = io_u->buflen / 512;
+	unsigned int offset;
+	void *p, *end;
 
-	*((unsigned long long *) io_u->xfer_buf) = io_u->offset;
-	end = io_u->xfer_buf + io_u->xfer_buflen - sizeof(io_u->start_time);
-	memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
+	if (!nr_blocks)
+		return;
+
+	p = io_u->xfer_buf;
+	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 * io_u->offset) & 511;
+		if (offset >= 512 - sizeof(unsigned long long))
+			offset -= sizeof(unsigned long long);
+		*((unsigned long long *) p + offset) = io_u->offset;
+
+		end = p + 512 - sizeof(io_u->start_time);
+		memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
+		p += 512;
+	}
 }
 
 /*