Commit 3a4ea23d authored by Dai Ngo's avatar Dai Ngo Committed by Chuck Lever

NFSD: keep track of the number of courtesy clients in the system

Add counter nfs4_courtesy_client_count to nfsd_net to keep track
of the number of courtesy clients in the system.
Signed-off-by: default avatarDai Ngo <dai.ngo@oracle.com>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 06981d56
...@@ -192,6 +192,8 @@ struct nfsd_net { ...@@ -192,6 +192,8 @@ struct nfsd_net {
atomic_t nfs4_client_count; atomic_t nfs4_client_count;
int nfs4_max_clients; int nfs4_max_clients;
atomic_t nfsd_courtesy_clients;
}; };
/* Simple check to find out if a given net was properly initialized */ /* Simple check to find out if a given net was properly initialized */
......
...@@ -160,6 +160,13 @@ static bool is_client_expired(struct nfs4_client *clp) ...@@ -160,6 +160,13 @@ static bool is_client_expired(struct nfs4_client *clp)
return clp->cl_time == 0; return clp->cl_time == 0;
} }
static void nfsd4_dec_courtesy_client_count(struct nfsd_net *nn,
struct nfs4_client *clp)
{
if (clp->cl_state != NFSD4_ACTIVE)
atomic_add_unless(&nn->nfsd_courtesy_clients, -1, 0);
}
static __be32 get_client_locked(struct nfs4_client *clp) static __be32 get_client_locked(struct nfs4_client *clp)
{ {
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
...@@ -169,6 +176,7 @@ static __be32 get_client_locked(struct nfs4_client *clp) ...@@ -169,6 +176,7 @@ static __be32 get_client_locked(struct nfs4_client *clp)
if (is_client_expired(clp)) if (is_client_expired(clp))
return nfserr_expired; return nfserr_expired;
atomic_inc(&clp->cl_rpc_users); atomic_inc(&clp->cl_rpc_users);
nfsd4_dec_courtesy_client_count(nn, clp);
clp->cl_state = NFSD4_ACTIVE; clp->cl_state = NFSD4_ACTIVE;
return nfs_ok; return nfs_ok;
} }
...@@ -190,6 +198,7 @@ renew_client_locked(struct nfs4_client *clp) ...@@ -190,6 +198,7 @@ renew_client_locked(struct nfs4_client *clp)
list_move_tail(&clp->cl_lru, &nn->client_lru); list_move_tail(&clp->cl_lru, &nn->client_lru);
clp->cl_time = ktime_get_boottime_seconds(); clp->cl_time = ktime_get_boottime_seconds();
nfsd4_dec_courtesy_client_count(nn, clp);
clp->cl_state = NFSD4_ACTIVE; clp->cl_state = NFSD4_ACTIVE;
} }
...@@ -2235,6 +2244,7 @@ __destroy_client(struct nfs4_client *clp) ...@@ -2235,6 +2244,7 @@ __destroy_client(struct nfs4_client *clp)
if (clp->cl_cb_conn.cb_xprt) if (clp->cl_cb_conn.cb_xprt)
svc_xprt_put(clp->cl_cb_conn.cb_xprt); svc_xprt_put(clp->cl_cb_conn.cb_xprt);
atomic_add_unless(&nn->nfs4_client_count, -1, 0); atomic_add_unless(&nn->nfs4_client_count, -1, 0);
nfsd4_dec_courtesy_client_count(nn, clp);
free_client(clp); free_client(clp);
wake_up_all(&expiry_wq); wake_up_all(&expiry_wq);
} }
...@@ -4358,6 +4368,8 @@ void nfsd4_init_leases_net(struct nfsd_net *nn) ...@@ -4358,6 +4368,8 @@ void nfsd4_init_leases_net(struct nfsd_net *nn)
max_clients = (u64)si.totalram * si.mem_unit / (1024 * 1024 * 1024); max_clients = (u64)si.totalram * si.mem_unit / (1024 * 1024 * 1024);
max_clients *= NFS4_CLIENTS_PER_GB; max_clients *= NFS4_CLIENTS_PER_GB;
nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB); nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB);
atomic_set(&nn->nfsd_courtesy_clients, 0);
} }
static void init_nfs4_replay(struct nfs4_replay *rp) static void init_nfs4_replay(struct nfs4_replay *rp)
...@@ -5911,8 +5923,11 @@ nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist, ...@@ -5911,8 +5923,11 @@ nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
goto exp_client; goto exp_client;
if (!state_expired(lt, clp->cl_time)) if (!state_expired(lt, clp->cl_time))
break; break;
if (!atomic_read(&clp->cl_rpc_users)) if (!atomic_read(&clp->cl_rpc_users)) {
if (clp->cl_state == NFSD4_ACTIVE)
atomic_inc(&nn->nfsd_courtesy_clients);
clp->cl_state = NFSD4_COURTESY; clp->cl_state = NFSD4_COURTESY;
}
if (!client_has_state(clp)) if (!client_has_state(clp))
goto exp_client; goto exp_client;
if (!nfs4_anylock_blockers(clp)) if (!nfs4_anylock_blockers(clp))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment