FSTests Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] generic/465: fix a read bug when encounter EOF
@ 2019-09-16  5:24 Su Yanjun
  2019-09-25  9:47 ` Eryu Guan
  0 siblings, 1 reply; 4+ messages in thread
From: Su Yanjun @ 2019-09-16  5:24 UTC (permalink / raw)
  To: guaneryu; +Cc: fstests, suyj.fnst

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] generic/465: fix a read bug when encounter EOF
  2019-09-16  5:24 [PATCH] generic/465: fix a read bug when encounter EOF Su Yanjun
@ 2019-09-25  9:47 ` Eryu Guan
  2019-09-27  1:46   ` Su Yanjun
  0 siblings, 1 reply; 4+ messages in thread
From: Eryu Guan @ 2019-09-25  9:47 UTC (permalink / raw)
  To: Su Yanjun; +Cc: fstests

On Mon, Sep 16, 2019 at 01:24:26PM +0800, Su Yanjun wrote:
> 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>

Would you please provide more info on the actual failure you've seen? I
think the partial read issue should have been addressed by commit
2428c08a6025 ("generic/465: just check the actual read data under dio
read/write")

Thanks,
Eryu

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] generic/465: fix a read bug when encounter EOF
  2019-09-25  9:47 ` Eryu Guan
@ 2019-09-27  1:46   ` Su Yanjun
  2019-09-27  1:46     ` Su Yanjun
  0 siblings, 1 reply; 4+ messages in thread
From: Su Yanjun @ 2019-09-27  1:46 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests


在 2019/9/25 17:47, Eryu Guan 写道:
> On Mon, Sep 16, 2019 at 01:24:26PM +0800, Su Yanjun wrote:
>> 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>
> Would you please provide more info on the actual failure you've seen? I
> think the partial read issue should have been addressed by commit
> 2428c08a6025 ("generic/465: just check the actual read data under dio
> read/write")

I rechecked my patch and my patch is not needed at all.

It's  only workaround of a kernel bug of nfs. In some cases nfs returns 
wrong data to userspace, but the return value is ok.

I will send a kernel patch to nfs mailist.

Thanks a lot.

>
> Thanks,
> Eryu
>
>> ---
>>   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
>>
>>
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] generic/465: fix a read bug when encounter EOF
  2019-09-27  1:46   ` Su Yanjun
@ 2019-09-27  1:46     ` Su Yanjun
  0 siblings, 0 replies; 4+ messages in thread
From: Su Yanjun @ 2019-09-27  1:46 UTC (permalink / raw)
  To: Eryu Guan; +Cc: fstests


在 2019/9/25 17:47, Eryu Guan 写道:
> On Mon, Sep 16, 2019 at 01:24:26PM +0800, Su Yanjun wrote:
>> 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>
> Would you please provide more info on the actual failure you've seen? I
> think the partial read issue should have been addressed by commit
> 2428c08a6025 ("generic/465: just check the actual read data under dio
> read/write")

I rechecked my patch and my patch is not needed at all.

It's  only workaround of a kernel bug of nfs. In some cases nfs returns 
wrong data to userspace, but the return value is ok.

I will send a kernel patch to nfs mailist.

Thanks a lot.

>
> Thanks,
> Eryu
>
>> ---
>>   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
>>
>>
>>
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  5:24 [PATCH] generic/465: fix a read bug when encounter EOF Su Yanjun
2019-09-25  9:47 ` Eryu Guan
2019-09-27  1:46   ` Su Yanjun
2019-09-27  1:46     ` Su Yanjun

FSTests Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/fstests/0 fstests/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 fstests fstests/ https://lore.kernel.org/fstests \
		fstests@vger.kernel.org linux-fstests@archiver.kernel.org
	public-inbox-index fstests

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.fstests


AGPL code for this site: git clone https://public-inbox.org/ public-inbox