xfs
[Top] [All Lists]

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

To: Eric Sandeen <sandeen@xxxxxxxxxxx>
Subject: Re: [PATCH] xfs_io: fix random pread/pwrite to honor offset
From: Mark Tinguely <tinguely@xxxxxxx>
Date: Wed, 09 Apr 2014 15:48:09 -0500
Cc: xfs-oss <xfs@xxxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <53459C4E.9030902@xxxxxxxxxxx>
References: <53459C4E.9030902@xxxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:9.0) Gecko/20120122 Thunderbird/9.0
On 04/09/14 14:15, Eric Sandeen wrote:
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(

offset can be the end of file offset. Do we care that the read (/write)
could start or end past the end of file?


        *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;

Looks like this was introduced in:
commit 8fb2237e65555ff540e8b6108ffccfffefe239ac
Author: Nathan Scott <nathans@xxxxxxx>
Date:   Fri Nov 11 14:25:18 2005 +0000

Provide further debugging options and tweaks for analysing the read/write paths.
Merge of master-melb:xfs-cmds:24372a by kenmcd.

 ---

If it was broken for 8.5 years, I think it could be removed.

--Mark.

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