From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: Tom Haynes <loghyr@gmail.com>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v3 3/8] nfsd: don't stamp over an applied delegated mtime at DELEGRETURN
Date: Mon, 09 Nov 2026 15:36:44 -0500 [thread overview]
Message-ID: <20261109-deleg-cb-getattr-times-v3-3-710c7244a6ea@kernel.org> (raw)
In-Reply-To: <20261109-deleg-cb-getattr-times-v3-0-710c7244a6ea@kernel.org>
nfsd4_finalize_deleg_timestamps() stamps a/m/ctime to "now" at
DELEGRETURN when the file was written and dl_setattr is clear. But
dl_setattr is only set when both the mtime and ctime vets pass:
- nfsd4_vet_deleg_attrs() applies the holder's mtime but leaves
dl_setattr clear if that mtime doesn't pass dl_ctime. A client mtime a
fraction of a millisecond behind the server's ctime at grant is
enough.
- cb_getattr_update_times() applies the holder's mtime but never sets
dl_setattr.
Either way, DELEGRETURN then overwrites the mtime the holder supplied
with the return time. Seen as git t1092 failures over NFSv4.2: an
untouched file's c/mtime jump ~25s after git recorded them.
- Set dl_setattr whenever the holder's mtime is applied. Test it under
inode_lock at DELEGRETURN, so a racing CB_GETATTR reply's mtime isn't
stamped over.
- If that mtime doesn't pass dl_ctime, set ctime to the current time
instead of leaving it at its grant value. DELEGRETURN no longer
stamps it, and where the change attribute derives from ctime (no
i_version), it must still move across the holder's writes. dl_ctime
is recorded from the inode, so later vetting sees that ctime. RFC 9754
specifies the change time only when the mtime exceeds it; RFC 8881
section 10.4.3 says the server SHOULD keep time_metadata and change
from going backward.
- Have SETATTR and CB_GETATTR share nfsd4_vet_deleg_attrs(), so their
vetting can't diverge again.
The client fix "NFS: don't let delegated c/mtime stamps go backward"
makes the ctime case rare.
Fixes: e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 82 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 47 insertions(+), 35 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a8966d1f786f..35712e129b7a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1463,6 +1463,12 @@ static void put_deleg_file(struct nfs4_file *fp)
static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct file *f)
{
+ struct inode *inode = file_inode(f);
+ struct iattr attr = {
+ .ia_valid = ATTR_ATIME | ATTR_CTIME | ATTR_MTIME | ATTR_DELEG,
+ };
+ int ret;
+
/* don't do anything if FMODE_NOCMTIME isn't set */
if ((READ_ONCE(f->f_mode) & FMODE_NOCMTIME) == 0)
return;
@@ -1475,12 +1481,22 @@ static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct f
if (!READ_ONCE(dp->dl_written))
return;
+ /* A racing CB_GETATTR reply sets dl_setattr under inode_lock */
+ inode_lock(inode);
/* did it get a setattr for the timestamps at some point? */
- if (dp->dl_setattr)
+ if (dp->dl_setattr) {
+ inode_unlock(inode);
return;
+ }
/* Stamp everything to "now" */
- nfsd_update_cmtime_attr(f, ATTR_ATIME);
+ ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
+ inode_unlock(inode);
+ if (ret)
+ pr_notice_ratelimited("nfsd: Unable to update timestamps on inode %02x:%02x:%llu: %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)
@@ -10720,14 +10736,16 @@ bool nfsd4_vet_deleg_time(struct timespec64 *req, const struct timespec64 *orig,
}
/**
- * nfsd4_vet_deleg_attrs - vet the delegated timestamps in a SETATTR
- * @iattr: attributes to be set
- * @dp: timestamp delegation held by the SETATTR's sender
- * @deleg_attrs: FATTR4_WORD2_TIME_DELEG_* bits in the SETATTR
+ * nfsd4_vet_deleg_attrs - vet a timestamp delegation holder's times
+ * @iattr: holder's times in ia_atime and ia_mtime
+ * @dp: holder's timestamp delegation
+ * @deleg_attrs: FATTR4_WORD2_TIME_DELEG_* bits naming the times to vet
*
- * Drop requested timestamps that don't pass nfsd4_vet_deleg_time(), and
- * clamp ones in the future. Set dl_setattr if both the mtime and ctime
- * pass.
+ * Set the ATTR_[AMC]TIME* bits in @iattr for the times that pass
+ * nfsd4_vet_deleg_time(), clamping ones in the future, and clear them for
+ * the ones that don't. Ctime follows an applied mtime, or is set to the
+ * current time if that mtime doesn't pass dl_ctime: DELEGRETURN won't
+ * stamp it, and the change attribute may derive from it.
*
* Context: Caller holds the inode_lock across this, applying @iattr, and
* nfsd4_record_deleg_attrs(), so cb_getattr_update_times() can't move
@@ -10741,21 +10759,21 @@ void nfsd4_vet_deleg_attrs(struct iattr *iattr, struct nfs4_delegation *dp,
lockdep_assert_held_write(&inode->i_rwsem);
- if ((deleg_attrs & FATTR4_WORD2_TIME_DELEG_ACCESS) &&
- !nfsd4_vet_deleg_time(&iattr->ia_atime, &dp->dl_atime, &now))
+ if (deleg_attrs & FATTR4_WORD2_TIME_DELEG_ACCESS) {
iattr->ia_valid &= ~(ATTR_ATIME | ATTR_ATIME_SET);
+ if (nfsd4_vet_deleg_time(&iattr->ia_atime, &dp->dl_atime, &now))
+ iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
+ }
if (deleg_attrs & 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))
- dp->dl_setattr = true;
- else
- iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET);
- } else {
- iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |
- ATTR_MTIME | ATTR_MTIME_SET);
- }
+ iattr->ia_valid &= ~(ATTR_MTIME | ATTR_MTIME_SET |
+ ATTR_CTIME | ATTR_CTIME_SET);
+ if (!nfsd4_vet_deleg_time(&iattr->ia_mtime, &dp->dl_mtime, &now))
+ return;
+ iattr->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME;
+ iattr->ia_ctime = iattr->ia_mtime;
+ if (nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now))
+ iattr->ia_valid |= ATTR_CTIME_SET;
}
}
@@ -10778,9 +10796,12 @@ void nfsd4_record_deleg_attrs(const struct iattr *iattr,
if (iattr->ia_valid & ATTR_ATIME_SET)
dp->dl_atime = iattr->ia_atime;
- if (iattr->ia_valid & ATTR_MTIME_SET)
+ if (iattr->ia_valid & ATTR_MTIME_SET) {
dp->dl_mtime = iattr->ia_mtime;
- /* inode_set_ctime_deleg() keeps a later ctime */
+ /* Don't let DELEGRETURN stamp over the holder's mtime */
+ dp->dl_setattr = true;
+ }
+ /* Ctime may be "now", or inode_set_ctime_deleg() kept a later one */
if (iattr->ia_valid & ATTR_CTIME)
dp->dl_ctime = inode_get_ctime(inode);
}
@@ -10810,8 +10831,6 @@ static void cb_getattr_update_times(const struct path *path,
/* Serialize vetting against dl_*time with their update below */
inode_lock(inode);
if (deleg_attrs_deleg(dp->dl_type)) {
- struct timespec64 now = current_time(inode);
-
/*
* The holder's own SETATTRs, xattr changes, fallocates, LINKs
* etc. don't break its delegation and don't show up in its
@@ -10826,16 +10845,9 @@ static void cb_getattr_update_times(const struct path *path,
attrs.ia_atime = ncf->ncf_cb_atime;
attrs.ia_mtime = ncf->ncf_cb_mtime;
-
- 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, &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;
- }
+ nfsd4_vet_deleg_attrs(&attrs, dp,
+ FATTR4_WORD2_TIME_DELEG_ACCESS |
+ FATTR4_WORD2_TIME_DELEG_MODIFY);
/*
* The times are the holder's, so don't hold the GETATTR
--
2.56.0
next prev parent reply other threads:[~2026-11-09 20:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 20:36 [PATCH v3 0/8] nfsd: more delegated timestamp fixes Jeff Layton
2026-11-09 20:36 ` [PATCH v3 1/8] nfsd: Report vetted delegated timestamps in GETATTR replies Jeff Layton
2026-11-09 20:36 ` [PATCH v3 2/8] nfsd: Honor delegated timestamps when change and size match Jeff Layton
2026-11-09 20:36 ` Jeff Layton [this message]
2026-11-09 20:36 ` [PATCH v3 4/8] nfsd: don't vet delegated times against an exclusive-create verifier Jeff Layton
2026-11-09 20:36 ` [PATCH v3 5/8] nfsd: mark the delegation written on COPY/CLONE instead of stamping c/mtime Jeff Layton
2026-11-09 20:36 ` [PATCH v3 6/8] fs: check a fine-grained time before clamping a delegated ctime Jeff Layton
2026-11-09 20:36 ` [PATCH v3 7/8] nfsd: check a fine-grained time before clamping a delegated mtime Jeff Layton
2026-11-09 20:36 ` [PATCH v3 8/8] nfsd: raise delegated time floors after a size-changing SETATTR Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109-deleg-cb-getattr-times-v3-3-710c7244a6ea@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=loghyr@gmail.com \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®