[PATCH 03/11] nfsd: count a delegation in cl_delegs_in_recall only once

From: Jeff Layton

Date: Fri Nov 20 2026 - 11:40:39 EST


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 it
directly, possibly repeatedly.

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

Skip setting dl_recalled, the increment, the client expiry, and
fi_had_conflict when dl_recalled is already set. All callers and the
F_UNLCK decrement run under flc_lock. fl_break_time = 0,
nfsd_break_one_deleg() 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@xxxxxxxxxx>
---
fs/nfsd/nfs4state.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index f6a01ab0602a..490fefaef52a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6645,11 +6645,19 @@ 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 this directly. Only the first call
+ * may count the recall, since nfsd_change_deleg_cb() undoes it 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 +6667,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