mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: 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>,
	Christian Brauner <brauner@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Jeff Layton <jlayton@kernel.org>
Subject: [PATCH 02/11] nfsd: take freeze protection before updating delegation timestamps
Date: Fri, 20 Nov 2026 08:40:08 -0800	[thread overview]
Message-ID: <20261120-delegts-fixes-v1-2-c89b37d2d462@kernel.org> (raw)
In-Reply-To: <20261120-delegts-fixes-v1-0-c89b37d2d462@kernel.org>

cb_getattr_update_times(), nfsd_update_cmtime_attr() and
nfsd4_finalize_deleg_timestamps() call notify_change() under
inode_lock(), but nothing holds freeze protection for the export. They
modify a frozen filesystem: on ext4, a foreign GETATTR whose CB_GETATTR
finds the holder modified the file trips the WARN_ON() in
ext4_journal_check_start(), and the inode's mtime and ctime change while
it is frozen.

The delegation's file and COPY's or CLONE's destination are open for
write, so the mount's write access is held. Only the superblock's
freeze protection is missing, and it goes outside inode_lock.

- cb_getattr_update_times() runs in an nfsd thread answering GETATTR.
  Rather than hold the thread until the thaw, it tries for freeze
  protection and returns NFS4ERR_DELAY, which has the client retry.
- nfsd_update_cmtime_attr(), from COPY and CLONE, waits for the thaw,
  as the data change that made the update necessary did.
- nfsd4_finalize_deleg_timestamps() runs when a delegation's lease is
  released, which includes the laundromat and nfsd shutdown. Those
  must not wait for a thaw, so it tries for freeze protection and
  leaves the times alone, with a notice, if the filesystem is frozen.

Reported-by: Christian Brauner <brauner@kernel.org>
Closes: https://lore.kernel.org/linux-nfs/20261114-abdrehen-mahnwache-farbpalette-9c31774145cc@brauner/
Fixes: 7e8ae8486e44 ("fs/nfsd: fix update of inode attrs in CB_GETATTR")
Fixes: e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
Fixes: 2863bac7f49c ("nfsd: update mtime/ctime on CLONE in presense of delegated attributes")
Fixes: 4183cf383b6f ("nfsd: update mtime/ctime on COPY in presence of delegated attributes")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/nfs4state.c | 65 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 17 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 048b2616d783..f6a01ab0602a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1453,6 +1453,30 @@ static void put_deleg_file(struct nfs4_file *fp)
 	}
 }
 
+static void nfsd_cmtime_notice(struct inode *inode, int err)
+{
+	pr_notice_ratelimited("nfsd: Unable to update timestamps on inode %02x:%02x:%llu: %d\n",
+			      MAJOR(inode->i_sb->s_dev),
+			      MINOR(inode->i_sb->s_dev),
+			      inode->i_ino, err);
+}
+
+/* Caller holds freeze protection for @f's filesystem */
+static void __nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
+{
+	struct inode *inode = file_inode(f);
+	struct iattr attr = {
+		.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG | flags,
+	};
+	int ret;
+
+	inode_lock(inode);
+	ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
+	inode_unlock(inode);
+	if (ret)
+		nfsd_cmtime_notice(inode, ret);
+}
+
 static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct file *f)
 {
 	/* don't do anything if FMODE_NOCMTIME isn't set */
@@ -1471,8 +1495,18 @@ static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct f
 	if (dp->dl_setattr)
 		return;
 
+	/*
+	 * This runs from the laundromat and from nfsd shutdown too, which
+	 * must not wait for a frozen filesystem to thaw. Leave the times
+	 * alone then.
+	 */
+	if (!file_start_write_trylock(f)) {
+		nfsd_cmtime_notice(file_inode(f), -EBUSY);
+		return;
+	}
 	/* Stamp everything to "now" */
-	nfsd_update_cmtime_attr(f, ATTR_ATIME);
+	__nfsd_update_cmtime_attr(f, ATTR_ATIME);
+	file_end_write(f);
 }
 
 static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)
@@ -10780,10 +10814,18 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
 	if (!attrs.ia_valid)
 		return 0;
 
+	/*
+	 * The delegation's file is open for write, so only freeze
+	 * protection is missing. Don't hold an nfsd thread until a frozen
+	 * filesystem thaws: NFS4ERR_DELAY has the client retry.
+	 */
+	if (!sb_start_write_trylock(inode->i_sb))
+		return -EAGAIN;
 	attrs.ia_valid |= ATTR_DELEG;
 	inode_lock(inode);
 	ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL);
 	inode_unlock(inode);
+	sb_end_write(inode->i_sb);
 	return ret;
 }
 
@@ -11052,25 +11094,14 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,
  * @flags: any additional flags that should be updated
  *
  * Given upon opening a file delegated attributes were issues, update
- * @f attributes to current times.
+ * @f attributes to current times. Waits for a frozen filesystem to thaw,
+ * like the data change that makes this necessary.
  */
 void nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
 {
-	int ret;
-	struct inode *inode = file_inode(f);
-	struct iattr attr = {
-		.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG | flags,
-	};
-
-	inode_lock(inode);
-	ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
-	inode_unlock(inode);
-	if (ret)
-		pr_notice_ratelimited("nfsd: Unable to update timestamps on "
-				      "inode %02x:%02x:%llu: %d\n",
-				      MAJOR(inode->i_sb->s_dev),
-				      MINOR(inode->i_sb->s_dev),
-				      inode->i_ino, ret);
+	file_start_write(f);
+	__nfsd_update_cmtime_attr(f, flags);
+	file_end_write(f);
 }
 
 static void

-- 
2.56.1


  parent reply	other threads:[~2026-11-20 16:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:40 [PATCH 00/11] nfsd: various delegated timestamp fixes Jeff Layton
2026-11-20 16:40 ` [PATCH 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr() Jeff Layton
2026-11-20 16:40 ` Jeff Layton [this message]
2026-11-20 16:40 ` [PATCH 03/11] nfsd: count a delegation in cl_delegs_in_recall only once Jeff Layton
2026-11-20 16:40 ` [PATCH 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS Jeff Layton
2026-11-20 16:40 ` [PATCH 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes Jeff Layton
2026-11-20 16:40 ` [PATCH 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation Jeff Layton
2026-11-20 16:40 ` [PATCH 07/11] nfsd: recall when a CB_GETATTR reply omits the size Jeff Layton
2026-11-20 16:40 ` [PATCH 08/11] nfsd: apply delegated times in a separate times-only setattr Jeff Layton
2026-11-20 16:40 ` [PATCH 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open Jeff Layton
2026-11-20 16:40 ` [PATCH 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation Jeff Layton
2026-11-20 16:40 ` [PATCH 11/11] nfsd: take the write delegation grant stat before hashing 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=20261120-delegts-fixes-v1-2-c89b37d2d462@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /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®