]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
SUNRPC: Simplify lookup code
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 12 Oct 2018 17:28:26 +0000 (13:28 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 23 Oct 2018 16:24:33 +0000 (12:24 -0400)
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>
include/linux/sunrpc/auth.h
net/sunrpc/auth.c

index 2c97a3933ef902d3e77502112ac9a696841ef7ee..a7fc8f5a2dad88c104b2cd5acd7d420775e9e8ef 100644 (file)
@@ -206,11 +206,11 @@ bool                      rpcauth_cred_key_to_expire(struct rpc_auth *, struct rpc_cred *);
 char *                 rpcauth_stringify_acceptor(struct rpc_cred *);
 
 static inline
-struct rpc_cred *      get_rpccred(struct rpc_cred *cred)
+struct rpc_cred *get_rpccred(struct rpc_cred *cred)
 {
-       if (cred != NULL)
-               atomic_inc(&cred->cr_count);
-       return cred;
+       if (cred != NULL && atomic_inc_not_zero(&cred->cr_count))
+               return cred;
+       return NULL;
 }
 
 /**
@@ -226,9 +226,7 @@ struct rpc_cred *   get_rpccred(struct rpc_cred *cred)
 static inline struct rpc_cred *
 get_rpccred_rcu(struct rpc_cred *cred)
 {
-       if (atomic_inc_not_zero(&cred->cr_count))
-               return cred;
-       return NULL;
+       return get_rpccred(cred);
 }
 
 #endif /* __KERNEL__ */
index c1576b1109746f4b842fb0bafc5c9584dc27b768..77748e572686c76ebaaa907a0b231005aa038139 100644 (file)
@@ -588,19 +588,15 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
                if (!entry->cr_ops->crmatch(acred, entry, flags))
                        continue;
                if (flags & RPCAUTH_LOOKUP_RCU) {
-                       if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) &&
-                           !test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags))
-                               cred = entry;
+                       if (test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags) ||
+                           atomic_read(&entry->cr_count) == 0)
+                               continue;
+                       cred = entry;
                        break;
                }
-               spin_lock(&cache->lock);
-               if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) == 0) {
-                       spin_unlock(&cache->lock);
-                       continue;
-               }
                cred = get_rpccred(entry);
-               spin_unlock(&cache->lock);
-               break;
+               if (cred)
+                       break;
        }
        rcu_read_unlock();
 
@@ -621,7 +617,8 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
                if (!entry->cr_ops->crmatch(acred, entry, flags))
                        continue;
                cred = get_rpccred(entry);
-               break;
+               if (cred)
+                       break;
        }
        if (cred == NULL) {
                cred = new;