mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>,
	 Lance Shelton <lance.shelton@hammerspace.com>,
	 Olga Kornievskaia <okorniev@redhat.com>
Cc: Thomas Haynes <loghyr@gmail.com>,
	linux-nfs@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Jeff Layton <jlayton@kernel.org>
Subject: [PATCH 1/3] NFS: don't let delegated c/mtime stamps go backward
Date: Fri, 06 Nov 2026 15:48:04 -0500	[thread overview]
Message-ID: <20261106-delegts-nfs-v1-1-1d5c5e364a07@kernel.org> (raw)
In-Reply-To: <20261106-delegts-nfs-v1-0-1d5c5e364a07@kernel.org>

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@kernel.org>
---
 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


  reply	other threads:[~2026-11-06 20:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 20:48 [PATCH 0/3] NFS: fixes for delegated timestamps Jeff Layton
2026-11-06 20:48 ` Jeff Layton [this message]
2026-11-06 20:48 ` [PATCH 2/3] NFS: stamp after the server's ctime when truncating under delegated times Jeff Layton
2026-11-06 20:48 ` [PATCH 3/3] NFS: stamp after the server's ctime following a CLONE 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=20261106-delegts-nfs-v1-1-1d5c5e364a07@kernel.org \
    --to=jlayton@kernel.org \
    --cc=anna@kernel.org \
    --cc=lance.shelton@hammerspace.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=loghyr@gmail.com \
    --cc=okorniev@redhat.com \
    --cc=trondmy@kernel.org \
    /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®