public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
@ 2018-07-25  3:13 piaojun
  2018-07-25  3:32 ` Dominique Martinet
  0 siblings, 1 reply; 4+ messages in thread
From: piaojun @ 2018-07-25  3:13 UTC (permalink / raw)
  To: Dominique Martinet
  Cc: akpm@linux-foundation.org, Eric Van Hensbergen, Ron Minnich,
	Latchesar Ionkov, Linux Kernel Mailing List, v9fs-developer,
	groug

In my testing, v9fs_fid_xattr_set will return successfully even if the
backend ext4 filesystem has no space to store xattr key-value. That will
cause inconsistent behavior between front end and back end. The reason is
that lsetxattr will be triggered by p9_client_clunk, and unfortunately we
did not catch the error. This patch will catch the error to notify upper
caller.

p9_client_clunk (in 9p)
  p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
    v9fs_clunk (in qemu)
      put_fid
        free_fid
          v9fs_xattr_fid_clunk
            v9fs_co_lsetxattr
              s->ops->lsetxattr
                ext4_xattr_user_set (in host ext4 filesystem)

Signed-off-by: Jun Piao <piaojun@huawei.com>
---
 fs/9p/xattr.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
index f329eee..352abc3 100644
--- a/fs/9p/xattr.c
+++ b/fs/9p/xattr.c
@@ -105,7 +105,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
 {
 	struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
 	struct iov_iter from;
-	int retval;
+	int retval, err;

 	iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);

@@ -126,7 +126,9 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
 			 retval);
 	else
 		p9_client_write(fid, 0, &from, &retval);
-	p9_client_clunk(fid);
+	err = p9_client_clunk(fid);
+	if (!retval && err)
+		retval = err;
 	return retval;
 }

-- 

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

* Re: [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
  2018-07-25  3:13 [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed piaojun
@ 2018-07-25  3:32 ` Dominique Martinet
  2018-07-25  3:58   ` piaojun
  0 siblings, 1 reply; 4+ messages in thread
From: Dominique Martinet @ 2018-07-25  3:32 UTC (permalink / raw)
  To: piaojun
  Cc: akpm@linux-foundation.org, Eric Van Hensbergen, Ron Minnich,
	Latchesar Ionkov, Linux Kernel Mailing List, v9fs-developer,
	groug

piaojun wrote on Wed, Jul 25, 2018:
> In my testing, v9fs_fid_xattr_set will return successfully even if the
> backend ext4 filesystem has no space to store xattr key-value. That will
> cause inconsistent behavior between front end and back end. The reason is
> that lsetxattr will be triggered by p9_client_clunk, and unfortunately we
> did not catch the error. This patch will catch the error to notify upper
> caller.
> 
> p9_client_clunk (in 9p)
>   p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
>     v9fs_clunk (in qemu)
>       put_fid
>         free_fid
>           v9fs_xattr_fid_clunk
>             v9fs_co_lsetxattr
>               s->ops->lsetxattr
>                 ext4_xattr_user_set (in host ext4 filesystem)
> 
> Signed-off-by: Jun Piao <piaojun@huawei.com>

Good catch!

LGTM on its own but see comment below for further error checking.
Please let me know if you want to do this in a v2 or submit a separate
patch altogether, I can pick this one up as it is.

> ---
>  fs/9p/xattr.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
> index f329eee..352abc3 100644
> --- a/fs/9p/xattr.c
> +++ b/fs/9p/xattr.c
> @@ -105,7 +105,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
>  {
>  	struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
>  	struct iov_iter from;
> -	int retval;
> +	int retval, err;
> 
>  	iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);
> 
> @@ -126,7 +126,9 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
>  			 retval);
>  	else
>  		p9_client_write(fid, 0, &from, &retval);

I'm not sure what to do about this but it's also possible for
p9_client_write to not write the full length without setting and error.

We should probably compare the return value of p9_client_write and
value_len to detect short writes and return an error in this case.

> -	p9_client_clunk(fid);
> +	err = p9_client_clunk(fid);
> +	if (!retval && err)
> +		retval = err;
>  	return retval;
>  }
> 
> -- 

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

* Re: [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
  2018-07-25  3:32 ` Dominique Martinet
@ 2018-07-25  3:58   ` piaojun
  2018-07-25  4:06     ` Dominique Martinet
  0 siblings, 1 reply; 4+ messages in thread
From: piaojun @ 2018-07-25  3:58 UTC (permalink / raw)
  To: Dominique Martinet
  Cc: akpm@linux-foundation.org, Eric Van Hensbergen, Ron Minnich,
	Latchesar Ionkov, Linux Kernel Mailing List, v9fs-developer,
	groug

Hi Dominique,

On 2018/7/25 11:32, Dominique Martinet wrote:
> piaojun wrote on Wed, Jul 25, 2018:
>> In my testing, v9fs_fid_xattr_set will return successfully even if the
>> backend ext4 filesystem has no space to store xattr key-value. That will
>> cause inconsistent behavior between front end and back end. The reason is
>> that lsetxattr will be triggered by p9_client_clunk, and unfortunately we
>> did not catch the error. This patch will catch the error to notify upper
>> caller.
>>
>> p9_client_clunk (in 9p)
>>   p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
>>     v9fs_clunk (in qemu)
>>       put_fid
>>         free_fid
>>           v9fs_xattr_fid_clunk
>>             v9fs_co_lsetxattr
>>               s->ops->lsetxattr
>>                 ext4_xattr_user_set (in host ext4 filesystem)
>>
>> Signed-off-by: Jun Piao <piaojun@huawei.com>
> 
> Good catch!
> 
> LGTM on its own but see comment below for further error checking.
> Please let me know if you want to do this in a v2 or submit a separate
> patch altogether, I can pick this one up as it is.
> 
>> ---
>>  fs/9p/xattr.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
>> index f329eee..352abc3 100644
>> --- a/fs/9p/xattr.c
>> +++ b/fs/9p/xattr.c
>> @@ -105,7 +105,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
>>  {
>>  	struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
>>  	struct iov_iter from;
>> -	int retval;
>> +	int retval, err;
>>
>>  	iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);
>>
>> @@ -126,7 +126,9 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
>>  			 retval);
>>  	else
>>  		p9_client_write(fid, 0, &from, &retval);
> 
> I'm not sure what to do about this but it's also possible for
> p9_client_write to not write the full length without setting and error.
> 
> We should probably compare the return value of p9_client_write and
> value_len to detect short writes and return an error in this case.
> 
It looks like we could identify short writes error from the *err. If no
error case breaks the while loop, the total equal to the whole data len.

Thanks,
Jun

>> -	p9_client_clunk(fid);
>> +	err = p9_client_clunk(fid);
>> +	if (!retval && err)
>> +		retval = err;
>>  	return retval;
>>  }
>>
>> -- 
> .
> 

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

* Re: [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed
  2018-07-25  3:58   ` piaojun
@ 2018-07-25  4:06     ` Dominique Martinet
  0 siblings, 0 replies; 4+ messages in thread
From: Dominique Martinet @ 2018-07-25  4:06 UTC (permalink / raw)
  To: piaojun
  Cc: akpm@linux-foundation.org, Eric Van Hensbergen, Ron Minnich,
	Latchesar Ionkov, Linux Kernel Mailing List, v9fs-developer,
	groug

piaojun wrote on Wed, Jul 25, 2018:
> On 2018/7/25 11:32, Dominique Martinet wrote:
> >>  		p9_client_write(fid, 0, &from, &retval);
> > 
> > I'm not sure what to do about this but it's also possible for
> > p9_client_write to not write the full length without setting and error.
> > 
> > We should probably compare the return value of p9_client_write and
> > value_len to detect short writes and return an error in this case.
> 
> It looks like we could identify short writes error from the *err. If no
> error case breaks the while loop, the total equal to the whole data len.

Ah, I looked too fast and missed the while loop in p9_client_write...
It's rather unusual for such a low level call to handle retries, but I
guess that's 9p.

Right, will take that patch as is then.

Thanks,
-- 
Dominique

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

end of thread, other threads:[~2018-07-25  4:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25  3:13 [PATCH] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed piaojun
2018-07-25  3:32 ` Dominique Martinet
2018-07-25  3:58   ` piaojun
2018-07-25  4:06     ` Dominique Martinet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox