From: Jeff Layton <jlayton@kernel.org>
To: Christian Brauner <brauner@kernel.org>,
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>,
Jan Kara <jack@suse.cz>
Cc: Thomas 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 1/3] fs: stamp the current time for a stale delegated ctime update
Date: Fri, 04 Sep 2026 10:17:32 -0400 [thread overview]
Message-ID: <20260904-delegts-v3-1-b6062ba75f07@kernel.org> (raw)
In-Reply-To: <20260904-delegts-v3-0-b6062ba75f07@kernel.org>
inode_set_ctime_deleg() drops an update that does not advance the ctime.
That is correct when a client reports a timestamp that it advanced on its
own. It is wrong when the client moves the timestamp backwards on purpose,
as utimensat() does.
Stamp the current time in that case. The ctime still never moves backwards.
Fixes: 3952f1cbcbc4 ("nfsd: fix SETATTR updates for delegated timestamps")
Assisted-by: LLM
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/inode.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index ba7da39be4a3..09eac2e0e172 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2959,11 +2959,17 @@ EXPORT_SYMBOL(inode_set_ctime_current);
* inode attributes, including the mtime. When updating the mtime, update
* the ctime to a value at least equal to that.
*
- * This can race with concurrent updates to the inode, in which
- * case the update is skipped.
+ * The ctime never moves backwards. An @update that does not advance the ctime
+ * records the current time instead, so that the delegated change is still
+ * visible in the ctime.
+ *
+ * This can still race with a concurrent update to the inode. That stamp takes
+ * precedence, and is at least as recent as the one it displaces.
*
* Note that this works even when multigrain timestamps are not enabled,
* so it is used in either case.
+ *
+ * Returns the resulting ctime.
*/
struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 update)
{
@@ -2975,10 +2981,6 @@ struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 u
cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED;
cur_ts.tv_sec = inode_get_ctime_sec(inode);
- /* If the update is older than the existing value, skip it. */
- if (timespec64_compare(&update, &cur_ts) <= 0)
- return cur_ts;
-
ktime_get_coarse_real_ts64_mg(&now);
/* Clamp the update to "now" if it's in the future */
@@ -2987,9 +2989,14 @@ struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 u
update = timestamp_truncate(update, inode);
- /* No need to update if the values are already the same */
- if (timespec64_equal(&update, &cur_ts))
- return cur_ts;
+ /*
+ * The update does not advance the ctime. Stamp the current time, so
+ * that the delegated change is still visible in the ctime. Compare
+ * after clamping and truncating, since either can pull an update that
+ * was ahead of the ctime back onto it.
+ */
+ if (timespec64_compare(&update, &cur_ts) <= 0)
+ return inode_set_ctime_current(inode);
/*
* Try to swap the nsec value into place. If it fails, that means
--
2.55.0
next prev parent reply other threads:[~2026-09-04 14:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 14:17 [PATCH v3 0/3] fs/nfsd: accept a backdated timestamp from a delegation holder Jeff Layton
2026-09-04 14:17 ` Jeff Layton [this message]
2026-09-04 14:17 ` [PATCH v3 2/3] nfsd: " Jeff Layton
2026-09-04 14:17 ` [PATCH v3 3/3] nfsd: compare CB_GETATTR times against the inode 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=20260904-delegts-v3-1-b6062ba75f07@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®