All of lore.kernel.org
 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: "Aurélien Couderc" <aurelien.couderc2002@gmail.com>,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jeff Layton" <jlayton@kernel.org>
Subject: [PATCH v2 03/11] nfsd: count a delegation in cl_delegs_in_recall only once
Date: Mon, 23 Nov 2026 04:59:06 -0800	[thread overview]
Message-ID: <20261123-delegts-fixes-v2-3-960ce0fb2fed@kernel.org> (raw)
In-Reply-To: <20261123-delegts-fixes-v2-0-960ce0fb2fed@kernel.org>

nfsd_break_deleg_cb() can run more than once per lease:
- __break_lease() calls lm_break for a read breaker
  (FL_DOWNGRADE_PENDING) and again for a later write breaker
  (FL_UNLOCK_PENDING).
- nfsd_handle_dir_event() and nfsd_recall_all_dir_delegs() call
  nfsd_break_deleg_cb() directly, possibly repeatedly.

Each call increments cl_delegs_in_recall, but nfsd_change_deleg_cb()
decrements it only once, at F_UNLCK. The leaked count keeps
nfs4_anylock_blockers() true, so the client can never again become a
courtesy client.

When dl_recalled is already set, skip the increment, the client expiry,
and the stores to dl_recalled and fi_had_conflict. All callers and the
F_UNLCK decrement run under flc_lock. Setting fl_break_time to 0, the
nfsd_break_one_deleg() call, and the false return stay unconditional.

Fixes: 66af25799940 ("NFSD: add courteous server support for thread with only delegation")
Fixes: cb7444b27c85 ("nfsd: add notification handlers for dir events")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/nfs4state.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index c4c0f6cfa14d..5c2151b329c4 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6645,11 +6645,20 @@ nfsd_break_deleg_cb(struct file_lease *fl)
 
 	trace_nfsd_cb_recall(&dp->dl_stid);
 
-	dp->dl_recalled = true;
-	atomic_inc(&clp->cl_delegs_in_recall);
-	if (try_to_expire_client(clp)) {
-		nn = net_generic(clp->net, nfsd_net_id);
-		mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
+	/*
+	 * lm_break runs again for a write breaker after a read breaker, and
+	 * the dir notification paths call nfsd_break_deleg_cb() directly.
+	 * Only the first call may count the recall, since
+	 * nfsd_change_deleg_cb() decrements cl_delegs_in_recall only once.
+	 */
+	if (!dp->dl_recalled) {
+		dp->dl_recalled = true;
+		atomic_inc(&clp->cl_delegs_in_recall);
+		if (try_to_expire_client(clp)) {
+			nn = net_generic(clp->net, nfsd_net_id);
+			mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
+		}
+		fp->fi_had_conflict = true;
 	}
 
 	/*
@@ -6659,7 +6668,6 @@ nfsd_break_deleg_cb(struct file_lease *fl)
 	 */
 	fl->fl_break_time = 0;
 
-	fp->fi_had_conflict = true;
 	nfsd_break_one_deleg(dp);
 	return false;
 }

-- 
2.56.1


  parent reply	other threads:[~2026-11-23 12:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
2026-11-23 12:59 ` [PATCH v2 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr() Jeff Layton
2026-11-23 12:59 ` [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps Jeff Layton
2026-11-23 17:46   ` Chuck Lever
2026-11-23 12:59 ` Jeff Layton [this message]
2026-11-23 12:59 ` [PATCH v2 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS Jeff Layton
2026-11-24  7:39   ` Aurélien Couderc
2026-11-23 12:59 ` [PATCH v2 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes Jeff Layton
2026-11-23 12:59 ` [PATCH v2 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation Jeff Layton
2026-11-23 12:59 ` [PATCH v2 07/11] nfsd: recall when a CB_GETATTR reply omits the size Jeff Layton
2026-11-23 12:59 ` [PATCH v2 08/11] nfsd: apply delegated times in a separate times-only setattr Jeff Layton
2026-11-23 12:59 ` [PATCH v2 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open Jeff Layton
2026-11-23 12:59 ` [PATCH v2 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation Jeff Layton
2026-11-23 12:59 ` [PATCH v2 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=20261123-delegts-fixes-v2-3-960ce0fb2fed@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=aurelien.couderc2002@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.