All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH] xfs_io: fix random pread/pwrite to honor offset
Date: Wed, 09 Apr 2014 14:15:26 -0500	[thread overview]
Message-ID: <53459C4E.9030902@sandeen.net> (raw)

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@redhat.com>
---

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;

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2014-04-09 19:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 19:15 Eric Sandeen [this message]
2014-04-09 20:48 ` [PATCH] xfs_io: fix random pread/pwrite to honor offset Mark Tinguely
2014-04-09 20:55   ` Eric Sandeen
2014-04-11  4:48     ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53459C4E.9030902@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.