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 v2 1/3] NFS: don't let delegated c/mtime stamps go backward
Date: Mon, 09 Nov 2026 15:44:47 -0500 [thread overview]
Message-ID: <20261109-delegts-nfs-v2-1-9d1e926cc3d5@kernel.org> (raw)
In-Reply-To: <20261109-delegts-nfs-v2-0-9d1e926cc3d5@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. Compute the stamp before storing it, so lockless
readers (getattr, CB_GETATTR) never see the trailing coarse time.
Fixes: e12912d94137 ("NFSv4: Add support for delegated atime and mtime attributes")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfs/inode.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 9839087cf373..98d8a34fab9d 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -629,25 +629,33 @@ 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_stamp(struct inode *inode)
+{
+ struct timespec64 ctime = inode_get_ctime(inode);
+ struct timespec64 now = current_time(inode);
+
+ if (timespec64_compare(&now, &ctime) <= 0) {
+ now = ctime;
+ timespec64_add_ns(&now, 1);
+ }
+ return now;
+}
+
static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)
{
unsigned int cache_flags = 0;
if (attr->ia_valid & ATTR_MTIME_SET) {
- struct timespec64 ctime = inode_get_ctime(inode);
- struct timespec64 mtime = inode_get_mtime(inode);
- struct timespec64 now;
- bool updated = false;
-
- now = inode_set_ctime_current(inode);
- if (!timespec64_equal(&now, &ctime))
- updated = true;
-
+ /* The stamp is always after the old ctime */
+ inode_set_ctime_to_ts(inode, nfs_delegated_stamp(inode));
inode_set_mtime_to_ts(inode, attr->ia_mtime);
- if (!timespec64_equal(&now, &mtime))
- updated = true;
-
- inode_maybe_inc_iversion(inode, updated);
+ inode_maybe_inc_iversion(inode, true);
cache_flags |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME;
}
if (attr->ia_valid & ATTR_ATIME) {
@@ -665,7 +673,11 @@ static void nfs_update_atime(struct inode *inode)
static void nfs_update_mtime(struct inode *inode)
{
- inode_update_time(inode, FS_UPD_CMTIME, 0);
+ struct timespec64 now = nfs_delegated_stamp(inode);
+
+ /* Not inode_update_time(): lockless readers would see its stamp */
+ inode_set_ctime_to_ts(inode, now);
+ inode_set_mtime_to_ts(inode, now);
NFS_I(inode)->cache_validity &=
~(NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME);
}
--
2.56.0
next prev parent reply other threads:[~2026-11-09 20:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 20:44 [PATCH v2 0/3] NFS: fixes for delegated timestamps Jeff Layton
2026-11-09 20:44 ` Jeff Layton [this message]
2026-11-09 20:44 ` [PATCH v2 2/3] NFS: stamp after the server's ctime when truncating under delegated times Jeff Layton
2026-11-09 20:44 ` [PATCH v2 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=20261109-delegts-nfs-v2-1-9d1e926cc3d5@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®