All of lore.kernel.org
 help / color / mirror / Atom feed
From: Su Yanjun <suyj.fnst@cn.fujitsu.com>
To: guaneryu@gmail.com
Cc: fstests@vger.kernel.org, suyj.fnst@cn.fujitsu.com
Subject: [PATCH] generic/465: fix a read bug when encounter EOF
Date: Mon, 16 Sep 2019 13:24:26 +0800	[thread overview]
Message-ID: <1568611466-100970-1-git-send-email-suyj.fnst@cn.fujitsu.com> (raw)

In nfs test, if the writer has not written enough data for reader reading,
then reader only get partial data and test fails.

We can continue reading until read enough data.

Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
---
 src/aio-dio-regress/aio-dio-append-write-read-race.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/aio-dio-regress/aio-dio-append-write-read-race.c b/src/aio-dio-regress/aio-dio-append-write-read-race.c
index 911f272..f28ef3c 100644
--- a/src/aio-dio-regress/aio-dio-append-write-read-race.c
+++ b/src/aio-dio-regress/aio-dio-append-write-read-race.c
@@ -44,14 +44,27 @@ static void usage(const char *prog)
 static void *reader(void *arg)
 {
 	struct io_data *data = (struct io_data *)arg;
+	size_t blksize = data->blksize;
+	size_t offset = data->offset;
+	char   *buf = data->buf;
 
 	memset(data->buf, 'b', data->blksize);
 	reader_ready = 1;
 	do {
-		data->read_sz = pread(data->fd, data->buf, data->blksize,
-				      data->offset);
+		data->read_sz = pread(data->fd, buf, blksize,
+				      offset);
 		if (data->read_sz < 0)
 			perror("read file");
+
+		if (data->read_sz > 0) {
+			blksize -= data->read_sz;
+			offset  += data->read_sz;
+			buf	+= data->read_sz;
+			data->read_sz = 0;
+		}
+
+		if (blksize <= 0)
+			break;
 	} while (data->read_sz <= 0);
 
 	return NULL;
-- 
2.7.4

             reply	other threads:[~2019-09-16  5:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16  5:24 Su Yanjun [this message]
2019-09-25  9:47 ` [PATCH] generic/465: fix a read bug when encounter EOF Eryu Guan
2019-09-27  1:46   ` Su Yanjun
2019-09-27  1:46     ` Su Yanjun

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=1568611466-100970-1-git-send-email-suyj.fnst@cn.fujitsu.com \
    --to=suyj.fnst@cn.fujitsu.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.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.