diff mbox series

[v2,1/2] nfsd: Fix a regression in nfsd_setattr()

Message ID 20240216012451.22725-2-trondmy@kernel.org (mailing list archive)
State New
Headers show
Series Fix NFSv3 SETATTR behaviours | expand

Commit Message

Trond Myklebust Feb. 16, 2024, 1:24 a.m. UTC
From: Trond Myklebust <trond.myklebust@hammerspace.com>

Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls to
fh_fill_pre_attrs() and fh_fill_post_attrs().

Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of fh_(un)lock for file operations")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfsd/nfs4proc.c | 4 ++++
 fs/nfsd/vfs.c      | 9 +++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

Comments

Chuck Lever Feb. 16, 2024, 1:33 p.m. UTC | #1
On Thu, Feb 15, 2024 at 08:24:50PM -0500, trondmy@kernel.org wrote:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes behaviour
> when doing a SETATTR rpc call by stripping out the calls to
> fh_fill_pre_attrs() and fh_fill_post_attrs().

Can you give more detail about what broke?


> Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of fh_(un)lock for file operations")
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  fs/nfsd/nfs4proc.c | 4 ++++
>  fs/nfsd/vfs.c      | 9 +++++++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 14712fa08f76..e6d8624efc83 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>  	};
>  	struct inode *inode;
>  	__be32 status = nfs_ok;
> +	bool save_no_wcc;
>  	int err;
>  
>  	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
> @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>  
>  	if (status)
>  		goto out;
> +	save_no_wcc = cstate->current_fh.fh_no_wcc;
> +	cstate->current_fh.fh_no_wcc = true;
>  	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
>  				0, (time64_t)0);
> +	cstate->current_fh.fh_no_wcc = save_no_wcc;
>  	if (!status)
>  		status = nfserrno(attrs.na_labelerr);
>  	if (!status)
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 6e7e37192461..58fab461bc00 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  	int		accmode = NFSD_MAY_SATTR;
>  	umode_t		ftype = 0;
>  	__be32		err;
> -	int		host_err;
> +	int		host_err = 0;
>  	bool		get_write_count;
>  	bool		size_change = (iap->ia_valid & ATTR_SIZE);
>  	int		retries;
> @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  	}
>  
>  	inode_lock(inode);
> +	err = fh_fill_pre_attrs(fhp);
> +	if (err)
> +		goto out_unlock;
>  	for (retries = 1;;) {
>  		struct iattr attrs;
>  
> @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  		attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
>  						dentry, ACL_TYPE_DEFAULT,
>  						attr->na_dpacl);
> +	fh_fill_post_attrs(fhp);
> +out_unlock:
>  	inode_unlock(inode);
>  	if (size_change)
>  		put_write_access(inode);
>  out:
>  	if (!host_err)
>  		host_err = commit_metadata(fhp);
> -	return nfserrno(host_err);
> +	return err != 0 ? err : nfserrno(host_err);
>  }
>  
>  #if defined(CONFIG_NFSD_V4)
> -- 
> 2.43.1
> 
>
Trond Myklebust Feb. 16, 2024, 6:18 p.m. UTC | #2
On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
> On Thu, Feb 15, 2024 at 08:24:50PM -0500, trondmy@kernel.org wrote:
> > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > 
> > Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
> > behaviour
> > when doing a SETATTR rpc call by stripping out the calls to
> > fh_fill_pre_attrs() and fh_fill_post_attrs().
> 
> Can you give more detail about what broke?

Without the calls to fh_fill_pre_attrs() and fh_fill_post_attrs(), we
don't store any pre/post op attributes and we can't return any such
attributes to the NFSv3 client.

> 
> 
> > Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of
> > fh_(un)lock for file operations")
> > Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> > ---
> >  fs/nfsd/nfs4proc.c | 4 ++++
> >  fs/nfsd/vfs.c      | 9 +++++++--
> >  2 files changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> > index 14712fa08f76..e6d8624efc83 100644
> > --- a/fs/nfsd/nfs4proc.c
> > +++ b/fs/nfsd/nfs4proc.c
> > @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
> > nfsd4_compound_state *cstate,
> >  	};
> >  	struct inode *inode;
> >  	__be32 status = nfs_ok;
> > +	bool save_no_wcc;
> >  	int err;
> >  
> >  	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
> > @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
> > nfsd4_compound_state *cstate,
> >  
> >  	if (status)
> >  		goto out;
> > +	save_no_wcc = cstate->current_fh.fh_no_wcc;
> > +	cstate->current_fh.fh_no_wcc = true;
> >  	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
> >  				0, (time64_t)0);
> > +	cstate->current_fh.fh_no_wcc = save_no_wcc;
> >  	if (!status)
> >  		status = nfserrno(attrs.na_labelerr);
> >  	if (!status)
> > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> > index 6e7e37192461..58fab461bc00 100644
> > --- a/fs/nfsd/vfs.c
> > +++ b/fs/nfsd/vfs.c
> > @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
> > svc_fh *fhp,
> >  	int		accmode = NFSD_MAY_SATTR;
> >  	umode_t		ftype = 0;
> >  	__be32		err;
> > -	int		host_err;
> > +	int		host_err = 0;
> >  	bool		get_write_count;
> >  	bool		size_change = (iap->ia_valid & ATTR_SIZE);
> >  	int		retries;
> > @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
> > svc_fh *fhp,
> >  	}
> >  
> >  	inode_lock(inode);
> > +	err = fh_fill_pre_attrs(fhp);
> > +	if (err)
> > +		goto out_unlock;
> >  	for (retries = 1;;) {
> >  		struct iattr attrs;
> >  
> > @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
> > svc_fh *fhp,
> >  		attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
> >  						dentry,
> > ACL_TYPE_DEFAULT,
> >  						attr->na_dpacl);
> > +	fh_fill_post_attrs(fhp);
> > +out_unlock:
> >  	inode_unlock(inode);
> >  	if (size_change)
> >  		put_write_access(inode);
> >  out:
> >  	if (!host_err)
> >  		host_err = commit_metadata(fhp);
> > -	return nfserrno(host_err);
> > +	return err != 0 ? err : nfserrno(host_err);
> >  }
> >  
> >  #if defined(CONFIG_NFSD_V4)
> > -- 
> > 2.43.1
> > 
> > 
>
Chuck Lever Feb. 16, 2024, 6:19 p.m. UTC | #3
> On Feb 16, 2024, at 1:18 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
> 
> On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
>> On Thu, Feb 15, 2024 at 08:24:50PM -0500, trondmy@kernel.org wrote:
>>> From: Trond Myklebust <trond.myklebust@hammerspace.com>
>>> 
>>> Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
>>> behaviour
>>> when doing a SETATTR rpc call by stripping out the calls to
>>> fh_fill_pre_attrs() and fh_fill_post_attrs().
>> 
>> Can you give more detail about what broke?
> 
> Without the calls to fh_fill_pre_attrs() and fh_fill_post_attrs(), we
> don't store any pre/post op attributes and we can't return any such
> attributes to the NFSv3 client.

I get that. Why does that matter?


>>> Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of
>>> fh_(un)lock for file operations")
>>> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
>>> ---
>>>  fs/nfsd/nfs4proc.c | 4 ++++
>>>  fs/nfsd/vfs.c      | 9 +++++++--
>>>  2 files changed, 11 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
>>> index 14712fa08f76..e6d8624efc83 100644
>>> --- a/fs/nfsd/nfs4proc.c
>>> +++ b/fs/nfsd/nfs4proc.c
>>> @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
>>> nfsd4_compound_state *cstate,
>>>   };
>>>   struct inode *inode;
>>>   __be32 status = nfs_ok;
>>> + bool save_no_wcc;
>>>   int err;
>>>  
>>>   if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
>>> @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
>>> nfsd4_compound_state *cstate,
>>>  
>>>   if (status)
>>>   goto out;
>>> + save_no_wcc = cstate->current_fh.fh_no_wcc;
>>> + cstate->current_fh.fh_no_wcc = true;
>>>   status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
>>>   0, (time64_t)0);
>>> + cstate->current_fh.fh_no_wcc = save_no_wcc;
>>>   if (!status)
>>>   status = nfserrno(attrs.na_labelerr);
>>>   if (!status)
>>> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
>>> index 6e7e37192461..58fab461bc00 100644
>>> --- a/fs/nfsd/vfs.c
>>> +++ b/fs/nfsd/vfs.c
>>> @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>> svc_fh *fhp,
>>>   int accmode = NFSD_MAY_SATTR;
>>>   umode_t ftype = 0;
>>>   __be32 err;
>>> - int host_err;
>>> + int host_err = 0;
>>>   bool get_write_count;
>>>   bool size_change = (iap->ia_valid & ATTR_SIZE);
>>>   int retries;
>>> @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>> svc_fh *fhp,
>>>   }
>>>  
>>>   inode_lock(inode);
>>> + err = fh_fill_pre_attrs(fhp);
>>> + if (err)
>>> + goto out_unlock;
>>>   for (retries = 1;;) {
>>>   struct iattr attrs;
>>>  
>>> @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>> svc_fh *fhp,
>>>   attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
>>>   dentry,
>>> ACL_TYPE_DEFAULT,
>>>   attr->na_dpacl);
>>> + fh_fill_post_attrs(fhp);
>>> +out_unlock:
>>>   inode_unlock(inode);
>>>   if (size_change)
>>>   put_write_access(inode);
>>>  out:
>>>   if (!host_err)
>>>   host_err = commit_metadata(fhp);
>>> - return nfserrno(host_err);
>>> + return err != 0 ? err : nfserrno(host_err);
>>>  }
>>>  
>>>  #if defined(CONFIG_NFSD_V4)
>>> -- 
>>> 2.43.1
>>> 
>>> 
>> 
> 
> -- 
> Trond Myklebust
> Linux NFS client maintainer, Hammerspace
> trond.myklebust@hammerspace.com


--
Chuck Lever
Chuck Lever Feb. 16, 2024, 6:25 p.m. UTC | #4
> On Feb 16, 2024, at 1:19 PM, Chuck Lever III <chuck.lever@oracle.com> wrote:
> 
> 
> 
>> On Feb 16, 2024, at 1:18 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
>> 
>> On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
>>> On Thu, Feb 15, 2024 at 08:24:50PM -0500, trondmy@kernel.org wrote:
>>>> From: Trond Myklebust <trond.myklebust@hammerspace.com>
>>>> 
>>>> Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
>>>> behaviour
>>>> when doing a SETATTR rpc call by stripping out the calls to
>>>> fh_fill_pre_attrs() and fh_fill_post_attrs().
>>> 
>>> Can you give more detail about what broke?
>> 
>> Without the calls to fh_fill_pre_attrs() and fh_fill_post_attrs(), we
>> don't store any pre/post op attributes and we can't return any such
>> attributes to the NFSv3 client.
> 
> I get that. Why does that matter?

Or, to be a little less terse... clients rely on the pre/post
op attributes around a SETATTR, I guess, but I don't see why.
I'm missing some context.


>>>> Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of
>>>> fh_(un)lock for file operations")
>>>> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
>>>> ---
>>>> fs/nfsd/nfs4proc.c | 4 ++++
>>>> fs/nfsd/vfs.c      | 9 +++++++--
>>>> 2 files changed, 11 insertions(+), 2 deletions(-)
>>>> 
>>>> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
>>>> index 14712fa08f76..e6d8624efc83 100644
>>>> --- a/fs/nfsd/nfs4proc.c
>>>> +++ b/fs/nfsd/nfs4proc.c
>>>> @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
>>>> nfsd4_compound_state *cstate,
>>>>  };
>>>>  struct inode *inode;
>>>>  __be32 status = nfs_ok;
>>>> + bool save_no_wcc;
>>>>  int err;
>>>> 
>>>>  if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
>>>> @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
>>>> nfsd4_compound_state *cstate,
>>>> 
>>>>  if (status)
>>>>  goto out;
>>>> + save_no_wcc = cstate->current_fh.fh_no_wcc;
>>>> + cstate->current_fh.fh_no_wcc = true;
>>>>  status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
>>>>  0, (time64_t)0);
>>>> + cstate->current_fh.fh_no_wcc = save_no_wcc;
>>>>  if (!status)
>>>>  status = nfserrno(attrs.na_labelerr);
>>>>  if (!status)
>>>> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
>>>> index 6e7e37192461..58fab461bc00 100644
>>>> --- a/fs/nfsd/vfs.c
>>>> +++ b/fs/nfsd/vfs.c
>>>> @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>>> svc_fh *fhp,
>>>>  int accmode = NFSD_MAY_SATTR;
>>>>  umode_t ftype = 0;
>>>>  __be32 err;
>>>> - int host_err;
>>>> + int host_err = 0;
>>>>  bool get_write_count;
>>>>  bool size_change = (iap->ia_valid & ATTR_SIZE);
>>>>  int retries;
>>>> @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>>> svc_fh *fhp,
>>>>  }
>>>> 
>>>>  inode_lock(inode);
>>>> + err = fh_fill_pre_attrs(fhp);
>>>> + if (err)
>>>> + goto out_unlock;
>>>>  for (retries = 1;;) {
>>>>  struct iattr attrs;
>>>> 
>>>> @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, struct
>>>> svc_fh *fhp,
>>>>  attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
>>>>  dentry,
>>>> ACL_TYPE_DEFAULT,
>>>>  attr->na_dpacl);
>>>> + fh_fill_post_attrs(fhp);
>>>> +out_unlock:
>>>>  inode_unlock(inode);
>>>>  if (size_change)
>>>>  put_write_access(inode);
>>>> out:
>>>>  if (!host_err)
>>>>  host_err = commit_metadata(fhp);
>>>> - return nfserrno(host_err);
>>>> + return err != 0 ? err : nfserrno(host_err);
>>>> }
>>>> 
>>>> #if defined(CONFIG_NFSD_V4)
>>>> -- 
>>>> 2.43.1
>>>> 
>>>> 
>>> 
>> 
>> -- 
>> Trond Myklebust
>> Linux NFS client maintainer, Hammerspace
>> trond.myklebust@hammerspace.com
> 
> 
> --
> Chuck Lever


--
Chuck Lever
Trond Myklebust Feb. 16, 2024, 6:57 p.m. UTC | #5
On Fri, 2024-02-16 at 18:25 +0000, Chuck Lever III wrote:
> 
> 
> > On Feb 16, 2024, at 1:19 PM, Chuck Lever III
> > <chuck.lever@oracle.com> wrote:
> > 
> > 
> > 
> > > On Feb 16, 2024, at 1:18 PM, Trond Myklebust
> > > <trondmy@hammerspace.com> wrote:
> > > 
> > > On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
> > > > On Thu, Feb 15, 2024 at 08:24:50PM -0500,
> > > > trondmy@kernel.org wrote:
> > > > > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > > > > 
> > > > > Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
> > > > > behaviour
> > > > > when doing a SETATTR rpc call by stripping out the calls to
> > > > > fh_fill_pre_attrs() and fh_fill_post_attrs().
> > > > 
> > > > Can you give more detail about what broke?
> > > 
> > > Without the calls to fh_fill_pre_attrs() and
> > > fh_fill_post_attrs(), we
> > > don't store any pre/post op attributes and we can't return any
> > > such
> > > attributes to the NFSv3 client.
> > 
> > I get that. Why does that matter?
> 
> Or, to be a little less terse... clients rely on the pre/post
> op attributes around a SETATTR, I guess, but I don't see why.
> I'm missing some context.

   1. SETATTR is not atomic, and is not implemented as being atomic in
      Linux. It is perfectly possible for, say, the file to get
      truncated, but for the other attribute changes to get dropped on
      the floor. NFSv4 communicates that information via the bitmap.
      NFSv3 does it using the pre/post attributes.
   2. When doing a guarded SETATTR, if the server returns
      NFS3ERR_NOT_SYNC, the client may want to update its cached ctime
      and resend.


> 
> 
> > > > > Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of
> > > > > fh_(un)lock for file operations")
> > > > > Signed-off-by: Trond Myklebust
> > > > > <trond.myklebust@hammerspace.com>
> > > > > ---
> > > > > fs/nfsd/nfs4proc.c | 4 ++++
> > > > > fs/nfsd/vfs.c      | 9 +++++++--
> > > > > 2 files changed, 11 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> > > > > index 14712fa08f76..e6d8624efc83 100644
> > > > > --- a/fs/nfsd/nfs4proc.c
> > > > > +++ b/fs/nfsd/nfs4proc.c
> > > > > @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp,
> > > > > struct
> > > > > nfsd4_compound_state *cstate,
> > > > >  };
> > > > >  struct inode *inode;
> > > > >  __be32 status = nfs_ok;
> > > > > + bool save_no_wcc;
> > > > >  int err;
> > > > > 
> > > > >  if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
> > > > > @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp,
> > > > > struct
> > > > > nfsd4_compound_state *cstate,
> > > > > 
> > > > >  if (status)
> > > > >  goto out;
> > > > > + save_no_wcc = cstate->current_fh.fh_no_wcc;
> > > > > + cstate->current_fh.fh_no_wcc = true;
> > > > >  status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
> > > > >  0, (time64_t)0);
> > > > > + cstate->current_fh.fh_no_wcc = save_no_wcc;
> > > > >  if (!status)
> > > > >  status = nfserrno(attrs.na_labelerr);
> > > > >  if (!status)
> > > > > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> > > > > index 6e7e37192461..58fab461bc00 100644
> > > > > --- a/fs/nfsd/vfs.c
> > > > > +++ b/fs/nfsd/vfs.c
> > > > > @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp,
> > > > > struct
> > > > > svc_fh *fhp,
> > > > >  int accmode = NFSD_MAY_SATTR;
> > > > >  umode_t ftype = 0;
> > > > >  __be32 err;
> > > > > - int host_err;
> > > > > + int host_err = 0;
> > > > >  bool get_write_count;
> > > > >  bool size_change = (iap->ia_valid & ATTR_SIZE);
> > > > >  int retries;
> > > > > @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp,
> > > > > struct
> > > > > svc_fh *fhp,
> > > > >  }
> > > > > 
> > > > >  inode_lock(inode);
> > > > > + err = fh_fill_pre_attrs(fhp);
> > > > > + if (err)
> > > > > + goto out_unlock;
> > > > >  for (retries = 1;;) {
> > > > >  struct iattr attrs;
> > > > > 
> > > > > @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp,
> > > > > struct
> > > > > svc_fh *fhp,
> > > > >  attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
> > > > >  dentry,
> > > > > ACL_TYPE_DEFAULT,
> > > > >  attr->na_dpacl);
> > > > > + fh_fill_post_attrs(fhp);
> > > > > +out_unlock:
> > > > >  inode_unlock(inode);
> > > > >  if (size_change)
> > > > >  put_write_access(inode);
> > > > > out:
> > > > >  if (!host_err)
> > > > >  host_err = commit_metadata(fhp);
> > > > > - return nfserrno(host_err);
> > > > > + return err != 0 ? err : nfserrno(host_err);
> > > > > }
> > > > > 
> > > > > #if defined(CONFIG_NFSD_V4)
> > > > > -- 
> > > > > 2.43.1
> > > > > 
> > > > > 
> > > >
Chuck Lever Feb. 17, 2024, 5:05 p.m. UTC | #6
On Fri, Feb 16, 2024 at 06:57:16PM +0000, Trond Myklebust wrote:
> On Fri, 2024-02-16 at 18:25 +0000, Chuck Lever III wrote:
> > 
> > 
> > > On Feb 16, 2024, at 1:19 PM, Chuck Lever III
> > > <chuck.lever@oracle.com> wrote:
> > > 
> > > 
> > > 
> > > > On Feb 16, 2024, at 1:18 PM, Trond Myklebust
> > > > <trondmy@hammerspace.com> wrote:
> > > > 
> > > > On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
> > > > > On Thu, Feb 15, 2024 at 08:24:50PM -0500,
> > > > > trondmy@kernel.org wrote:
> > > > > > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > > > > > 
> > > > > > Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
> > > > > > behaviour
> > > > > > when doing a SETATTR rpc call by stripping out the calls to
> > > > > > fh_fill_pre_attrs() and fh_fill_post_attrs().
> > > > > 
> > > > > Can you give more detail about what broke?
> > > > 
> > > > Without the calls to fh_fill_pre_attrs() and
> > > > fh_fill_post_attrs(), we
> > > > don't store any pre/post op attributes and we can't return any
> > > > such
> > > > attributes to the NFSv3 client.
> > > 
> > > I get that. Why does that matter?
> > 
> > Or, to be a little less terse... clients rely on the pre/post
> > op attributes around a SETATTR, I guess, but I don't see why.
> > I'm missing some context.
> 
>    1. SETATTR is not atomic, and is not implemented as being atomic in
>       Linux. It is perfectly possible for, say, the file to get
>       truncated, but for the other attribute changes to get dropped on
>       the floor. NFSv4 communicates that information via the bitmap.
>       NFSv3 does it using the pre/post attributes.
>    2. When doing a guarded SETATTR, if the server returns
>       NFS3ERR_NOT_SYNC, the client may want to update its cached ctime
>       and resend.

All granted, but I'm still not clear. Let me ask this a different
way.

As far as I can tell, it's always been optional for an NFSv3 server
to include pre- and post-op attributes in wcc_data. Both the
pre_op_attr and post_op_attr XDR types start with an
"attribute_follows" discriminator. Therefore clients cannot rely on
receiving those attributes.

The patch description says that "Commit bb4d53d66e4b broke the NFSv3
                                                     ^^^^^
pre/post op attributes ...". And I think you also used the word
"nasty" in an earlier email. So what is broken if the server /never/
returns those attributes? What are the application-visible effects
of the server behavior change in bb4d53d66e4b ?

I don't have a problem reverting that part of bb4d53d66e4b, but
"broke" is doing some heavy lifting here. I want to understand why
we need to revert. Because it seems to me the server's current NFSv3
SETATTR implementation is spec-compliant. As far as I can tell,
bb4d53d66e4b might result in a little more network traffic in some
cases, but it won't impact interoperability or outcome.

Do you mean that you want to restore the previous, more optimized,
server behavior to return pre- and post-op attributes when they are
available? And if so, what is the application-visible benefit?
Trond Myklebust Feb. 17, 2024, 6:16 p.m. UTC | #7
On Sat, 2024-02-17 at 12:05 -0500, Chuck Lever wrote:
> On Fri, Feb 16, 2024 at 06:57:16PM +0000, Trond Myklebust wrote:
> > On Fri, 2024-02-16 at 18:25 +0000, Chuck Lever III wrote:
> > > 
> > > 
> > > > On Feb 16, 2024, at 1:19 PM, Chuck Lever III
> > > > <chuck.lever@oracle.com> wrote:
> > > > 
> > > > 
> > > > 
> > > > > On Feb 16, 2024, at 1:18 PM, Trond Myklebust
> > > > > <trondmy@hammerspace.com> wrote:
> > > > > 
> > > > > On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
> > > > > > On Thu, Feb 15, 2024 at 08:24:50PM -0500,
> > > > > > trondmy@kernel.org wrote:
> > > > > > > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > > > > > > 
> > > > > > > Commit bb4d53d66e4b broke the NFSv3 pre/post op
> > > > > > > attributes
> > > > > > > behaviour
> > > > > > > when doing a SETATTR rpc call by stripping out the calls
> > > > > > > to
> > > > > > > fh_fill_pre_attrs() and fh_fill_post_attrs().
> > > > > > 
> > > > > > Can you give more detail about what broke?
> > > > > 
> > > > > Without the calls to fh_fill_pre_attrs() and
> > > > > fh_fill_post_attrs(), we
> > > > > don't store any pre/post op attributes and we can't return
> > > > > any
> > > > > such
> > > > > attributes to the NFSv3 client.
> > > > 
> > > > I get that. Why does that matter?
> > > 
> > > Or, to be a little less terse... clients rely on the pre/post
> > > op attributes around a SETATTR, I guess, but I don't see why.
> > > I'm missing some context.
> > 
> >    1. SETATTR is not atomic, and is not implemented as being atomic
> > in
> >       Linux. It is perfectly possible for, say, the file to get
> >       truncated, but for the other attribute changes to get dropped
> > on
> >       the floor. NFSv4 communicates that information via the
> > bitmap.
> >       NFSv3 does it using the pre/post attributes.
> >    2. When doing a guarded SETATTR, if the server returns
> >       NFS3ERR_NOT_SYNC, the client may want to update its cached
> > ctime
> >       and resend.
> 
> All granted, but I'm still not clear. Let me ask this a different
> way.
> 
> As far as I can tell, it's always been optional for an NFSv3 server
> to include pre- and post-op attributes in wcc_data. Both the
> pre_op_attr and post_op_attr XDR types start with an
> "attribute_follows" discriminator. Therefore clients cannot rely on
> receiving those attributes.
> 
> The patch description says that "Commit bb4d53d66e4b broke the NFSv3
>                                                      ^^^^^
> pre/post op attributes ...". And I think you also used the word
> "nasty" in an earlier email. So what is broken if the server /never/
> returns those attributes? What are the application-visible effects
> of the server behavior change in bb4d53d66e4b ?
> 
> I don't have a problem reverting that part of bb4d53d66e4b, but
> "broke" is doing some heavy lifting here. I want to understand why
> we need to revert. Because it seems to me the server's current NFSv3
> SETATTR implementation is spec-compliant. As far as I can tell,
> bb4d53d66e4b might result in a little more network traffic in some
> cases, but it won't impact interoperability or outcome.
> 

As I said above, you broke the NFSv3 client's ability to determine
whether or not the SETATTR was a failure, success or a partial success.
That's not heavy lifting, it is a fact.

The function nfsd_setattr() uses two different calls to notify_change()
in order to perform its function. Either one of them can return an
error. Either one of them can fail, and the way that the client finds
out whether or not the operation was a partial success is by examining
the pre/post op attributes (NFSv3) or the returned bitmap (NFSv4).

The patch does not try to fix NFSv4, since AFAICS, that code has always
been broken.

However, the NFSv3 code was not broken prior to bb4d53d66e4b. It was
correctly returning pre/post op attributes that reflected the
success/failure of the setattr operation. That is therefore a
regression.
Furthermore, it is a totally unnecessary regression. The whole point of
SETATTR is to change the value of the attributes of the exact same file
for which the pre/post op attributes are being retrieved. There is no
extra disk access required to retrieve those attributes, nor should
there be any other overhead other than copying them into the buffer.

> Do you mean that you want to restore the previous, more optimized,
> server behavior to return pre- and post-op attributes when they are
> available? And if so, what is the application-visible benefit?

Application correctness: the ability to see that your file got
truncated despite the RPC call returning an error.
Jeffrey Layton Feb. 18, 2024, 2:21 p.m. UTC | #8
On Sat, 2024-02-17 at 18:16 +0000, Trond Myklebust wrote:
> On Sat, 2024-02-17 at 12:05 -0500, Chuck Lever wrote:
> > On Fri, Feb 16, 2024 at 06:57:16PM +0000, Trond Myklebust wrote:
> > > On Fri, 2024-02-16 at 18:25 +0000, Chuck Lever III wrote:
> > > > 
> > > > 
> > > > > On Feb 16, 2024, at 1:19 PM, Chuck Lever III
> > > > > <chuck.lever@oracle.com> wrote:
> > > > > 
> > > > > 
> > > > > 
> > > > > > On Feb 16, 2024, at 1:18 PM, Trond Myklebust
> > > > > > <trondmy@hammerspace.com> wrote:
> > > > > > 
> > > > > > On Fri, 2024-02-16 at 08:33 -0500, Chuck Lever wrote:
> > > > > > > On Thu, Feb 15, 2024 at 08:24:50PM -0500,
> > > > > > > trondmy@kernel.org wrote:
> > > > > > > > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > > > > > > > 
> > > > > > > > Commit bb4d53d66e4b broke the NFSv3 pre/post op
> > > > > > > > attributes
> > > > > > > > behaviour
> > > > > > > > when doing a SETATTR rpc call by stripping out the calls
> > > > > > > > to
> > > > > > > > fh_fill_pre_attrs() and fh_fill_post_attrs().
> > > > > > > 
> > > > > > > Can you give more detail about what broke?
> > > > > > 
> > > > > > Without the calls to fh_fill_pre_attrs() and
> > > > > > fh_fill_post_attrs(), we
> > > > > > don't store any pre/post op attributes and we can't return
> > > > > > any
> > > > > > such
> > > > > > attributes to the NFSv3 client.
> > > > > 
> > > > > I get that. Why does that matter?
> > > > 
> > > > Or, to be a little less terse... clients rely on the pre/post
> > > > op attributes around a SETATTR, I guess, but I don't see why.
> > > > I'm missing some context.
> > > 
> > >    1. SETATTR is not atomic, and is not implemented as being atomic
> > > in
> > >       Linux. It is perfectly possible for, say, the file to get
> > >       truncated, but for the other attribute changes to get dropped
> > > on
> > >       the floor. NFSv4 communicates that information via the
> > > bitmap.
> > >       NFSv3 does it using the pre/post attributes.
> > >    2. When doing a guarded SETATTR, if the server returns
> > >       NFS3ERR_NOT_SYNC, the client may want to update its cached
> > > ctime
> > >       and resend.
> > 
> > All granted, but I'm still not clear. Let me ask this a different
> > way.
> > 
> > As far as I can tell, it's always been optional for an NFSv3 server
> > to include pre- and post-op attributes in wcc_data. Both the
> > pre_op_attr and post_op_attr XDR types start with an
> > "attribute_follows" discriminator. Therefore clients cannot rely on
> > receiving those attributes.
> > 
> > The patch description says that "Commit bb4d53d66e4b broke the NFSv3
> >                                                      ^^^^^
> > pre/post op attributes ...". And I think you also used the word
> > "nasty" in an earlier email. So what is broken if the server /never/
> > returns those attributes? What are the application-visible effects
> > of the server behavior change in bb4d53d66e4b ?
> > 
> > I don't have a problem reverting that part of bb4d53d66e4b, but
> > "broke" is doing some heavy lifting here. I want to understand why
> > we need to revert. Because it seems to me the server's current NFSv3
> > SETATTR implementation is spec-compliant. As far as I can tell,
> > bb4d53d66e4b might result in a little more network traffic in some
> > cases, but it won't impact interoperability or outcome.
> > 
> 
> As I said above, you broke the NFSv3 client's ability to determine
> whether or not the SETATTR was a failure, success or a partial success.
> That's not heavy lifting, it is a fact.
> 
> The function nfsd_setattr() uses two different calls to notify_change()
> in order to perform its function. Either one of them can return an
> error. Either one of them can fail, and the way that the client finds
> out whether or not the operation was a partial success is by examining
> the pre/post op attributes (NFSv3) or the returned bitmap (NFSv4).
> 
> The patch does not try to fix NFSv4, since AFAICS, that code has always
> been broken.
> 

Ugh, yeah we can definitely do a better job there.

> However, the NFSv3 code was not broken prior to bb4d53d66e4b. It was
> correctly returning pre/post op attributes that reflected the
> success/failure of the setattr operation. That is therefore a
> regression.
> Furthermore, it is a totally unnecessary regression. The whole point of
> SETATTR is to change the value of the attributes of the exact same file
> for which the pre/post op attributes are being retrieved. There is no
> extra disk access required to retrieve those attributes, nor should
> there be any other overhead other than copying them into the buffer.
> 
> > Do you mean that you want to restore the previous, more optimized,
> > server behavior to return pre- and post-op attributes when they are
> > available? And if so, what is the application-visible benefit?
> 
> Application correctness: the ability to see that your file got
> truncated despite the RPC call returning an error.
> 

So for instance: a v3 client sends a SETATTR with a size and mode change
in the same op. The size change works, but the mode change doesn't for
some reason.

The server returns an error, as expected, but without the pre/post op
attrs, the v3 client could just assume that _nothing_ worked and not
notice the size change. Alternately, I guess the client could invalidate
the attrcache after any SETATTR error, but that's sub-optimal.

The fix looks reasonable to me:

Reviewed-by: Jeff Layton <jlayton@kernel.org>
NeilBrown Feb. 18, 2024, 9:57 p.m. UTC | #9
On Fri, 16 Feb 2024, trondmy@kernel.org wrote:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes behaviour
> when doing a SETATTR rpc call by stripping out the calls to
> fh_fill_pre_attrs() and fh_fill_post_attrs().
> 
> Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of fh_(un)lock for file operations")
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  fs/nfsd/nfs4proc.c | 4 ++++
>  fs/nfsd/vfs.c      | 9 +++++++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 14712fa08f76..e6d8624efc83 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>  	};
>  	struct inode *inode;
>  	__be32 status = nfs_ok;
> +	bool save_no_wcc;
>  	int err;
>  
>  	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
> @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>  
>  	if (status)
>  		goto out;
> +	save_no_wcc = cstate->current_fh.fh_no_wcc;
> +	cstate->current_fh.fh_no_wcc = true;
>  	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
>  				0, (time64_t)0);
> +	cstate->current_fh.fh_no_wcc = save_no_wcc;

This looks clumsy.
I think the background is that NFSv3 needs atomic wcc attributes for
file operations, but NFSv4 doesn't - it only has them for directory ops.
So NFSv4, like NFSv2, doesn't want fh_fill_pre_attrs() to be called by
nfsd_setattr().

NFSv2 avoids it by always setting ->fh_no_wcc.  Here you temporarily set
fh_no_wcc to true for the same effect.  So the code is correct.
But it is not obvious to the casual reader why this is happening.

I would rather a "wcc_wanted" flag or similar, but that can be done in a
separate clean-up patch later.

Thanks for finding and fixing this regression of mine.

Reviewed-by: NeilBrown <neilb@suse.de>

NeilBrown



>  	if (!status)
>  		status = nfserrno(attrs.na_labelerr);
>  	if (!status)
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 6e7e37192461..58fab461bc00 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  	int		accmode = NFSD_MAY_SATTR;
>  	umode_t		ftype = 0;
>  	__be32		err;
> -	int		host_err;
> +	int		host_err = 0;
>  	bool		get_write_count;
>  	bool		size_change = (iap->ia_valid & ATTR_SIZE);
>  	int		retries;
> @@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  	}
>  
>  	inode_lock(inode);
> +	err = fh_fill_pre_attrs(fhp);
> +	if (err)
> +		goto out_unlock;
>  	for (retries = 1;;) {
>  		struct iattr attrs;
>  
> @@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
>  		attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
>  						dentry, ACL_TYPE_DEFAULT,
>  						attr->na_dpacl);
> +	fh_fill_post_attrs(fhp);
> +out_unlock:
>  	inode_unlock(inode);
>  	if (size_change)
>  		put_write_access(inode);
>  out:
>  	if (!host_err)
>  		host_err = commit_metadata(fhp);
> -	return nfserrno(host_err);
> +	return err != 0 ? err : nfserrno(host_err);
>  }
>  
>  #if defined(CONFIG_NFSD_V4)
> -- 
> 2.43.1
> 
> 
>
Trond Myklebust Feb. 19, 2024, 1:33 a.m. UTC | #10
On Mon, 2024-02-19 at 08:57 +1100, NeilBrown wrote:
> On Fri, 16 Feb 2024, trondmy@kernel.org wrote:
> > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> > 
> > Commit bb4d53d66e4b broke the NFSv3 pre/post op attributes
> > behaviour
> > when doing a SETATTR rpc call by stripping out the calls to
> > fh_fill_pre_attrs() and fh_fill_post_attrs().
> > 
> > Fixes: bb4d53d66e4b ("NFSD: use (un)lock_inode instead of
> > fh_(un)lock for file operations")
> > Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> > ---
> >  fs/nfsd/nfs4proc.c | 4 ++++
> >  fs/nfsd/vfs.c      | 9 +++++++--
> >  2 files changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> > index 14712fa08f76..e6d8624efc83 100644
> > --- a/fs/nfsd/nfs4proc.c
> > +++ b/fs/nfsd/nfs4proc.c
> > @@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
> > nfsd4_compound_state *cstate,
> >  	};
> >  	struct inode *inode;
> >  	__be32 status = nfs_ok;
> > +	bool save_no_wcc;
> >  	int err;
> >  
> >  	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
> > @@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct
> > nfsd4_compound_state *cstate,
> >  
> >  	if (status)
> >  		goto out;
> > +	save_no_wcc = cstate->current_fh.fh_no_wcc;
> > +	cstate->current_fh.fh_no_wcc = true;
> >  	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
> >  				0, (time64_t)0);
> > +	cstate->current_fh.fh_no_wcc = save_no_wcc;
> 
> This looks clumsy.
> I think the background is that NFSv3 needs atomic wcc attributes for
> file operations, but NFSv4 doesn't - it only has them for directory
> ops.
> So NFSv4, like NFSv2, doesn't want fh_fill_pre_attrs() to be called
> by
> nfsd_setattr().
> 
> NFSv2 avoids it by always setting ->fh_no_wcc.  Here you temporarily
> set
> fh_no_wcc to true for the same effect.  So the code is correct.
> But it is not obvious to the casual reader why this is happening.
> 
> I would rather a "wcc_wanted" flag or similar, but that can be done
> in a
> separate clean-up patch later.

That is in theory what the fh_no_wcc flag is for, however the issue is
that it got overloaded to also mean 'change_info4 wanted' when we added
support for NFSv4 to knfsd.
NFSv4 does not have a concept of weak cache consistency, but it does
try to track updates to the change attribute atomically (ideally) for
most operations that change the directory contents.

IOW: I think a better clean up would be to separate out 'wcc' and
'change_info4' as representing different functionality.
diff mbox series

Patch

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 14712fa08f76..e6d8624efc83 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1143,6 +1143,7 @@  nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	};
 	struct inode *inode;
 	__be32 status = nfs_ok;
+	bool save_no_wcc;
 	int err;
 
 	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
@@ -1168,8 +1169,11 @@  nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
 	if (status)
 		goto out;
+	save_no_wcc = cstate->current_fh.fh_no_wcc;
+	cstate->current_fh.fh_no_wcc = true;
 	status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs,
 				0, (time64_t)0);
+	cstate->current_fh.fh_no_wcc = save_no_wcc;
 	if (!status)
 		status = nfserrno(attrs.na_labelerr);
 	if (!status)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 6e7e37192461..58fab461bc00 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -497,7 +497,7 @@  nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	int		accmode = NFSD_MAY_SATTR;
 	umode_t		ftype = 0;
 	__be32		err;
-	int		host_err;
+	int		host_err = 0;
 	bool		get_write_count;
 	bool		size_change = (iap->ia_valid & ATTR_SIZE);
 	int		retries;
@@ -555,6 +555,9 @@  nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	}
 
 	inode_lock(inode);
+	err = fh_fill_pre_attrs(fhp);
+	if (err)
+		goto out_unlock;
 	for (retries = 1;;) {
 		struct iattr attrs;
 
@@ -582,13 +585,15 @@  nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		attr->na_aclerr = set_posix_acl(&nop_mnt_idmap,
 						dentry, ACL_TYPE_DEFAULT,
 						attr->na_dpacl);
+	fh_fill_post_attrs(fhp);
+out_unlock:
 	inode_unlock(inode);
 	if (size_change)
 		put_write_access(inode);
 out:
 	if (!host_err)
 		host_err = commit_metadata(fhp);
-	return nfserrno(host_err);
+	return err != 0 ? err : nfserrno(host_err);
 }
 
 #if defined(CONFIG_NFSD_V4)