Commit 59f8e91b authored by J. Bruce Fields's avatar J. Bruce Fields

nfsd4: use reference count to free client

Keep a second reference count which is what is really used to decide
when to free the client's memory.

Next I'm going to add an nfsd/clients/ directory with a subdirectory for
each NFSv4 client.  File objects under nfsd/clients/ will hold these
references.
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 14ed14cc
...@@ -1879,6 +1879,24 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name) ...@@ -1879,6 +1879,24 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
return NULL; return NULL;
} }
static void __free_client(struct kref *k)
{
struct nfs4_client *clp = container_of(k, struct nfs4_client, cl_ref);
free_svc_cred(&clp->cl_cred);
kfree(clp->cl_ownerstr_hashtbl);
kfree(clp->cl_name.data);
idr_destroy(&clp->cl_stateids);
if (clp->cl_nfsd_dentry)
nfsd_client_rmdir(clp->cl_nfsd_dentry);
kmem_cache_free(client_slab, clp);
}
void drop_client(struct nfs4_client *clp)
{
kref_put(&clp->cl_ref, __free_client);
}
static void static void
free_client(struct nfs4_client *clp) free_client(struct nfs4_client *clp)
{ {
...@@ -1891,11 +1909,7 @@ free_client(struct nfs4_client *clp) ...@@ -1891,11 +1909,7 @@ free_client(struct nfs4_client *clp)
free_session(ses); free_session(ses);
} }
rpc_destroy_wait_queue(&clp->cl_cb_waitq); rpc_destroy_wait_queue(&clp->cl_cb_waitq);
free_svc_cred(&clp->cl_cred); drop_client(clp);
kfree(clp->cl_ownerstr_hashtbl);
kfree(clp->cl_name.data);
idr_destroy(&clp->cl_stateids);
kmem_cache_free(client_slab, clp);
} }
/* must be called under the client_lock */ /* must be called under the client_lock */
...@@ -2216,6 +2230,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name, ...@@ -2216,6 +2230,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
free_client(clp); free_client(clp);
return NULL; return NULL;
} }
kref_init(&clp->cl_ref);
nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL);
clp->cl_time = get_seconds(); clp->cl_time = get_seconds();
clear_bit(0, &clp->cl_cb_slot_busy); clear_bit(0, &clp->cl_cb_slot_busy);
......
...@@ -348,6 +348,7 @@ struct nfs4_client { ...@@ -348,6 +348,7 @@ struct nfs4_client {
u32 cl_exchange_flags; u32 cl_exchange_flags;
/* number of rpc's in progress over an associated session: */ /* number of rpc's in progress over an associated session: */
atomic_t cl_rpc_users; atomic_t cl_rpc_users;
struct kref cl_ref;
struct nfs4_op_map cl_spo_must_allow; struct nfs4_op_map cl_spo_must_allow;
/* for nfs41 callbacks */ /* for nfs41 callbacks */
......
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