Fix NFSv3 SETATTR behaviours
Subsystems (2)
[email protected]
maintainerv2 cover Fix NFSv3 SETATTR behaviours
From: Trond Myklebust <[email protected]>
Fix recent regressions in nfsd_setattr(), and fix the "guarded SETATTR" behaviour for NFSv3.
Trond Myklebust (2):
nfsd: Fix a regression in nfsd_setattr()
nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 7 +++++-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 29 ++++++++++++++++++++--------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.1
[email protected]
maintainerPATCH v2 1/2 nfsd: Fix a regression in nfsd_setattr()
From: Trond Myklebust <[email protected]>
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().
--- fs/nfsd/nfs4proc.c | 4 ++++ fs/nfsd/vfs.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +4 -0
@@ -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)
fs/nfsd/vfs.c +7 -2
@@ -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 )
Signature · 1 line
2.43.1
[email protected]
maintainerPATCH v2 2/2 nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
From: Trond Myklebust <[email protected]>
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)
fs/nfsd/nfs3proc.c +4 -2
@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }
fs/nfsd/nfs3xdr.c +1 -4
@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;
fs/nfsd/nfs4proc.c +1 -2
@@ -1171,8 +1171,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 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 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);
fs/nfsd/nfs4state.c +1 -1
@@ -5191,7 +5191,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
fs/nfsd/nfsproc.c +3 -3
@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;
@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:
fs/nfsd/vfs.c +13 -7
@@ -476,7 +476,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this
@@ -488,8 +487,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;
@@ -538,9 +536,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with
@@ -558,6 +553,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;
@@ -585,6 +590,7 @@ 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); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);
@@ -1409,7 +1415,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));
fs/nfsd/vfs.h +1 -1
@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
fs/nfsd/xdr3.h +1 -1
@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {
Signature · 1 line
2.43.1
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
In reply to [email protected]Quoted 5 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().
Can you give more detail about what broke?
Quoted 75 lines
Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead of fh_(un)lock for file operations")Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfs4proc.c | 4 ++++ fs/nfsd/vfs.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +4
-0@@ -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)fs/nfsd/vfs.c +7
-2@@ -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 )Signature · 1 line
2.43.1
Signature · 1 line
Chuck Lever
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 9 lines · Chuck Lever
Quoted 6 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_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.
Quoted 85 lines
Quoted 84 lines
Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead offh_(un)lock for file operations")
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfsd/nfs4proc.c | 4 ++++
fs/nfsd/vfs.c | 9 +++++++--2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-0@@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, structnfsd4_compound_state *cstate, }; struct inode *inode; __be32 status = nfs_ok; +bool save_no_wcc; int err;
if (setattr->sa_iattr.ia_valid&ATTR_SIZE) {fs/nfsd/nfs4proc.c +0
-0@@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if (status)
goto out;fs/nfsd/nfs4proc.c +2
-0+ 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);fs/nfsd/nfs4proc.c +1
-0+ cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status)
status =nfserrno(attrs.na_labelerr); if (!status)fs/nfsd/vfs.c +1
-1@@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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;
fs/nfsd/vfs.c +0
-0@@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, }
inode_lock(inode);fs/nfsd/vfs.c +3
-0+ err =fh_fill_pre_attrs (fhp); +if (err) + goto out_unlock;for (retries = 1;;) {
struct iattr attrs;fs/nfsd/vfs.c +2
-0@@ -582,13 +585,15 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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);fs/nfsd/vfs.c +1
-1-return nfserrno (host_err); +return err !=0 ? err :nfserrno (host_err);}
#ifdefined(CONFIG_NFSD_V4)Signature · 1 line
2.43.1
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 13 lines · Trond Myklebust
Quoted 8 lines · Chuck Lever
Quoted 6 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().
Quoted 5 lines
Quoted 1 line
Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_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?
Quoted 77 lines
Quoted 77 lines
Quoted 77 lines
Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead offh_(un)lock for file operations")
Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfs4proc.c | 4 ++++ fs/nfsd/vfs.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-0@@ -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) {fs/nfsd/nfs4proc.c +3
-0@@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, structnfsd4_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)
fs/nfsd/vfs.c +1
-1@@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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;
fs/nfsd/vfs.c +6
-1@@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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); }
Quoted 11 lines
Quoted 6 lines
Quoted 5 lines
#if
defined(CONFIG_NFSD_V4)Signature · 1 line
2.43.1Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
--
Chuck Lever
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 17 lines · Chuck Lever III
Quoted 14 lines · Trond Myklebust
Quoted 8 lines · Chuck Lever
Quoted 6 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_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.
Quoted 84 lines
Quoted 84 lines
Quoted 83 lines
Quoted 82 lines
Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead offh_(un)lock for file operations")
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfsd/nfs4proc.c| 4 ++++fs/nfsd/vfs.c| 9 +++++++--2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-0@@ -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) {fs/nfsd/nfs4proc.c +3
-0@@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, structnfsd4_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)
fs/nfsd/vfs.c +1
-1@@ -497,7 +497,7 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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;
fs/nfsd/vfs.c +5
-0@@ -555,6 +555,9 @@ nfsd_setattr(struct svc_rqst *rqstp, structsvc_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);
- returnnfserrno(host_err);
+ return err != 0 ? err :nfserrno(host_err);
}#if
defined(CONFIG_NFSD_V4)Signature · 1 line
2.43.1
Quoted 8 lines
Quoted 4 lines
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]--
Chuck Lever
--
Chuck Lever
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 28 lines · Chuck Lever III
Quoted 28 lines
Quoted 20 lines · Chuck Lever III
On Feb 16, 2024, at 1:18 PM, Trond Myklebust
<[email protected]> wrote:Quoted 10 lines · Chuck Lever
Quoted 6 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_fill_post_attrs(), we
don't store any pre/post op attributes and we can't return any such
attributes to the NFSv3 client.
Quoted 5 lines
Quoted 1 line
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.
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 90 lines
Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead offh_(un)lock for file operations")
Signed-off-by: Trond Myklebust
<[email protected]>
---fs/nfsd/nfs4proc.c| 4 ++++
fs/nfsd/vfs.c | 9 +++++++--2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp,struct
nfsd4_compound_state*cstate,
};
struct inode *inode;
__be32 status =nfs_ok;
+ boolsave_no_wcc;
int err;if (
setattr->sa_iattr.ia_valid&ATTR_SIZE) {fs/nfsd/nfs4proc.c +0
-0@@ -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)fs/nfsd/vfs.c +0
-0@@ -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;
- inthost_err;
+ inthost_err= 0;
boolget_write_count;
boolsize_change= (iap->ia_valid&ATTR_SIZE);
int retries;fs/nfsd/vfs.c +0
-0@@ -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)
+ gotoout_unlock;
for (retries = 1;;) {
struct iattr attrs;fs/nfsd/vfs.c +0
-0@@ -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);
- returnnfserrno(host_err);
+ return err != 0 ? err :nfserrno(host_err);
}#if
defined(CONFIG_NFSD_V4)Signature · 1 line
2.43.1
Signature · 2 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 35 lines · Trond Myklebust
Quoted 28 lines · Chuck Lever III
Quoted 28 lines
Quoted 20 lines · Chuck Lever III
On Feb 16, 2024, at 1:18 PM, Trond Myklebust
<[email protected]> wrote:Quoted 10 lines · Chuck Lever
Quoted 6 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_fill_post_attrs(), we
don't store any pre/post op attributes and we can't return any such
attributes to the NFSv3 client.Quoted 5 lines
Quoted 1 line
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.
Quoted 8 lines
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 returnsNFS3ERR_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?
Signature · 1 line
Chuck Lever
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 68 lines · Chuck Lever
Quoted 38 lines · Trond Myklebust
Quoted 31 lines · Chuck Lever III
Quoted 31 lines
Quoted 23 lines · Chuck Lever III
On Feb 16, 2024, at 1:18 PM, Trond Myklebust
<[email protected]> wrote:Quoted 4 lines · Chuck Lever
Quoted 2 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Quoted 8 lines
Quoted 6 lines
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes
behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_fill_post_attrs(), we
don't store any pre/post op attributes and we can't return any
such
attributes to the NFSv3 client.Quoted 5 lines
Quoted 1 line
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.
Quoted 12 lines
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 returnsNFS3ERR_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 thepre_op_attrandpost_op_attrXDR types start with an "attribute_follows" discriminator. Therefore clients cannot rely on receiving those attributes.The patch description says that "Commit
bb4d53d66e4bbroke 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 inbb4d53d66e4b?
Quoted 7 lines
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,bb4d53d66e4bmight 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.
Quoted 3 lines
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.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
Quoted 81 lines · Trond Myklebust
Quoted 68 lines · Chuck Lever
Quoted 38 lines · Trond Myklebust
Quoted 31 lines · Chuck Lever III
Quoted 31 lines
Quoted 23 lines · Chuck Lever III
On Feb 16, 2024, at 1:18 PM, Trond Myklebust
<[email protected]> wrote:Quoted 4 lines · Chuck Lever
Quoted 2 lines · On Thu, Feb 15, 2024 at 08:24:50PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Quoted 8 lines
Quoted 6 lines
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes
behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Can you give more detail about what broke?
Without the calls to
fh_fill_pre_attrs()andfh_fill_post_attrs(), we
don't store any pre/post op attributes and we can't return any
such
attributes to the NFSv3 client.Quoted 5 lines
Quoted 1 line
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.
Quoted 12 lines
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 returnsNFS3ERR_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 thepre_op_attrandpost_op_attrXDR types start with an "attribute_follows" discriminator. Therefore clients cannot rely on receiving those attributes.The patch description says that "Commit
bb4d53d66e4bbroke 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 inbb4d53d66e4b?Quoted 7 lines
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,bb4d53d66e4bmight 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.
Quoted 9 lines
The function
nfsd_setattr()uses two different calls tonotify_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.
Quoted 10 lines
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.
Quoted 7 lines
Quoted 3 lines
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:
Re: [PATCH v2 2/2] nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
In reply to [email protected]Quoted 202 lines · On Thu, 2024-02-15 at 20:24 -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)fs/nfsd/nfs3proc.c +4
-2@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }fs/nfsd/nfs3xdr.c +1
-4@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;fs/nfsd/nfs4proc.c +1
-2@@ -1171,8 +1171,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 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 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);fs/nfsd/nfs4state.c +1
-1@@ -5191,7 +5191,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,fs/nfsd/nfsproc.c +3
-3@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:fs/nfsd/vfs.c +13
-7@@ -476,7 +476,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this @@ -488,8 +487,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;@@ -538,9 +536,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with @@ -558,6 +553,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;@@ -585,6 +590,7 @@ 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); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);@@ -1409,7 +1415,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));fs/nfsd/vfs.h +1
-1@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,fs/nfsd/xdr3.h +0
-0
fs/nfsd/xdr3.h struct nfsd3_sattrargs { · line 20
Quoted 8 lines
fs/nfsd/xdr3.h +1
-1@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {
I thought I sent this the other day, but...
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
In reply to [email protected]Quoted 26 lines · On Fri, 16 Feb 2024, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead of fh_(un)lock for file operations")Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfs4proc.c | 4 ++++ fs/nfsd/vfs.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-0@@ -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 ) {
fs/nfsd/nfs4proc.c nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1176
Quoted 8 lines
fs/nfsd/nfs4proc.c +3
-0@@ -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.
NeilBrown
Quoted 48 lines
fs/nfsd/nfs4proc.c +0
-0if (!status) status =nfserrno (attrs.na_labelerr);if (!status)fs/nfsd/vfs.c +7
-2@@ -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 )Signature · 1 line
2.43.1
Re: [PATCH v2 2/2] nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr()
In reply to [email protected]Quoted 215 lines · On Fri, 16 Feb 2024, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The main point of the guarded SETATTR is to prevent races with other WRITE and SETATTR calls. That requires that the check of the guard time against the inode ctime be done after taking the inode lock.
Furthermore, we need to take into account the 32-bit nature of timestamps in NFSv3, and the possibility that files may change at a faster rate than once a second.
Signed-off-by Trond Myklebust <[email protected]>--- fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 3 +-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 20 +++++++++++++------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-)fs/nfsd/nfs3proc.c +4
-2@@ -71,13 +71,15 @@ nfsd3_proc_setattr(struct svc_rqst *rqstp)struct nfsd_attrs attrs = { .na_iattr = &argp->attrs, }; +const struct timespec64 *guardtime =NULL ;dprintk ("nfsd: SETATTR(3) %s\n" ,SVCFH_fmt (&argp->fh));fh_copy (&resp->fh, &argp->fh); - resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, - argp->check_guard, argp->guardtime); +if (argp->check_guard) + guardtime = &argp->guardtime; + resp->status =nfsd_setattr (rqstp, &resp->fh, &attrs, guardtime);return rpc_success; }fs/nfsd/nfs3xdr.c +1
-4@@ -295,17 +295,14 @@ svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,static bool svcxdr_decode_sattrguard3 (struct xdr_stream *xdr,struct nfsd3_sattrargs *args) { -__be32 *p;u32 check;if (xdr_stream_decode_bool (xdr, &check) <0 )return false;if (check) { - p =xdr_inline_decode (xdr,XDR_UNIT *2 ); -if (!p) +if (!svcxdr_decode_nfstime3 (xdr, &args->guardtime))return false; args->check_guard =1 ; - args->guardtime =be32_to_cpup (p); }else args->check_guard =0 ;fs/nfsd/nfs4proc.c +1
-2@@ -1171,8 +1171,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 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 ); + status =nfsd_setattr (rqstp, &cstate->current_fh, &attrs,NULL ); cstate->current_fh.fh_no_wcc = save_no_wcc;if (!status) status =nfserrno (attrs.na_labelerr);fs/nfsd/nfs4state.c +1
-1@@ -5191,7 +5191,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return 0 ;if (!(open->op_share_access &NFS4_SHARE_ACCESS_WRITE ))return nfserr_inval; -return nfsd_setattr (rqstp, fh, &attrs,0 , (time64_t )0 ); +return nfsd_setattr (rqstp, fh, &attrs,NULL ); } static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,fs/nfsd/nfsproc.c +3
-3@@ -103,7 +103,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp) } } - resp->status =nfsd_setattr (rqstp, fhp, &attrs,0 , (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, fhp, &attrs,NULL );if (resp->status != nfs_ok) goto out;@@ -390,8 +390,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)*/ attr->ia_valid &=ATTR_SIZE ;if (attr->ia_valid) - resp->status =nfsd_setattr (rqstp, newfhp, &attrs,0 , - (time64_t )0 ); + resp->status =nfsd_setattr (rqstp, newfhp, &attrs, +NULL ); } out_unlock:fs/nfsd/vfs.c +13
-7@@ -476,7 +476,6 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)* @rqstp: controlling RPC transaction * @fhp: filehandle of target * @attr: attributes to set -* @check_guard: set to 1 if guardtime is a valid timestamp * @guardtime: do not act if ctime.tv_sec does not match this timestamp * * This call may adjust the contents of @attr (in particular, this @@ -488,8 +487,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)*/ __be32 nfsd_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct nfsd_attrs *attr, -int check_guard,time64_t guardtime) +struct nfsd_attrs *attr,const struct timespec64 *guardtime) {struct dentry *dentry;struct inode *inode;@@ -538,9 +536,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,nfsd_sanitize_attrs (inode, iap); -if (check_guard && guardtime !=inode_get_ctime_sec (inode)) -return nfserr_notsync; -/* * The size case is special, it changes the file in addition to the * attributes, and file systems don't expect it to be mixed with @@ -558,6 +553,16 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, err =fh_fill_pre_attrs (fhp);if (err) goto out_unlock; + +if (guardtime) { +struct timespec64 ctime =inode_get_ctime (inode); +if ((u32 )guardtime->tv_sec != (u32 )ctime.tv_sec || + guardtime->tv_nsec != ctime.tv_nsec) { + err = nfserr_notsync; + goto out_fill_attrs; + } + } +for (retries =1 ;;) {struct iattr attrs;@@ -585,6 +590,7 @@ 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); +out_fill_attrs:fh_fill_post_attrs (fhp); out_unlock:inode_unlock (inode);@@ -1409,7 +1415,7 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,* if the attributes have not changed. */ if (iap->ia_valid) - status =nfsd_setattr (rqstp, resfhp, attrs,0 , (time64_t )0 ); + status =nfsd_setattr (rqstp, resfhp, attrs,NULL );else status =nfserrno (commit_metadata (resfhp));fs/nfsd/vfs.h +1
-1@@ -69,7 +69,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, const char *, unsigned int, struct svc_export **, struct dentry **);__be32 nfsd_setattr (struct svc_rqst *,struct svc_fh *, -struct nfsd_attrs *,int ,time64_t ); +struct nfsd_attrs *,const struct timespec64 *);int nfsd_mountpoint (struct dentry *,struct svc_export *);#ifdef CONFIG_NFSD_V4 __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,fs/nfsd/xdr3.h +1
-1@@ -14,7 +14,7 @@ struct nfsd3_sattrargs {struct svc_fh fh;struct iattr attrs;int check_guard; -time64_t guardtime; +struct timespec64 guardtime; };struct nfsd3_diropargs {Signature · 1 line
2.43.1
Nice cleanup was well as the bug fix - thanks,
NeilBrown
Re: [PATCH v2 1/2] nfsd: Fix a regression in nfsd_setattr()
In reply to NeilBrownQuoted 48 lines · NeilBrown
Quoted 37 lines · On Fri, 16 Feb 2024, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Commit
bb4d53d66e4bbroke the NFSv3 pre/post op attributes behaviour
when doing a SETATTR rpc call by stripping out the calls tofh_fill_pre_attrs()andfh_fill_post_attrs().Fixes bb4d53d66e4b ("NFSD: use (un)lock_inode instead offh_(un)lock for file operations")
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfsd/nfs4proc.c | 4 ++++
fs/nfsd/vfs.c | 9 +++++++--2 files changed, 11 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-0@@ -1143,6 +1143,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, structnfsd4_compound_state *cstate, }; struct inode *inode; __be32 status = nfs_ok; +bool save_no_wcc; int err;
if (setattr->sa_iattr.ia_valid&ATTR_SIZE) {fs/nfsd/nfs4proc.c +0
-0@@ -1168,8 +1169,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if (status)
goto out;fs/nfsd/nfs4proc.c +2
-0+ 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);fs/nfsd/nfs4proc.c nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 1176
Quoted 1 line
fs/nfsd/nfs4proc.c +1
-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 wantfh_fill_pre_attrs()to be called bynfsd_setattr().
Quoted 8 lines
NFSv2 avoids it by always setting ->fh_no_wcc. Here you temporarily set
fh_no_wccto 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.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 9 lines · On Thu, Feb 15, 2024 at 08:24:49PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Fix recent regressions in
nfsd_setattr(), and fix the "guarded SETATTR" behaviour for NFSv3.Trond Myklebust (2):
nfsd: Fix a regression innfsd_setattr()
nfsd: Fix NFSv3 atomicity bugs innfsd_setattr()
Quoted 13 lines
fs/nfsd/nfs3proc.c | 6 ++++-- fs/nfsd/nfs3xdr.c | 5 +---- fs/nfsd/nfs4proc.c | 7 +++++-- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsproc.c | 6 +++--- fs/nfsd/vfs.c | 29 ++++++++++++++++++++--------- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-)Signature · 1 line
2.43.1
Both applied to nfsd-next. Thanks gents!
Signature · 1 line
Chuck Lever