public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: xfs@oss.sgi.com
Subject: [PATCH] xfs_io: Prevent devide by zero from {pread,pwrite}_random
Date: Thu, 25 Feb 2016 19:20:53 +0400	[thread overview]
Message-ID: <8760xc3jfu.fsf@openvz.org> (raw)


Math is wrong if range requested is less or equals to block size

xfs_io -c 'pwrite -b 4k 8k 4k -R' \
       -c 'pread -b 4k  4k 4k -R' -f file

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 io/pread.c  | 6 +++++-
 io/pwrite.c | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/io/pread.c b/io/pread.c
index f16c86c..b98355f 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -245,7 +245,11 @@ read_random(
 
 	*total = 0;
 	while (count > 0) {
-		off = ((offset + (random() % range)) / buffersize) * buffersize;
+		if (range)
+			off = ((offset + (random() % range)) / buffersize) *
+				buffersize;
+		else
+			off = offset;
 		bytes = do_pread(fd, off, buffersize, buffersize);
 		if (bytes == 0)
 			break;
diff --git a/io/pwrite.c b/io/pwrite.c
index 4fc8de6..67631ce 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -128,7 +128,11 @@ write_random(
 
 	*total = 0;
 	while (count > 0) {
-		off = ((offset + (random() % range)) / buffersize) * buffersize;
+		if (range)
+			off = ((offset + (random() % range)) / buffersize) *
+				buffersize;
+		else
+			off = offset;
 		bytes = do_pwrite(file->fd, off, buffersize, buffersize);
 		if (bytes == 0)
 			break;
-- 
1.8.3.1

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

             reply	other threads:[~2016-02-25 15:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 15:20 Dmitry Monakhov [this message]
2016-03-01 12:09 ` [PATCH] xfs_io: Prevent devide by zero from {pread, pwrite}_random Christoph Hellwig

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=8760xc3jfu.fsf@openvz.org \
    --to=dmonakhov@openvz.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox