io_u: tweak small content buffer scramble
authorJens Axboe <axboe@kernel.dk>
Thu, 30 Nov 2017 13:50:36 +0000 (06:50 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 30 Nov 2017 13:50:36 +0000 (06:50 -0700)
We currently generate a 'random' offset in a 512b chunk to fill in
the offset. Since we don't want the later time scramble to
overwrite it, we check and adjust for that. Instead just ensure that
we generate a random offset in the first half of the 512b chunk,
then we know we never overlap.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_u.c

diff --git a/io_u.c b/io_u.c
index 8087bd6a119217e9df7954bfec52a4afaea1dcd7..c25854273a68d279a9265ec1780cc4fc260da4d2 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1687,15 +1687,15 @@ static void small_content_scramble(struct io_u *io_u)
        for (i = 0; i < nr_blocks; i++) {
                /*
                 * Fill the byte offset into a "random" start offset of
        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.
+                * the first half of the buffer.
                 */
                 */
-               offset = (io_u->start_time.tv_nsec ^ boffset) & 511;
-               offset &= ~(sizeof(uint64_t) - 1);
-               if (offset >= 512 - sizeof(uint64_t))
-                       offset -= sizeof(uint64_t);
+               offset = (io_u->start_time.tv_nsec ^ boffset) & 255;
+               offset &= ~(sizeof(boffset) - 1);
                memcpy(p + offset, &boffset, sizeof(boffset));
 
                memcpy(p + offset, &boffset, sizeof(boffset));
 
+               /*
+                * Fill the start time into the end of the buffer
+                */
                end = p + 512 - sizeof(io_u->start_time);
                memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
                p += 512;
                end = p + 512 - sizeof(io_u->start_time);
                memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
                p += 512;