Add counter nfscourtesy_client_count to keep track of the number of courtesy clients in the system. Signed-off-by: Dai Ngo <dai.ngo@xxxxxxxxxx> --- fs/nfsd/nfs4state.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 9409a0dc1b76..a34ffb0d8c77 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -126,11 +126,13 @@ static const struct nfsd4_callback_ops nfsd4_cb_recall_ops; static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops; static struct workqueue_struct *laundry_wq; +static atomic_t courtesy_client_count; int nfsd4_create_laundry_wq(void) { int rc = 0; + atomic_set(&courtesy_client_count, 0); laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4"); if (laundry_wq == NULL) rc = -ENOMEM; @@ -169,7 +171,8 @@ static __be32 get_client_locked(struct nfs4_client *clp) if (is_client_expired(clp)) return nfserr_expired; atomic_inc(&clp->cl_rpc_users); - clp->cl_state = NFSD4_ACTIVE; + if (xchg(&clp->cl_state, NFSD4_ACTIVE) != NFSD4_ACTIVE) + atomic_add_unless(&courtesy_client_count, -1, 0); return nfs_ok; } @@ -190,7 +193,8 @@ renew_client_locked(struct nfs4_client *clp) list_move_tail(&clp->cl_lru, &nn->client_lru); clp->cl_time = ktime_get_boottime_seconds(); - clp->cl_state = NFSD4_ACTIVE; + if (xchg(&clp->cl_state, NFSD4_ACTIVE) != NFSD4_ACTIVE) + atomic_add_unless(&courtesy_client_count, -1, 0); } static void put_client_renew_locked(struct nfs4_client *clp) @@ -2226,6 +2230,8 @@ __destroy_client(struct nfs4_client *clp) nfsd4_shutdown_callback(clp); if (clp->cl_cb_conn.cb_xprt) svc_xprt_put(clp->cl_cb_conn.cb_xprt); + if (clp->cl_state != NFSD4_ACTIVE) + atomic_add_unless(&courtesy_client_count, -1, 0); free_client(clp); wake_up_all(&expiry_wq); } @@ -5803,8 +5809,11 @@ nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist, goto exp_client; if (!state_expired(lt, clp->cl_time)) break; - if (!atomic_read(&clp->cl_rpc_users)) - clp->cl_state = NFSD4_COURTESY; + if (!atomic_read(&clp->cl_rpc_users)) { + if (xchg(&clp->cl_state, NFSD4_COURTESY) == + NFSD4_ACTIVE) + atomic_inc(&courtesy_client_count); + } if (!client_has_state(clp) || ktime_get_boottime_seconds() >= (clp->cl_time + NFSD_COURTESY_CLIENT_TIMEOUT)) -- 2.9.5