RPC: Move credcache-specific code out of put_rpccred() Signed-off-by: Trond Myklebust --- auth.c | 40 ++++++++-------------------------------- auth_gss/auth_gss.c | 2 +- auth_null.c | 2 +- auth_unix.c | 2 +- 4 files changed, 11 insertions(+), 35 deletions(-) Index: linux-2.6.11-rc3/net/sunrpc/auth.c =================================================================== --- linux-2.6.11-rc3.orig/net/sunrpc/auth.c +++ linux-2.6.11-rc3/net/sunrpc/auth.c @@ -99,21 +99,6 @@ rpcauth_init_credcache(struct rpc_auth * } /* - * Destroy an unreferenced credential - */ -static inline void -rpcauth_crdestroy(struct rpc_cred *cred) -{ -#ifdef RPC_DEBUG - BUG_ON(cred->cr_magic != RPCAUTH_CRED_MAGIC || - atomic_read(&cred->cr_count) || - !list_empty(&cred->cr_hash)); - cred->cr_magic = 0; -#endif - cred->cr_ops->crdestroy(cred); -} - -/* * Destroy a list of credentials */ static inline @@ -124,7 +109,7 @@ void rpcauth_destroy_credlist(struct lis while (!list_empty(head)) { cred = list_entry(head->next, struct rpc_cred, cr_hash); list_del_init(&cred->cr_hash); - rpcauth_crdestroy(cred); + put_rpccred(cred); } } @@ -145,9 +130,7 @@ rpcauth_free_credcache(struct rpc_auth * list_for_each_safe(pos, next, &auth->au_credcache[i]) { cred = list_entry(pos, struct rpc_cred, cr_hash); cred->cr_auth = NULL; - list_del_init(&cred->cr_hash); - if (atomic_read(&cred->cr_count) == 0) - list_add(&cred->cr_hash, &free); + list_move(&cred->cr_hash, &free); } } spin_unlock(&rpc_credcache_lock); @@ -157,13 +140,12 @@ rpcauth_free_credcache(struct rpc_auth * static inline int rpcauth_prune_expired(struct rpc_cred *cred, struct list_head *free) { - if (atomic_read(&cred->cr_count) != 0) + if (atomic_read(&cred->cr_count) != 1) return 0; - if (time_before(jiffies, cred->cr_expire)) + if (time_before(jiffies, cred->cr_expire + cred->cr_auth->au_expire)) return 0; cred->cr_auth = NULL; - list_del(&cred->cr_hash); - list_add(&cred->cr_hash, free); + list_move(&cred->cr_hash, free); return 1; } @@ -297,16 +279,10 @@ rpcauth_holdcred(struct rpc_task *task) void put_rpccred(struct rpc_cred *cred) { - if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock)) - return; - - if (list_empty(&cred->cr_hash)) { - spin_unlock(&rpc_credcache_lock); - rpcauth_crdestroy(cred); + cred->cr_expire = jiffies; + if (!atomic_dec_and_test(&cred->cr_count)) return; - } - cred->cr_expire = jiffies + cred->cr_auth->au_expire; - spin_unlock(&rpc_credcache_lock); + cred->cr_ops->crdestroy(cred); } void Index: linux-2.6.11-rc3/net/sunrpc/auth_null.c =================================================================== --- linux-2.6.11-rc3.orig/net/sunrpc/auth_null.c +++ linux-2.6.11-rc3/net/sunrpc/auth_null.c @@ -56,7 +56,7 @@ nul_create_cred(struct rpc_auth *auth, s if (!(cred = (struct rpc_cred *) kmalloc(sizeof(*cred),GFP_KERNEL))) return NULL; - atomic_set(&cred->cr_count, 0); + atomic_set(&cred->cr_count, 1); cred->cr_flags = RPCAUTH_CRED_UPTODATE; cred->cr_uid = acred->uid; cred->cr_ops = &null_credops; Index: linux-2.6.11-rc3/net/sunrpc/auth_unix.c =================================================================== --- linux-2.6.11-rc3.orig/net/sunrpc/auth_unix.c +++ linux-2.6.11-rc3/net/sunrpc/auth_unix.c @@ -77,7 +77,7 @@ unx_create_cred(struct rpc_auth *auth, s if (!(cred = (struct unx_cred *) kmalloc(sizeof(*cred), GFP_KERNEL))) return NULL; - atomic_set(&cred->uc_count, 0); + atomic_set(&cred->uc_count, 1); cred->uc_flags = RPCAUTH_CRED_UPTODATE; if (flags & RPC_TASK_ROOTCREDS) { cred->uc_uid = cred->uc_puid = 0; Index: linux-2.6.11-rc3/net/sunrpc/auth_gss/auth_gss.c =================================================================== --- linux-2.6.11-rc3.orig/net/sunrpc/auth_gss/auth_gss.c +++ linux-2.6.11-rc3/net/sunrpc/auth_gss/auth_gss.c @@ -666,7 +666,7 @@ gss_create_cred(struct rpc_auth *auth, s goto out_err; memset(cred, 0, sizeof(*cred)); - atomic_set(&cred->gc_count, 0); + atomic_set(&cred->gc_count, 1); cred->gc_uid = acred->uid; /* * Note: in order to force a call to call_refresh(), we deliberately