[PATCH v3 7/8] nfsd: check a fine-grained time before clamping a delegated mtime

From: Jeff Layton

Date: Mon Nov 09 2026 - 15:41:55 EST


nfsd4_vet_deleg_attrs() clamps a holder's mtime to current_time() if
the mtime is later. current_time() is coarse unless the filesystem is
multigrain and the inode's ctime was queried and is still equal to the
coarse time. A client holding a timestamp delegation stamps at least
1ns after the fine-grained ctime it was last sent, so an mtime returned
within the same coarse tick is clamped back, and the mtime the client
reported changes after DELEGRETURN. On non-multigrain exports that is
the normal case.

When the mtime is past the coarse time, clamp it and its ctime against
ktime_get_real_ts64() instead. Such an mtime also passes dl_ctime, so
its ctime goes through inode_set_ctime_deleg(), which raises the mgtime
floor past it; later stamps on other files can't appear older. atime
gets no such floor raise, so leave it clamped to the coarse time.

This depends on "fs: check a fine-grained time before clamping a
delegated ctime". Without it, ctime is still clamped to the coarse time
and the floor isn't raised, leaving mtime ahead of both.

Fixes: 6ae30d6eb26b ("nfsd: add support for delegated timestamps")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfsd/nfs4state.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 3bb518270b8b..03e694f635db 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -10785,6 +10785,17 @@ void nfsd4_vet_deleg_attrs(struct iattr *iattr, struct nfs4_delegation *dp,
}

if (deleg_attrs & FATTR4_WORD2_TIME_DELEG_MODIFY) {
+ /*
+ * A holder stamps just past the last fine-grained ctime it
+ * was sent, which can be past the coarse @now. Clamp against
+ * a fine-grained time instead. An mtime past @now also passes
+ * dl_ctime, so its ctime goes through inode_set_ctime_deleg(),
+ * which raises the mgtime floor past it. atime gets no such
+ * floor raise, so it stays clamped to the coarse time.
+ */
+ if (timespec64_compare(&iattr->ia_mtime, &now) > 0)
+ ktime_get_real_ts64(&now);
+
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))

--
2.56.0