linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
@ 2022-08-18 12:50 Sun Ke
  2022-08-19  9:18 ` [Linux-cachefs] " Gao Xiang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sun Ke @ 2022-08-18 12:50 UTC (permalink / raw)
  To: dhowells
  Cc: linux-cachefs, linux-kernel, kernel-janitors, linux-fsdevel,
	jefflexu, sunke32

The cache_size field of copen is specified by the user daemon.
If cache_size < 0, then the OPEN request is expected to fail,
while copen itself shall succeed. However, returning 0 is indeed
unexpected when cache_size is an invalid error code.

Fix this by returning error when cache_size is an invalid error code.

Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie")
Signed-off-by: Sun Ke <sunke32@huawei.com>
---
v3: update the commit log suggested by Jingbo.

 fs/cachefiles/ondemand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
index 1fee702d5529..ea8a1e8317d9 100644
--- a/fs/cachefiles/ondemand.c
+++ b/fs/cachefiles/ondemand.c
@@ -159,7 +159,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
 	/* fail OPEN request if daemon reports an error */
 	if (size < 0) {
 		if (!IS_ERR_VALUE(size))
-			size = -EINVAL;
+			ret = size = -EINVAL;
 		req->error = size;
 		goto out;
 	}
-- 
2.31.1


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

* Re: [Linux-cachefs] [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-18 12:50 [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen() Sun Ke
@ 2022-08-19  9:18 ` Gao Xiang
  2022-08-20  9:22 ` JeffleXu
  2022-08-24 10:19 ` David Howells
  2 siblings, 0 replies; 8+ messages in thread
From: Gao Xiang @ 2022-08-19  9:18 UTC (permalink / raw)
  To: Sun Ke
  Cc: dhowells, kernel-janitors, linux-kernel, linux-cachefs, linux-fsdevel

On Thu, Aug 18, 2022 at 08:50:38PM +0800, Sun Ke wrote:
> The cache_size field of copen is specified by the user daemon.
> If cache_size < 0, then the OPEN request is expected to fail,
> while copen itself shall succeed. However, returning 0 is indeed
> unexpected when cache_size is an invalid error code.
> 
> Fix this by returning error when cache_size is an invalid error code.
> 
> Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie")
> Signed-off-by: Sun Ke <sunke32@huawei.com>

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

> ---
> v3: update the commit log suggested by Jingbo.
> 
>  fs/cachefiles/ondemand.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
> index 1fee702d5529..ea8a1e8317d9 100644
> --- a/fs/cachefiles/ondemand.c
> +++ b/fs/cachefiles/ondemand.c
> @@ -159,7 +159,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
>  	/* fail OPEN request if daemon reports an error */
>  	if (size < 0) {
>  		if (!IS_ERR_VALUE(size))
> -			size = -EINVAL;
> +			ret = size = -EINVAL;
>  		req->error = size;
>  		goto out;
>  	}
> -- 
> 2.31.1
> 
> --
> Linux-cachefs mailing list
> Linux-cachefs@redhat.com
> https://listman.redhat.com/mailman/listinfo/linux-cachefs

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

* Re: [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-18 12:50 [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen() Sun Ke
  2022-08-19  9:18 ` [Linux-cachefs] " Gao Xiang
@ 2022-08-20  9:22 ` JeffleXu
  2022-08-24 10:19 ` David Howells
  2 siblings, 0 replies; 8+ messages in thread
From: JeffleXu @ 2022-08-20  9:22 UTC (permalink / raw)
  To: Sun Ke, dhowells
  Cc: linux-cachefs, linux-kernel, kernel-janitors, linux-fsdevel



On 8/18/22 8:50 PM, Sun Ke wrote:
> The cache_size field of copen is specified by the user daemon.
> If cache_size < 0, then the OPEN request is expected to fail,
> while copen itself shall succeed. However, returning 0 is indeed
> unexpected when cache_size is an invalid error code.
> 
> Fix this by returning error when cache_size is an invalid error code.
> 
> Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie")
> Signed-off-by: Sun Ke <sunke32@huawei.com>

LGTM.

Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>

> ---
> v3: update the commit log suggested by Jingbo.
> 
>  fs/cachefiles/ondemand.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
> index 1fee702d5529..ea8a1e8317d9 100644
> --- a/fs/cachefiles/ondemand.c
> +++ b/fs/cachefiles/ondemand.c
> @@ -159,7 +159,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
>  	/* fail OPEN request if daemon reports an error */
>  	if (size < 0) {
>  		if (!IS_ERR_VALUE(size))
> -			size = -EINVAL;
> +			ret = size = -EINVAL;
>  		req->error = size;
>  		goto out;
>  	}

-- 
Thanks,
Jingbo

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

* Re: [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-18 12:50 [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen() Sun Ke
  2022-08-19  9:18 ` [Linux-cachefs] " Gao Xiang
  2022-08-20  9:22 ` JeffleXu
@ 2022-08-24 10:19 ` David Howells
  2022-08-24 11:33   ` JeffleXu
  2 siblings, 1 reply; 8+ messages in thread
From: David Howells @ 2022-08-24 10:19 UTC (permalink / raw)
  To: Sun Ke
  Cc: dhowells, linux-cachefs, linux-kernel, kernel-janitors,
	linux-fsdevel, jefflexu

	/* fail OPEN request if copen format is invalid */
	ret = kstrtol(psize, 0, &size);
	if (ret) {
		req->error = ret;
		goto out;
	}

	/* fail OPEN request if daemon reports an error */
	if (size < 0) {
		if (!IS_ERR_VALUE(size))
			ret = size = -EINVAL;
		req->error = size;
		goto out;
	}

Should ret get set to the error in size?

David


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

* Re: [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-24 10:19 ` David Howells
@ 2022-08-24 11:33   ` JeffleXu
  2022-08-25 13:36     ` Dan Carpenter
  0 siblings, 1 reply; 8+ messages in thread
From: JeffleXu @ 2022-08-24 11:33 UTC (permalink / raw)
  To: David Howells, Sun Ke
  Cc: linux-cachefs, linux-kernel, kernel-janitors, linux-fsdevel

Hi David,

On 8/24/22 6:19 PM, David Howells wrote:
> 	/* fail OPEN request if copen format is invalid */
> 	ret = kstrtol(psize, 0, &size);
> 	if (ret) {
> 		req->error = ret;
> 		goto out;
> 	}
> 
> 	/* fail OPEN request if daemon reports an error */
> 	if (size < 0) {
> 		if (!IS_ERR_VALUE(size))
> 			ret = size = -EINVAL;
> 		req->error = size;
> 		goto out;
> 	}
> 
> Should ret get set to the error in size?


The user daemon completes the OPEN request by replying with the "copen"
command.  The format of "copen" is like: "copen <id>,<cache_size>",
where <cache_size> specifies the size of the backing file. Besides,
<cache_size> is also reused for specifying the error code when the user
daemon thinks it should fail the OPEN request. In this case, the OPEN
request will fail, while the copen command (i.e.
cachefiles_ondemand_copen()) shall return 0, since the format of the
input "copen" command has no problem at all. After all, the error code
inside <cache_size> is specified by the user daemon itself, and the fact
that the OPEN request will fail totally lies in the expectation of the
user daemon.


On the other hand, cachefiles_ondemand_copen() needs to return error
code when the user daemon specifies the "copen" command in a wrong
format, e.g. specifying an invalid error code in <cache_size>. This is
exactly what this patch fixes.


-- 
Thanks,
Jingbo

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

* Re: [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-24 11:33   ` JeffleXu
@ 2022-08-25 13:36     ` Dan Carpenter
  2022-08-25 13:58       ` [Linux-cachefs] " Gao Xiang
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2022-08-25 13:36 UTC (permalink / raw)
  To: JeffleXu
  Cc: David Howells, Sun Ke, linux-cachefs, linux-kernel,
	kernel-janitors, linux-fsdevel

I spent a long time looking at this as well...  It's really inscrutable
code.  It would be more readable if we just spelled things out in the
most pedantic way possible:

diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
index 1fee702d5529..7e1586bd5cf3 100644
--- a/fs/cachefiles/ondemand.c
+++ b/fs/cachefiles/ondemand.c
@@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
 
 	/* fail OPEN request if daemon reports an error */
 	if (size < 0) {
-		if (!IS_ERR_VALUE(size))
-			size = -EINVAL;
-		req->error = size;
+		if (!IS_ERR_VALUE(size)) {
+			req->error = -EINVAL;
+			ret = -EINVAL;
+		} else {
+			req->error = size;
+			ret = 0;
+		}
 		goto out;
 	}
 


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

* Re: [Linux-cachefs] [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-25 13:36     ` Dan Carpenter
@ 2022-08-25 13:58       ` Gao Xiang
  2022-08-26  1:11         ` Sun Ke
  0 siblings, 1 reply; 8+ messages in thread
From: Gao Xiang @ 2022-08-25 13:58 UTC (permalink / raw)
  To: Sun Ke, Dan Carpenter
  Cc: JeffleXu, kernel-janitors, linux-kernel, linux-cachefs, linux-fsdevel

On Thu, Aug 25, 2022 at 04:36:20PM +0300, Dan Carpenter wrote:
> I spent a long time looking at this as well...  It's really inscrutable
> code.  It would be more readable if we just spelled things out in the
> most pedantic way possible:
> 

Yeah, the following code looks much better. Ke, would you mind
sending a version like below instead?

Thanks,
Gao Xiang

> diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
> index 1fee702d5529..7e1586bd5cf3 100644
> --- a/fs/cachefiles/ondemand.c
> +++ b/fs/cachefiles/ondemand.c
> @@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
>  
>  	/* fail OPEN request if daemon reports an error */
>  	if (size < 0) {
> -		if (!IS_ERR_VALUE(size))
> -			size = -EINVAL;
> -		req->error = size;
> +		if (!IS_ERR_VALUE(size)) {
> +			req->error = -EINVAL;
> +			ret = -EINVAL;
> +		} else {
> +			req->error = size;
> +			ret = 0;
> +		}
>  		goto out;
>  	}
>  
> 
> --
> Linux-cachefs mailing list
> Linux-cachefs@redhat.com
> https://listman.redhat.com/mailman/listinfo/linux-cachefs

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

* Re: [Linux-cachefs] [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen()
  2022-08-25 13:58       ` [Linux-cachefs] " Gao Xiang
@ 2022-08-26  1:11         ` Sun Ke
  0 siblings, 0 replies; 8+ messages in thread
From: Sun Ke @ 2022-08-26  1:11 UTC (permalink / raw)
  To: Dan Carpenter, JeffleXu, kernel-janitors, linux-kernel,
	linux-cachefs, linux-fsdevel



在 2022/8/25 21:58, Gao Xiang 写道:
> On Thu, Aug 25, 2022 at 04:36:20PM +0300, Dan Carpenter wrote:
>> I spent a long time looking at this as well...  It's really inscrutable
>> code.  It would be more readable if we just spelled things out in the
>> most pedantic way possible:
>>
> 
> Yeah, the following code looks much better. Ke, would you mind
> sending a version like below instead?

OK, I will update it.
> 
> Thanks,
> Gao Xiang
> 
>> diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
>> index 1fee702d5529..7e1586bd5cf3 100644
>> --- a/fs/cachefiles/ondemand.c
>> +++ b/fs/cachefiles/ondemand.c
>> @@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
>>   
>>   	/* fail OPEN request if daemon reports an error */
>>   	if (size < 0) {
>> -		if (!IS_ERR_VALUE(size))
>> -			size = -EINVAL;
>> -		req->error = size;
>> +		if (!IS_ERR_VALUE(size)) {
>> +			req->error = -EINVAL;
>> +			ret = -EINVAL;
>> +		} else {
>> +			req->error = size;
>> +			ret = 0;
>> +		}
>>   		goto out;
>>   	}
>>   
>>
>> --
>> Linux-cachefs mailing list
>> Linux-cachefs@redhat.com
>> https://listman.redhat.com/mailman/listinfo/linux-cachefs
> .
> 

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

end of thread, other threads:[~2022-08-26  1:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 12:50 [PATCH v3] cachefiles: fix error return code in cachefiles_ondemand_copen() Sun Ke
2022-08-19  9:18 ` [Linux-cachefs] " Gao Xiang
2022-08-20  9:22 ` JeffleXu
2022-08-24 10:19 ` David Howells
2022-08-24 11:33   ` JeffleXu
2022-08-25 13:36     ` Dan Carpenter
2022-08-25 13:58       ` [Linux-cachefs] " Gao Xiang
2022-08-26  1:11         ` Sun Ke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).