nfsd/vfs: fix handling of delegated timestamp updates
Subsystems (4)
Jeff Layton
maintainerv4 cover nfsd/vfs: fix handling of delegated timestamp updates
This patchset fixes the handling of delegated timestamps in nfsd. This one also adopts Neil's suggestopn to use FMODE_NOCMTIME to freeze timestamp updates while there is a WRITE_ATTRS delegation outstanding.
Most of these patches are identical to the last set. I dropped the patch that removes inode_set_ctime_deleg(), and reworked the logic in setattr_copy() and friends to accomodate.
The last patch in the series is new. That one adds FMODE_NOCMTIME to the file while a WRITE_ATTRS delegation is in force, and adds a mechanism to ensure that the timestamps gets updated appropriately if the client never sends a SETATTR with updated timestamps in it. That should ensure that the ctime never rolls backward.
This patchset also leaves inode_set_ctime_deleg() in place. That's probably overengineered if we don't need to worry about ctime updates from the client racing with ctime updates due to writes anymore, but we can simplify it later if so.
The series passes the gitr testsuite in the "stress" configuration.
---
Changes in v4:
- Use FMODE_NOCMTIME to freeze timestamp updates on write
- drop patch that removes inode_set_ctime_deleg()
- rework logic in setattr_copy()
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- split out decoder fix into separate patch
- add Fixes: tags
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- add ATTR_CTIME_SET and remove inode_set_ctime_deleg()
- track original timestamps in struct nfs4_delegation
- fix delegated timestamp updates to respect saved timestamps
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (8):
nfsd: fix assignment of ia_ctime.tv_nsec on delegated mtime update
nfsd: ignore ATTR_DELEG when checking ia_valid before notify_change()
vfs: add ATTR_CTIME_SET flag
nfsd: use ATTR_CTIME_SET for delegated ctime updates
nfsd: track original timestamps in nfs4_delegation
nfsd: fix SETATTR updates for delegated timestamps
nfsd: fix timestamp updates in CB_GETATTR
nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
fs/attr.c | 44 ++++++++++++--------------- fs/nfsd/nfs4proc.c | 55 ++++++++++++++++++++++++++++++++-- fs/nfsd/nfs4state.c | 86 ++++++++++++++++++++++++++++++++++++++++------------- fs/nfsd/nfs4xdr.c | 5 ++-- fs/nfsd/state.h | 12 +++++++- fs/nfsd/vfs.c | 2 +- include/linux/fs.h | 1 + 7 files changed, 153 insertions(+), 52 deletions(-)
---
base-commit: b05f077b59098b4760e3f675b00a4e6a1ad4b0ad
change-id: 20250722-nfsd-testing-5e861a3cf3a0
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v4 1/8 nfsd: fix assignment of ia_ctime.tv_nsec on delegated mtime update
The ia_ctime.tv_nsec field should be set to modify.nseconds.
--- fs/nfsd/nfs4xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +1 -1
@@ -538,7 +538,7 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, iattr->ia_mtime.tv_sec = modify.seconds; iattr->ia_mtime.tv_nsec = modify.nseconds; iattr->ia_ctime.tv_sec = modify.seconds; - iattr->ia_ctime.tv_nsec = modify.seconds; + iattr->ia_ctime.tv_nsec = modify.nseconds; iattr->ia_valid |=ATTR_CTIME |ATTR_MTIME |ATTR_MTIME_SET |ATTR_DELEG ; }
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 2/8 nfsd: ignore ATTR_DELEG when checking ia_valid before notify_change()
In reply to Jeff LaytonIf the only flag left is ATTR_DELEG, then there are no changes to be made.
--- fs/nfsd/vfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/vfs.c +1 -1
@@ -467,7 +467,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)return 0 ; } -if (!iap->ia_valid) +if ((iap->ia_valid & ~ATTR_DELEG ) ==0 )return 0 ;/*
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 3/8 vfs: add ATTR_CTIME_SET flag
In reply to Jeff LaytonWhen ATTR_ATIME_SET and ATTR_MTIME_SET are set in the ia_valid mask, the notify_change() logic takes that to mean that the request should set those values explicitly, and not override them with "now".
With the advent of delegated timestamps, similar functionality is needed for the ctime. Add a ATTR_CTIME_SET flag, and use that to indicate that the ctime should be accepted as-is. Also, clean up the if statements to eliminate the extra negatives.
In setattr_copy() and setattr_copy_mgtime() use inode_set_ctime_deleg() when ATTR_CTIME_SET is set, instead of basing the decision on ATTR_DELEG.
--- fs/attr.c | 44 +++++++++++++++++++------------------------- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 25 deletions(-)
fs/attr.c +19 -25
@@ -286,20 +286,12 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)unsigned int ia_valid = attr->ia_valid;struct timespec64 now; -if (ia_valid &ATTR_CTIME ) { -/* -* In the case of an update for a write delegation, we must respect -* the value in ia_ctime and not use the current time. -*/ -if (ia_valid &ATTR_DELEG ) - now =inode_set_ctime_deleg (inode, attr->ia_ctime); -else - now =inode_set_ctime_current (inode); - }else { -/* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */ -WARN_ON_ONCE (ia_valid &ATTR_MTIME ); +if (ia_valid &ATTR_CTIME_SET ) + now =inode_set_ctime_deleg (inode, attr->ia_ctime); +else if (ia_valid &ATTR_CTIME ) + now =inode_set_ctime_current (inode); +else now =current_time (inode); - }if (ia_valid &ATTR_ATIME_SET )inode_set_atime_to_ts (inode, attr->ia_atime);
@@ -359,12 +351,11 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode,inode_set_atime_to_ts (inode, attr->ia_atime);if (ia_valid &ATTR_MTIME )inode_set_mtime_to_ts (inode, attr->ia_mtime); -if (ia_valid &ATTR_CTIME ) { -if (ia_valid &ATTR_DELEG ) -inode_set_ctime_deleg (inode, attr->ia_ctime); -else -inode_set_ctime_to_ts (inode, attr->ia_ctime); - } + +if (ia_valid &ATTR_CTIME_SET ) +inode_set_ctime_deleg (inode, attr->ia_ctime); +else if (ia_valid &ATTR_CTIME ) +inode_set_ctime_to_ts (inode, attr->ia_ctime); }EXPORT_SYMBOL (setattr_copy);
@@ -463,15 +454,18 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry, now =current_time (inode); - attr->ia_ctime = now; -if (!(ia_valid &ATTR_ATIME_SET )) - attr->ia_atime = now; -else +if (ia_valid &ATTR_ATIME_SET ) attr->ia_atime =timestamp_truncate (attr->ia_atime, inode); -if (!(ia_valid &ATTR_MTIME_SET )) - attr->ia_mtime = now;else + attr->ia_atime = now; +if (ia_valid &ATTR_CTIME_SET ) + attr->ia_ctime =timestamp_truncate (attr->ia_ctime, inode); +else + attr->ia_ctime = now; +if (ia_valid &ATTR_MTIME_SET ) attr->ia_mtime =timestamp_truncate (attr->ia_mtime, inode); +else + attr->ia_mtime = now;if (ia_valid &ATTR_KILL_PRIV ) { error =security_inode_need_killpriv (dentry);
include/linux/fs.h +1 -0
@@ -237,6 +237,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define ATTR_ATIME_SET (1 << 7)#define ATTR_MTIME_SET (1 << 8)#define ATTR_FORCE (1 << 9)/* Not a change, but a change it */ +#define ATTR_CTIME_SET (1 << 10)#define ATTR_KILL_SUID (1 << 11)#define ATTR_KILL_SGID (1 << 12)#define ATTR_FILE (1 << 13)
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 4/8 nfsd: use ATTR_CTIME_SET for delegated ctime updates
In reply to Jeff LaytonEnsure that notify_change() doesn't clobber a delegated ctime update with current_time() by setting ATTR_CTIME_SET for those updates.
Don't bother setting the timestamps in cb_getattr_update_times() in the non-delegated case. notify_change() will do that itself.
--- fs/nfsd/nfs4state.c | 6 +++--- fs/nfsd/nfs4xdr.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +3 -3
@@ -9167,7 +9167,6 @@ static bool set_cb_time(struct timespec64 *cb, const struct timespec64 *orig,static int cb_getattr_update_times (struct dentry *dentry,struct nfs4_delegation *dp) {struct inode *inode =d_inode (dentry); -struct timespec64 now =current_time (inode);struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr;struct iattr attrs = { };int ret;
@@ -9175,6 +9174,7 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegationif (deleg_attrs_deleg (dp->dl_type)) {struct timespec64 atime =inode_get_atime (inode);struct timespec64 mtime =inode_get_mtime (inode); +struct timespec64 now =current_time (inode); attrs.ia_atime = ncf->ncf_cb_atime; attrs.ia_mtime = ncf->ncf_cb_mtime;
@@ -9183,12 +9183,12 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation attrs.ia_valid |=ATTR_ATIME |ATTR_ATIME_SET ;if (set_cb_time (&attrs.ia_mtime, &mtime, &now)) { - attrs.ia_valid |=ATTR_CTIME |ATTR_MTIME |ATTR_MTIME_SET ; + attrs.ia_valid |=ATTR_CTIME |ATTR_CTIME_SET | +ATTR_MTIME |ATTR_MTIME_SET ; attrs.ia_ctime = attrs.ia_mtime; } }else { attrs.ia_valid |=ATTR_MTIME |ATTR_CTIME ; - attrs.ia_mtime = attrs.ia_ctime = now; }if (!attrs.ia_valid)
fs/nfsd/nfs4xdr.c +2 -1
@@ -539,7 +539,8 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, iattr->ia_mtime.tv_nsec = modify.nseconds; iattr->ia_ctime.tv_sec = modify.seconds; iattr->ia_ctime.tv_nsec = modify.nseconds; - iattr->ia_valid |=ATTR_CTIME |ATTR_MTIME |ATTR_MTIME_SET |ATTR_DELEG ; + iattr->ia_valid |=ATTR_CTIME |ATTR_CTIME_SET | +ATTR_MTIME |ATTR_MTIME_SET |ATTR_DELEG ; }/* request sanity: did attrlist4 contain the expected number of words? */
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 5/8 nfsd: track original timestamps in nfs4_delegation
In reply to Jeff LaytonAs Trond points out [1], the "original time" mentioned in RFC 9754 refers to the timestamps on the files at the time that the delegation was granted, and not the current timestamp of the file on the server.
Store the current timestamps for the file in the nfs4_delegation when granting one. Add STATX_ATIME and STATX_MTIME to the request mask in nfs4_delegation_stat(). When granting OPEN_DELEGATE_READ_ATTRS_DELEG, do a nfs4_delegation_stat() and save the correct atime. If the stat() fails for any reason, fall back to granting a normal read deleg.
[1]: https://lore.kernel.org/linux-nfs/[email protected]/
--- fs/nfsd/nfs4state.c | 11 ++++++++--- fs/nfsd/state.h | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +8 -3
@@ -6157,7 +6157,8 @@ nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh, path.dentry =file_dentry (nf->nf_file); rc =vfs_getattr (&path, stat, - (STATX_MODE |STATX_SIZE |STATX_CTIME |STATX_CHANGE_COOKIE ), +STATX_MODE |STATX_SIZE |STATX_ATIME | +STATX_MTIME |STATX_CTIME |STATX_CHANGE_COOKIE ,AT_STATX_SYNC_AS_STAT );nfsd_file_put (nf);
@@ -6274,10 +6275,14 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,OPEN_DELEGATE_WRITE ; dp->dl_cb_fattr.ncf_cur_fsize = stat.size; dp->dl_cb_fattr.ncf_initial_cinfo =nfsd4_change_attribute (&stat); + dp->dl_atime = stat.atime; + dp->dl_ctime = stat.ctime; + dp->dl_mtime = stat.mtime;trace_nfsd_deleg_write (&dp->dl_stid.sc_stateid); }else { - open->op_delegate_type = deleg_ts ?OPEN_DELEGATE_READ_ATTRS_DELEG : -OPEN_DELEGATE_READ ; + open->op_delegate_type = deleg_ts &&nfs4_delegation_stat (dp, currentfh, &stat) ? +OPEN_DELEGATE_READ_ATTRS_DELEG :OPEN_DELEGATE_READ ; + dp->dl_atime = stat.atime;trace_nfsd_deleg_read (&dp->dl_stid.sc_stateid); }nfs4_put_stid (&dp->dl_stid);
fs/nfsd/state.h +5 -0
@@ -224,6 +224,11 @@ struct nfs4_delegation {/* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr; + +/* For delegated timestamps */ +struct timespec64 dl_atime; +struct timespec64 dl_mtime; +struct timespec64 dl_ctime; };static inline bool deleg_is_read (u32 dl_type)
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 6/8 nfsd: fix SETATTR updates for delegated timestamps
In reply to Jeff LaytonSETATTRs containing delegated timestamp updates are currently not being vetted properly. Since we no longer need to compare the timestamps vs. the current timestamps, move the vetting of delegated timestamps wholly into nfsd.
Rename the set_cb_time() helper to nfsd4_vet_deleg_time(), and make it non-static. Add a new vet_deleg_attrs() helper that is called from nfsd4_setattr that uses nfsd4_vet_deleg_time() to properly validate the all the timestamps. If the validation indicates that the update should be skipped, unset the appropriate flags in ia_valid.
--- fs/nfsd/nfs4proc.c | 31 ++++++++++++++++++++++++++++++- fs/nfsd/nfs4state.c | 24 +++++++++++------------- fs/nfsd/state.h | 3 +++ 3 files changed, 44 insertions(+), 14 deletions(-)
fs/nfsd/nfs4proc.c +30 -1
@@ -1133,6 +1133,33 @@ nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)exp_put (u->secinfo_no_name.sin_exp); } +/* +* Validate that the requested timestamps are within the acceptable range. If +* timestamp appears to be in the future, then it will be clamped to +* current_time(). +*/ +static void +vet_deleg_attrs (struct nfsd4_setattr *setattr,struct nfs4_delegation *dp) +{ +struct timespec64 now =current_time (dp->dl_stid.sc_file->fi_inode); +struct iattr *iattr = &setattr->sa_iattr; + +if ((setattr->sa_bmval[2 ] &FATTR4_WORD2_TIME_DELEG_ACCESS ) && + !nfsd4_vet_deleg_time (&iattr->ia_atime, &dp->dl_atime, &now)) + iattr->ia_valid &= ~(ATTR_ATIME |ATTR_ATIME_SET ); + +if (setattr->sa_bmval[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY ) { +if (nfsd4_vet_deleg_time (&iattr->ia_mtime, &dp->dl_mtime, &now)) { + iattr->ia_ctime = iattr->ia_mtime; +if (!nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) + iattr->ia_valid &= ~(ATTR_CTIME |ATTR_CTIME_SET ); + }else { + iattr->ia_valid &= ~(ATTR_CTIME |ATTR_CTIME_SET | +ATTR_MTIME |ATTR_MTIME_SET ); + } + } +} +static __be32 nfsd4_setattr (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)
@@ -1170,8 +1197,10 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfs4_delegation *dp =delegstateid (st);/* Only for *_ATTRS_DELEG flavors */ -if (deleg_attrs_deleg (dp->dl_type)) +if (deleg_attrs_deleg (dp->dl_type)) { +vet_deleg_attrs (setattr, dp); status = nfs_ok; + } } }if (st)
fs/nfsd/nfs4state.c +11 -13
@@ -9135,25 +9135,25 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate, }/** -* set_cb_time - vet and set the timespec for a cb_getattr update -* @cb: timestamp from the CB_GETATTR response +* nfsd4_vet_deleg_time - vet and set the timespec for a delegated timestamp update +* @req: timestamp from the client * @orig: original timestamp in the inode * @now: current time * -* Given a timestamp in a CB_GETATTR response, check it against the +* Given a timestamp from the client response, check it against the * current timestamp in the inode and the current time. Returns true * if the inode's timestamp needs to be updated, and false otherwise. -* @cb may also be changed if the timestamp needs to be clamped. +* @req may also be changed if the timestamp needs to be clamped. */ -static bool set_cb_time (struct timespec64 *cb,const struct timespec64 *orig, -const struct timespec64 *now) +bool nfsd4_vet_deleg_time (struct timespec64 *req,const struct timespec64 *orig, +const struct timespec64 *now) {/* * "When the time presented is before the original time, then the * update is ignored." Also no need to update if there is no change. */ -if (timespec64_compare (cb, orig) <=0 ) +if (timespec64_compare (req, orig) <=0 )return false;/*
@@ -9161,10 +9161,8 @@ static bool set_cb_time(struct timespec64 *cb, const struct timespec64 *orig,* clamp the new time to the current time, or it may * return NFS4ERR_DELAY to the client, allowing it to retry." */ -if (timespec64_compare (cb, now) >0 ) { -/* clamp it */ - *cb = *now; - } +if (timespec64_compare (req, now) >0 ) + *req = *now;return true; }
@@ -9184,10 +9182,10 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation attrs.ia_atime = ncf->ncf_cb_atime; attrs.ia_mtime = ncf->ncf_cb_mtime; -if (set_cb_time (&attrs.ia_atime, &atime, &now)) +if (nfsd4_vet_deleg_time (&attrs.ia_atime, &atime, &now)) attrs.ia_valid |=ATTR_ATIME |ATTR_ATIME_SET ; -if (set_cb_time (&attrs.ia_mtime, &mtime, &now)) { +if (nfsd4_vet_deleg_time (&attrs.ia_mtime, &mtime, &now)) { attrs.ia_valid |=ATTR_CTIME |ATTR_CTIME_SET |ATTR_MTIME |ATTR_MTIME_SET ; attrs.ia_ctime = attrs.ia_mtime;
fs/nfsd/state.h +3 -0
@@ -247,6 +247,9 @@ static inline bool deleg_attrs_deleg(u32 dl_type) dl_type ==OPEN_DELEGATE_WRITE_ATTRS_DELEG ; } +bool nfsd4_vet_deleg_time (struct timespec64 *cb,const struct timespec64 *orig, +const struct timespec64 *now); +#define cb_to_delegation (cb) \ container_of(cb, struct nfs4_delegation, dl_recall)
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 7/8 nfsd: fix timestamp updates in CB_GETATTR
In reply to Jeff LaytonWhen updating the local timestamps from CB_GETATTR, the updated values are not being properly vetted.
Compare the update times vs. the saved times in the delegation rather than the current times in the inode. Also, ensure that the ctime is properly vetted vs. its original value.
--- fs/nfsd/nfs4state.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/nfsd/nfs4state.c +5 -6
@@ -9175,20 +9175,19 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegationint ret;if (deleg_attrs_deleg (dp->dl_type)) { -struct timespec64 atime =inode_get_atime (inode); -struct timespec64 mtime =inode_get_mtime (inode);struct timespec64 now =current_time (inode); attrs.ia_atime = ncf->ncf_cb_atime; attrs.ia_mtime = ncf->ncf_cb_mtime; -if (nfsd4_vet_deleg_time (&attrs.ia_atime, &atime, &now)) +if (nfsd4_vet_deleg_time (&attrs.ia_atime, &dp->dl_atime, &now)) attrs.ia_valid |=ATTR_ATIME |ATTR_ATIME_SET ; -if (nfsd4_vet_deleg_time (&attrs.ia_mtime, &mtime, &now)) { - attrs.ia_valid |=ATTR_CTIME |ATTR_CTIME_SET | -ATTR_MTIME |ATTR_MTIME_SET ; +if (nfsd4_vet_deleg_time (&attrs.ia_mtime, &dp->dl_mtime, &now)) { + attrs.ia_valid |=ATTR_MTIME |ATTR_MTIME_SET ; attrs.ia_ctime = attrs.ia_mtime; +if (nfsd4_vet_deleg_time (&attrs.ia_ctime, &dp->dl_ctime, &now)) + attrs.ia_valid |=ATTR_CTIME |ATTR_CTIME_SET ; } }else { attrs.ia_valid |=ATTR_MTIME |ATTR_CTIME ;
Signature · 1 line
2.50.1
Jeff Layton
maintainerPATCH v4 8/8 nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
In reply to Jeff LaytonInstead of allowing the ctime to roll backward with a WRITE_ATTRS delegation, set FMODE_NOCMTIME on the file and have it skip mtime and ctime updates.
It is possible that the client will never send a SETATTR to set the times before returning the delegation. Add two new bools to struct nfs4_delegation:
dl_written: tracks whether the file has been written since the delegation was granted. This is set in the WRITE and LAYOUTCOMMIT handlers.
dl_setattr: tracks whether the client has sent at least one valid mtime that can also update the ctime in a SETATTR.
When unlocking the lease for the delegation, clear FMODE_NOCMTIME. If the file has been written, but no setattr for the delegated mtime and ctime has been done, update the timestamps to current_time().
--- fs/nfsd/nfs4proc.c | 26 ++++++++++++++++++++++++-- fs/nfsd/nfs4state.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/state.h | 4 +++- 3 files changed, 69 insertions(+), 3 deletions(-)
fs/nfsd/nfs4proc.c +24 -2
@@ -1151,7 +1151,9 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)if (setattr->sa_bmval[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY ) {if (nfsd4_vet_deleg_time (&iattr->ia_mtime, &dp->dl_mtime, &now)) { iattr->ia_ctime = iattr->ia_mtime; -if (!nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) +if (nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) + dp->dl_setattr = true; +else iattr->ia_valid &= ~(ATTR_CTIME |ATTR_CTIME_SET ); }else { iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |
@@ -1238,12 +1240,26 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return status; } +static void nfsd4_file_mark_deleg_written (struct nfs4_file *fi) +{ +spin_lock (&fi->fi_lock); +if (!list_empty (&fi->fi_delegations)) { +struct nfs4_delegation *dp =list_first_entry (&fi->fi_delegations, + struct nfs4_delegation, dl_perfile); + +if (dp->dl_type ==OPEN_DELEGATE_WRITE_ATTRS_DELEG ) + dp->dl_written = true; + } +spin_unlock (&fi->fi_lock); +} +static __be32 nfsd4_write (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u) {struct nfsd4_write *write = &u->write;stateid_t *stateid = &write->wr_stateid; +struct nfs4_stid *stid =NULL ;struct nfsd_file *nf =NULL ;__be32 status = nfs_ok;unsigned long cnt;
@@ -1256,10 +1272,15 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,trace_nfsd_write_start (rqstp, &cstate->current_fh, write->wr_offset, cnt); status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, - stateid,WR_STATE , &nf,NULL ); + stateid,WR_STATE , &nf, &stid);if (status)return status; +if (stid) { +nfsd4_file_mark_deleg_written (stid->sc_file); +nfs4_put_stid (stid); + } + write->wr_how_written = write->wr_stable_how; status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, &write->wr_payload,
@@ -2550,6 +2571,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,mutex_unlock (&ls->ls_mutex); nfserr = ops->proc_layoutcommit (inode, rqstp, lcp); +nfsd4_file_mark_deleg_written (ls->ls_stid.sc_file);nfs4_put_stid (&ls->ls_stid); out:return nfserr;
fs/nfsd/nfs4state.c +42 -0
66 lines not on this page · raw message
fs/nfsd/state.h +3 -1
@@ -217,10 +217,12 @@ struct nfs4_delegation {struct nfs4_clnt_odstate *dl_clnt_odstate;time64_t dl_time;u32 dl_type; -/* For recall: */ +/* For recall: */ int dl_retries;struct nfsd4_callback dl_recall;bool dl_recalled; +bool dl_written; +bool dl_setattr;/* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr;
Signature · 1 line
2.50.1
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 9 lines · Jeff Layton
This patchset fixes the handling of delegated timestamps in nfsd. This one also adopts Neil's suggestopn to use
FMODE_NOCMTIMEto freeze timestamp updates while there is aWRITE_ATTRSdelegation outstanding.Most of these patches are identical to the last set. I dropped the patch that removes
inode_set_ctime_deleg(), and reworked the logic insetattr_copy()and friends to accomodate.[...]
Applied v4 to nfsd-testing, thanks!
[1/8] nfsd: fix assignment of ia_ctime.tv_nsec on delegated mtime update
commit: 237f236e44701cffc5cd9e302d4fec172a954d2f
[2/8] nfsd: ignore ATTR_DELEG when checking ia_valid before notify_change()
commit: 30a594d856dc2fc89d3751b5d630cd55fceffd9a
[3/8] vfs: add ATTR_CTIME_SET flag
commit: 3076cf4693efc8596a1d1eee17a9bc9b5c4b197d
[4/8] nfsd: use ATTR_CTIME_SET for delegated ctime updates
commit: 12b1b09ddb932c2be8148758ebb5d93265293d18
[5/8] nfsd: track original timestamps in nfs4_delegation
commit: 2082ff203cad83a7d50478112b2089743f8fea43
[6/8] nfsd: fix SETATTR updates for delegated timestamps
commit: 90a615f4a2836bbaf91ac18c3157944655949368
[7/8] nfsd: fix timestamp updates in CB_GETATTR
commit: ba17826b25e921ebca04fc54a59336dad68302ac
[8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
commit: 278138d4f85df580edde73ad4d89b8aae75d0e77--
Chuck Lever
NeilBrown
reviewerRe: [PATCH v4 8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
In reply to Jeff LaytonQuoted 8 lines · Jeff Layton
Instead of allowing the ctime to roll backward with a
WRITE_ATTRSdelegation, setFMODE_NOCMTIMEon the file and have it skip mtime and ctime updates.It is possible that the client will never send a SETATTR to set the times before returning the delegation. Add two new bools to struct
nfs4_delegation:
Quoted 6 lines
dl_written: tracks whether the file has been written since the delegation was granted. This is set in the WRITE and LAYOUTCOMMIT handlers.
dl_setattr: tracks whether the client has sent at least one valid mtime that can also update the ctime in a SETATTR.
Do we really need both of these?
Could we set dl_written on a write and clear it on a setattr that sets mtime/ctime?
Then on close, if it is still set we force an mtime update.
I would be inclined to put this bit in ->f_mode setting it precisely when FMODE_NOCMTIME is uses to skip the update. (There are 4 spare fmode bits).
But none of that need delay the current patchset which looks good to me (though I haven't dug quite enough to give a Reviewed-by).
Thanks,
NeilBRown
Quoted 177 lines
When unlocking the lease for the delegation, clear
FMODE_NOCMTIME. If the file has been written, but no setattr for the delegated mtime and ctime has been done, update the timestamps tocurrent_time().Suggested-by NeilBrown <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4proc.c | 26 ++++++++++++++++++++++++-- fs/nfsd/nfs4state.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/state.h | 4 +++- 3 files changed, 69 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +24
-2@@ -1151,7 +1151,9 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)if (setattr->sa_bmval[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY ) {if (nfsd4_vet_deleg_time (&iattr->ia_mtime, &dp->dl_mtime, &now)) { iattr->ia_ctime = iattr->ia_mtime; -if (!nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) +if (nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) + dp->dl_setattr = true; +else iattr->ia_valid &= ~(ATTR_CTIME |ATTR_CTIME_SET ); }else { iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |@@ -1238,12 +1240,26 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return status; } +static void nfsd4_file_mark_deleg_written (struct nfs4_file *fi) +{ +spin_lock (&fi->fi_lock); +if (!list_empty (&fi->fi_delegations)) { +struct nfs4_delegation *dp =list_first_entry (&fi->fi_delegations, + struct nfs4_delegation, dl_perfile); + +if (dp->dl_type ==OPEN_DELEGATE_WRITE_ATTRS_DELEG ) + dp->dl_written = true; + } +spin_unlock (&fi->fi_lock); +} +static __be32 nfsd4_write (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u) {struct nfsd4_write *write = &u->write;stateid_t *stateid = &write->wr_stateid; +struct nfs4_stid *stid =NULL ;struct nfsd_file *nf =NULL ;__be32 status = nfs_ok;unsigned long cnt;@@ -1256,10 +1272,15 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,trace_nfsd_write_start (rqstp, &cstate->current_fh, write->wr_offset, cnt); status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, - stateid,WR_STATE , &nf,NULL ); + stateid,WR_STATE , &nf, &stid);if (status)return status; +if (stid) { +nfsd4_file_mark_deleg_written (stid->sc_file); +nfs4_put_stid (stid); + } + write->wr_how_written = write->wr_stable_how; status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, &write->wr_payload,@@ -2550,6 +2571,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,mutex_unlock (&ls->ls_mutex); nfserr = ops->proc_layoutcommit (inode, rqstp, lcp); +nfsd4_file_mark_deleg_written (ls->ls_stid.sc_file);nfs4_put_stid (&ls->ls_stid); out:return nfserr;fs/nfsd/nfs4state.c +42
-0@@ -1222,6 +1222,42 @@ static void put_deleg_file(struct nfs4_file *fp)nfs4_file_put_access (fp,NFS4_SHARE_ACCESS_READ ); } +static void nfsd4_finalize_deleg_timestamps (struct nfs4_delegation *dp,struct file *f) +{ +struct iattr ia = { .ia_valid =ATTR_ATIME |ATTR_CTIME |ATTR_MTIME }; +struct inode *inode =file_inode (f); +int ret; + +/* don't do anything if FMODE_NOCMTIME isn't set */ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) ==0 ) +return ; + +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); + +/* was it never written? */ +if (!dp->dl_written) +return ; + +/* did it get a setattr for the timestamps at some point? */ +if (dp->dl_setattr) +return ; + +/* Stamp everything to "now" */ +inode_lock (inode); + ret =notify_change (&nop_mnt_idmap, f->f_path.dentry, &ia,NULL ); +inode_unlock (inode); +if (ret) { +struct inode *inode =file_inode (f); + +pr_notice_ratelimited ("Unable to update timestamps on inode %02x:%02x:%lu: %d\n" , +MAJOR (inode->i_sb->s_dev), +MINOR (inode->i_sb->s_dev), + inode->i_ino, ret); + } +} +static void nfs4_unlock_deleg_lease (struct nfs4_delegation *dp) {struct nfs4_file *fp = dp->dl_stid.sc_file;@@ -1229,6 +1265,7 @@ static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)WARN_ON_ONCE (!fp->fi_delegees); +nfsd4_finalize_deleg_timestamps (dp, nf->nf_file);kernel_setlease (nf->nf_file,F_UNLCK ,NULL , (void **)&dp);put_deleg_file (fp); }@@ -6265,6 +6302,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,memcpy (&open->op_delegate_stateid, &dp->dl_stid.sc_stateid,sizeof (dp->dl_stid.sc_stateid));if (open->op_share_access &NFS4_SHARE_ACCESS_WRITE ) { +struct file *f = dp->dl_stid.sc_file->fi_deleg_file->nf_file; +if (!nfsd4_add_rdaccess_to_wrdeleg (rqstp, open, fh, stp) || !nfs4_delegation_stat (dp, currentfh, &stat)) {nfs4_put_stid (&dp->dl_stid);@@ -6278,6 +6317,9 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open, dp->dl_atime = stat.atime; dp->dl_ctime = stat.ctime; dp->dl_mtime = stat.mtime; +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock);trace_nfsd_deleg_write (&dp->dl_stid.sc_stateid); }else { open->op_delegate_type = deleg_ts && nfs4_delegation_stat(dp, currentfh, &stat) ?fs/nfsd/state.h +3
-1@@ -217,10 +217,12 @@ struct nfs4_delegation {struct nfs4_clnt_odstate *dl_clnt_odstate;time64_t dl_time;u32 dl_type; -/* For recall: */ +/* For recall: */ int dl_retries;struct nfsd4_callback dl_recall;bool dl_recalled; +bool dl_written; +bool dl_setattr;/* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr;Signature · 2 lines
-- 2.50.1
Re: [PATCH v4 8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
In reply to Jeff LaytonHi Jeff,
I narrowed down the upstream failure for generic/215 and generic/407 to this commit.
Let's consider first where the kernel is compiled with delegated attributes off (but it also fails just the same if the delegated attributes are compiled in).
I don't understand why the code unconditionally changed to call nfsd4_finalize_deleg_timestamps() which I think the main driver behind the failure.
Running generic/407 there is an OPEN (which gives out a write delegation) and returns a change id, then on this filehandle there is a SETATTR (with a getattr) which returns a new changeid. Then there is a CLONE where the filehandle is the destination filehandle on which there is a getattr which returns unchanged changeid/modify time (bad). Then there is a DELEGRETURN (with a getattr) which again returns same change id. Test fails.
Prior to this commit. The changeid/modify time is different in CLONE and DELEGRETURN -- test passes.
Now let me describe what happens with delegated attributes enabled. OPEN returns delegated attributes delegation, included getattr return a changeid. Then CLONE is done, the included gettattr returns a different (from open's) changeid (different time_modify). Then there is SETATTR+GEATTR+DELEGRETURN compound from the client (which carries a time_deleg_modify value different from above). Server in getattr replies with changeid same as in clone and mtime with the value client provided. So I'm not sure exactly why the test fails here but that's a different problem as my focus is on "delegation attribute off option" at the moment.
I don't know if this is the correct fix or not but perhaps we shouldn't unconditionally be setting this mode? (note this fix only fixes the delegattributes off. however i have no claims that this patch is what broke 215/407 for delegated attributes on. Something else is in play there). If this solution is acceptable, I can send a patch.
fs/nfsd/nfs4state.c +0 -0
@@ -6318,7 +6318,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp,
struct nfsd4_open *open,
dp->dl_ctime = stat.ctime;
dp->dl_mtime = stat.mtime;
spin_lock(&f->f_lock);
- f->f_mode |= FMODE_NOCMTIME;
+ if (deleg_ts)
+ f->f_mode |= FMODE_NOCMTIME;
spin_unlock(&f->f_lock);
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
} else {Quoted 192 lines · Jeff Layton
Instead of allowing the ctime to roll backward with a
WRITE_ATTRSdelegation, setFMODE_NOCMTIMEon the file and have it skip mtime and ctime updates.It is possible that the client will never send a SETATTR to set the times before returning the delegation. Add two new bools to struct
nfs4_delegation:
dl_written: tracks whether the file has been written since the delegation was granted. This is set in the WRITE and LAYOUTCOMMIT handlers.
dl_setattr: tracks whether the client has sent at least one valid mtime that can also update the ctime in a SETATTR.When unlocking the lease for the delegation, clear
FMODE_NOCMTIME. If the file has been written, but no setattr for the delegated mtime and ctime has been done, update the timestamps tocurrent_time().Suggested-by NeilBrown <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4proc.c | 26 ++++++++++++++++++++++++-- fs/nfsd/nfs4state.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/state.h | 4 +++- 3 files changed, 69 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +24
-2@@ -1151,7 +1151,9 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)if (setattr->sa_bmval[2 ] &FATTR4_WORD2_TIME_DELEG_MODIFY ) {if (nfsd4_vet_deleg_time (&iattr->ia_mtime, &dp->dl_mtime, &now)) { iattr->ia_ctime = iattr->ia_mtime; -if (!nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) +if (nfsd4_vet_deleg_time (&iattr->ia_ctime, &dp->dl_ctime, &now)) + dp->dl_setattr = true; +else iattr->ia_valid &= ~(ATTR_CTIME |ATTR_CTIME_SET ); }else { iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |@@ -1238,12 +1240,26 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,return status; } +static void nfsd4_file_mark_deleg_written (struct nfs4_file *fi) +{ +spin_lock (&fi->fi_lock); +if (!list_empty (&fi->fi_delegations)) { +struct nfs4_delegation *dp =list_first_entry (&fi->fi_delegations, + struct nfs4_delegation, dl_perfile); + +if (dp->dl_type ==OPEN_DELEGATE_WRITE_ATTRS_DELEG ) + dp->dl_written = true; + } +spin_unlock (&fi->fi_lock); +} +static __be32 nfsd4_write (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u) {struct nfsd4_write *write = &u->write;stateid_t *stateid = &write->wr_stateid; +struct nfs4_stid *stid =NULL ;struct nfsd_file *nf =NULL ;__be32 status = nfs_ok;unsigned long cnt;@@ -1256,10 +1272,15 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,trace_nfsd_write_start (rqstp, &cstate->current_fh, write->wr_offset, cnt); status =nfs4_preprocess_stateid_op (rqstp, cstate, &cstate->current_fh, - stateid,WR_STATE , &nf,NULL ); + stateid,WR_STATE , &nf, &stid);if (status)return status; +if (stid) { +nfsd4_file_mark_deleg_written (stid->sc_file); +nfs4_put_stid (stid); + } + write->wr_how_written = write->wr_stable_how; status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, &write->wr_payload,@@ -2550,6 +2571,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,mutex_unlock (&ls->ls_mutex); nfserr = ops->proc_layoutcommit (inode, rqstp, lcp); +nfsd4_file_mark_deleg_written (ls->ls_stid.sc_file);nfs4_put_stid (&ls->ls_stid); out:return nfserr;fs/nfsd/nfs4state.c +42
-0@@ -1222,6 +1222,42 @@ static void put_deleg_file(struct nfs4_file *fp)nfs4_file_put_access (fp,NFS4_SHARE_ACCESS_READ ); } +static void nfsd4_finalize_deleg_timestamps (struct nfs4_delegation *dp,struct file *f) +{ +struct iattr ia = { .ia_valid =ATTR_ATIME |ATTR_CTIME |ATTR_MTIME }; +struct inode *inode =file_inode (f); +int ret; + +/* don't do anything if FMODE_NOCMTIME isn't set */ +if ((READ_ONCE (f->f_mode) &FMODE_NOCMTIME ) ==0 ) +return ; + +spin_lock (&f->f_lock); + f->f_mode &= ~FMODE_NOCMTIME ; +spin_unlock (&f->f_lock); + +/* was it never written? */ +if (!dp->dl_written) +return ; + +/* did it get a setattr for the timestamps at some point? */ +if (dp->dl_setattr) +return ; + +/* Stamp everything to "now" */ +inode_lock (inode); + ret =notify_change (&nop_mnt_idmap, f->f_path.dentry, &ia,NULL ); +inode_unlock (inode); +if (ret) { +struct inode *inode =file_inode (f); + +pr_notice_ratelimited ("Unable to update timestamps on inode %02x:%02x:%lu: %d\n" , +MAJOR (inode->i_sb->s_dev), +MINOR (inode->i_sb->s_dev), + inode->i_ino, ret); + } +} +static void nfs4_unlock_deleg_lease (struct nfs4_delegation *dp) {struct nfs4_file *fp = dp->dl_stid.sc_file;@@ -1229,6 +1265,7 @@ static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)WARN_ON_ONCE (!fp->fi_delegees); +nfsd4_finalize_deleg_timestamps (dp, nf->nf_file);kernel_setlease (nf->nf_file,F_UNLCK ,NULL , (void **)&dp);put_deleg_file (fp); }@@ -6265,6 +6302,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,memcpy (&open->op_delegate_stateid, &dp->dl_stid.sc_stateid,sizeof (dp->dl_stid.sc_stateid));if (open->op_share_access &NFS4_SHARE_ACCESS_WRITE ) { +struct file *f = dp->dl_stid.sc_file->fi_deleg_file->nf_file; +if (!nfsd4_add_rdaccess_to_wrdeleg (rqstp, open, fh, stp) || !nfs4_delegation_stat (dp, currentfh, &stat)) {nfs4_put_stid (&dp->dl_stid);@@ -6278,6 +6317,9 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open, dp->dl_atime = stat.atime; dp->dl_ctime = stat.ctime; dp->dl_mtime = stat.mtime; +spin_lock (&f->f_lock); + f->f_mode |=FMODE_NOCMTIME ; +spin_unlock (&f->f_lock);trace_nfsd_deleg_write (&dp->dl_stid.sc_stateid); }else { open->op_delegate_type = deleg_ts && nfs4_delegation_stat(dp, currentfh, &stat) ?fs/nfsd/state.h +3
-2@@ -217,10 +217,12 @@ struct nfs4_delegation {struct nfs4_clnt_odstate *dl_clnt_odstate;time64_t dl_time;u32 dl_type; -/* For recall: */ +/* For recall: */ int dl_retries;struct nfsd4_callback dl_recall;bool dl_recalled; +bool dl_written; +bool dl_setattr;/* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr; --2.50.1
Jeff Layton
maintainerRe: [PATCH v4 8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
Quoted 56 lines · Olga Kornievskaia
Hi Jeff,
I narrowed down the upstream failure for generic/215 and generic/407 to this commit.
Let's consider first where the kernel is compiled with delegated attributes off (but it also fails just the same if the delegated attributes are compiled in).
I don't understand why the code unconditionally changed to call
nfsd4_finalize_deleg_timestamps()which I think the main driver behind the failure.Running generic/407 there is an OPEN (which gives out a write delegation) and returns a change id, then on this filehandle there is a SETATTR (with a getattr) which returns a new changeid. Then there is a CLONE where the filehandle is the destination filehandle on which there is a getattr which returns unchanged changeid/modify time (bad). Then there is a DELEGRETURN (with a getattr) which again returns same change id. Test fails.
Prior to this commit. The changeid/modify time is different in CLONE and DELEGRETURN -- test passes.
Now let me describe what happens with delegated attributes enabled. OPEN returns delegated attributes delegation, included getattr return a changeid. Then CLONE is done, the included gettattr returns a different (from open's) changeid (different
time_modify). Then there is SETATTR+GEATTR+DELEGRETURN compound from the client (which carries atime_deleg_modifyvalue different from above). Server in getattr replies with changeid same as in clone and mtime with the value client provided. So I'm not sure exactly why the test fails here but that's a different problem as my focus is on "delegation attribute off option" at the moment.I don't know if this is the correct fix or not but perhaps we shouldn't unconditionally be setting this mode? (note this fix only fixes the delegattributes off. however i have no claims that this patch is what broke 215/407 for delegated attributes on. Something else is in play there). If this solution is acceptable, I can send a patch.
fs/nfsd/nfs4state.c +2
-1@@ -6318,7 +6318,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp,struct nfsd4_open *open, dp->dl_ctime = stat.ctime; dp->dl_mtime = stat.mtime;spin_lock (&f->f_lock); - f->f_mode |=FMODE_NOCMTIME ; +if (deleg_ts) + f->f_mode |=FMODE_NOCMTIME ;spin_unlock (&f->f_lock);trace_nfsd_deleg_write (&dp->dl_stid.sc_stateid);
Quoted 3 lines
} else {That patch does look correct to me -- nice catch. Have you validated that it fixes 215 and 407?
Thanks,
Jeff
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v4 8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation
Quoted 56 lines · Jeff Layton
Quoted 54 lines · Olga Kornievskaia
Hi Jeff,
I narrowed down the upstream failure for generic/215 and generic/407 to this commit.
Let's consider first where the kernel is compiled with delegated attributes off (but it also fails just the same if the delegated attributes are compiled in).
I don't understand why the code unconditionally changed to call
nfsd4_finalize_deleg_timestamps()which I think the main driver behind the failure.Running generic/407 there is an OPEN (which gives out a write delegation) and returns a change id, then on this filehandle there is a SETATTR (with a getattr) which returns a new changeid. Then there is a CLONE where the filehandle is the destination filehandle on which there is a getattr which returns unchanged changeid/modify time (bad). Then there is a DELEGRETURN (with a getattr) which again returns same change id. Test fails.
Prior to this commit. The changeid/modify time is different in CLONE and DELEGRETURN -- test passes.
Now let me describe what happens with delegated attributes enabled. OPEN returns delegated attributes delegation, included getattr return a changeid. Then CLONE is done, the included gettattr returns a different (from open's) changeid (different
time_modify). Then there is SETATTR+GEATTR+DELEGRETURN compound from the client (which carries atime_deleg_modifyvalue different from above). Server in getattr replies with changeid same as in clone and mtime with the value client provided. So I'm not sure exactly why the test fails here but that's a different problem as my focus is on "delegation attribute off option" at the moment.I don't know if this is the correct fix or not but perhaps we shouldn't unconditionally be setting this mode? (note this fix only fixes the delegattributes off. however i have no claims that this patch is what broke 215/407 for delegated attributes on. Something else is in play there). If this solution is acceptable, I can send a patch.
fs/nfsd/nfs4state.c +2
-1@@ -6318,7 +6318,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp,struct nfsd4_open *open, dp->dl_ctime = stat.ctime; dp->dl_mtime = stat.mtime;spin_lock (&f->f_lock); - f->f_mode |=FMODE_NOCMTIME ; +if (deleg_ts) + f->f_mode |=FMODE_NOCMTIME ;
Quoted 8 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +0
-0spin_unlock (&f->f_lock);trace_nfsd_deleg_write (&dp->dl_stid.sc_stateid);} else {That patch does look correct to me -- nice catch. Have you validated that it fixes 215 and 407?
Yes, it does fix 215 and 407 for me.
Quoted 5 lines
Thanks,
Jeff
--
Jeff Layton <[email protected]>