xfs
[Top] [All Lists]

[PATCH] xfs_io: fix random pread/pwrite to honor offset

To: xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH] xfs_io: fix random pread/pwrite to honor offset
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Wed, 09 Apr 2014 14:15:26 -0500
Delivered-to: xfs@xxxxxxxxxxx
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
xfs_io's pread & pwrite claim to support a random IO mode
where it will do random IOs between offset & offset+len.

However, offset was ignored, and we did the IOs between 0
and len instead.

Clang caught this by pointing out that the calculated/normalized
"offset" variable was never read.

(NB: If the range is larger than RAND_MAX, these functions don't
work, but that's always been true, so I'll leave it for another
day...)

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

I haven't tested this w/ xfstests but I don't see anyone who calls
pread/pwrite with "-R" (and it's not documented in the manpage!)

diff --git a/io/pread.c b/io/pread.c
index a42baed..465c22b 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -246,7 +246,7 @@ read_random(
 
        *total = 0;
        while (count > 0) {
-               off = ((random() % range) / buffersize) * buffersize;
+               off = ((offset + (random() % range)) / buffersize) * buffersize;
                bytes = do_pread(fd, off, buffersize, buffersize);
                if (bytes == 0)
                        break;
diff --git a/io/pwrite.c b/io/pwrite.c
index a2f0a81..f8a0b1e 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -129,7 +129,7 @@ write_random(
 
        *total = 0;
        while (count > 0) {
-               off = ((random() % range) / buffersize) * buffersize;
+               off = ((offset + (random() % range)) / buffersize) * buffersize;
                bytes = do_pwrite(file->fd, off, buffersize, buffersize);
                if (bytes == 0)
                        break;

<Prev in Thread] Current Thread [Next in Thread>