[PATCH 1/3] NFS: don't let delegated c/mtime stamps go backward
From: Jeff Layton
Date: Fri Nov 06 2026 - 15:48:31 EST
With a timestamp delegation the client stamps c/mtime from its own
coarse clock. That can land before the server's fine-grained ctime the
client cached from the OPEN or SETATTR reply, e.g. on a WRITE right
after an exclusive create. The server then either rejects the times
(they don't pass dl_ctime) or can't apply the ctime, since
inode_set_ctime_deleg() never moves ctime backward. Either way the
c/mtime the client reported while holding the delegation changes
after DELEGRETURN; git t1092 over NFSv4.2 sees a stat-dirty file.
When a delegated stamp isn't after the cached ctime, use the cached
ctime + 1ns instead.
Fixes: e12912d94137 ("NFSv4: Add support for delegated atime and mtime attributes")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfs/inode.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index e0a2e92952af..e990f353b7d0 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -629,6 +629,25 @@ nfs_fattr_fixup_delegated(struct inode *inode, struct nfs_fattr *fattr)
}
}
+/*
+ * With delegated timestamps, the client's coarse clock can trail the
+ * server's fine-grained ctime cached from an OPEN or SETATTR reply. The
+ * server won't move ctime backward when the times are returned, so a
+ * new stamp must land after the cached ctime.
+ */
+static struct timespec64
+nfs_delegated_ctime_after(struct inode *inode, const struct timespec64 *old)
+{
+ struct timespec64 now = inode_get_ctime(inode);
+
+ if (timespec64_compare(&now, old) <= 0) {
+ now = *old;
+ timespec64_add_ns(&now, 1);
+ inode_set_ctime_to_ts(inode, now);
+ }
+ return now;
+}
+
static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)
{
unsigned int cache_flags = 0;
@@ -639,7 +658,8 @@ static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)
struct timespec64 now;
bool updated = false;
- now = inode_set_ctime_current(inode);
+ inode_set_ctime_current(inode);
+ now = nfs_delegated_ctime_after(inode, &ctime);
if (!timespec64_equal(&now, &ctime))
updated = true;
@@ -665,7 +685,10 @@ static void nfs_update_atime(struct inode *inode)
static void nfs_update_mtime(struct inode *inode)
{
+ struct timespec64 ctime = inode_get_ctime(inode);
+
inode_update_time(inode, FS_UPD_CMTIME, 0);
+ inode_set_mtime_to_ts(inode, nfs_delegated_ctime_after(inode, &ctime));
NFS_I(inode)->cache_validity &=
~(NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME);
}
--
2.56.0