[PATCH v2 03/11] nfsd: count a delegation in cl_delegs_in_recall only once
From: Jeff Layton
Date: Mon Nov 23 2026 - 07:59:27 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
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@xxxxxxxxxx>
---
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