aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2018-10-12 13:28:26 -0400
committerTrond Myklebust <trond.myklebust@hammerspace.com>2018-10-23 12:24:33 -0400
commit07d02a67b7faae56e184f6c35f78de47f06da37f (patch)
tree8f5ecac1aeccf696c6098572afc8629537ff2ece
parent95cd623250adce2269e71cfeaf1d487cf4b0d088 (diff)
SUNRPC: Simplify lookup code
We no longer need to worry about whether or not the entry is hashed in order to figure out if the contents are valid. We only care whether or not the refcount is non-zero. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
-rw-r--r--include/linux/sunrpc/auth.h12
-rw-r--r--net/sunrpc/auth.c19
2 files changed, 13 insertions, 18 deletions
diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
index 2c97a3933ef9..a7fc8f5a2dad 100644
--- a/include/linux/sunrpc/auth.h
+++ b/include/linux/sunrpc/auth.h
@@ -206,11 +206,11 @@ bool rpcauth_cred_key_to_expire(struct rpc_auth *, struct rpc_cred *);
206char * rpcauth_stringify_acceptor(struct rpc_cred *); 206char * rpcauth_stringify_acceptor(struct rpc_cred *);
207 207
208static inline 208static inline
209struct rpc_cred * get_rpccred(struct rpc_cred *cred) 209struct rpc_cred *get_rpccred(struct rpc_cred *cred)
210{ 210{
211 if (cred != NULL) 211 if (cred != NULL && atomic_inc_not_zero(&cred->cr_count))
212 atomic_inc(&cred->cr_count); 212 return cred;
213 return cred; 213 return NULL;
214} 214}
215 215
216/** 216/**
@@ -226,9 +226,7 @@ struct rpc_cred * get_rpccred(struct rpc_cred *cred)
226static inline struct rpc_cred * 226static inline struct rpc_cred *
227get_rpccred_rcu(struct rpc_cred *cred) 227get_rpccred_rcu(struct rpc_cred *cred)
228{ 228{
229 if (atomic_inc_not_zero(&cred->cr_count)) 229 return get_rpccred(cred);
230 return cred;
231 return NULL;
232} 230}
233 231
234#endif /* __KERNEL__ */ 232#endif /* __KERNEL__ */
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index c1576b110974..77748e572686 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -588,19 +588,15 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
588 if (!entry->cr_ops->crmatch(acred, entry, flags)) 588 if (!entry->cr_ops->crmatch(acred, entry, flags))
589 continue; 589 continue;
590 if (flags & RPCAUTH_LOOKUP_RCU) { 590 if (flags & RPCAUTH_LOOKUP_RCU) {
591 if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) && 591 if (test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags) ||
592 !test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags)) 592 atomic_read(&entry->cr_count) == 0)
593 cred = entry; 593 continue;
594 cred = entry;
594 break; 595 break;
595 } 596 }
596 spin_lock(&cache->lock);
597 if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) == 0) {
598 spin_unlock(&cache->lock);
599 continue;
600 }
601 cred = get_rpccred(entry); 597 cred = get_rpccred(entry);
602 spin_unlock(&cache->lock); 598 if (cred)
603 break; 599 break;
604 } 600 }
605 rcu_read_unlock(); 601 rcu_read_unlock();
606 602
@@ -621,7 +617,8 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
621 if (!entry->cr_ops->crmatch(acred, entry, flags)) 617 if (!entry->cr_ops->crmatch(acred, entry, flags))
622 continue; 618 continue;
623 cred = get_rpccred(entry); 619 cred = get_rpccred(entry);
624 break; 620 if (cred)
621 break;
625 } 622 }
626 if (cred == NULL) { 623 if (cred == NULL) {
627 cred = new; 624 cred = new;