Skip to content

Commit

Permalink
SUNRPC: Convert auth creds to use refcount_t
Browse files Browse the repository at this point in the history
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
  • Loading branch information
Trond Myklebust committed Oct 23, 2018
1 parent 07d02a6 commit 79b1818
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/linux/sunrpc/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct rpc_cred {
const struct rpc_credops *cr_ops;
unsigned long cr_expire; /* when to gc */
unsigned long cr_flags; /* various flags */
atomic_t cr_count; /* ref count */
refcount_t cr_count; /* ref count */

kuid_t cr_uid;

Expand Down Expand Up @@ -208,7 +208,7 @@ char * rpcauth_stringify_acceptor(struct rpc_cred *);
static inline
struct rpc_cred *get_rpccred(struct rpc_cred *cred)
{
if (cred != NULL && atomic_inc_not_zero(&cred->cr_count))
if (cred != NULL && refcount_inc_not_zero(&cred->cr_count))
return cred;
return NULL;
}
Expand Down
14 changes: 7 additions & 7 deletions net/sunrpc/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)

if (nr_to_scan-- == 0)
break;
if (atomic_read(&cred->cr_count) > 1) {
if (refcount_read(&cred->cr_count) > 1) {
rpcauth_lru_remove_locked(cred);
continue;
}
Expand Down Expand Up @@ -589,7 +589,7 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
continue;
if (flags & RPCAUTH_LOOKUP_RCU) {
if (test_bit(RPCAUTH_CRED_NEW, &entry->cr_flags) ||
atomic_read(&entry->cr_count) == 0)
refcount_read(&entry->cr_count) == 0)
continue;
cred = entry;
break;
Expand Down Expand Up @@ -623,7 +623,7 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
if (cred == NULL) {
cred = new;
set_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
atomic_inc(&cred->cr_count);
refcount_inc(&cred->cr_count);
hlist_add_head_rcu(&cred->cr_hash, &cache->hashtable[nr]);
} else
list_add_tail(&new->cr_lru, &free);
Expand Down Expand Up @@ -670,7 +670,7 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
{
INIT_HLIST_NODE(&cred->cr_hash);
INIT_LIST_HEAD(&cred->cr_lru);
atomic_set(&cred->cr_count, 1);
refcount_set(&cred->cr_count, 1);
cred->cr_auth = auth;
cred->cr_ops = ops;
cred->cr_expire = jiffies;
Expand Down Expand Up @@ -739,9 +739,9 @@ put_rpccred(struct rpc_cred *cred)
if (cred == NULL)
return;
rcu_read_lock();
if (atomic_dec_and_test(&cred->cr_count))
if (refcount_dec_and_test(&cred->cr_count))
goto destroy;
if (atomic_read(&cred->cr_count) != 1 ||
if (refcount_read(&cred->cr_count) != 1 ||
!test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags))
goto out;
if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) {
Expand All @@ -752,7 +752,7 @@ put_rpccred(struct rpc_cred *cred)
rpcauth_lru_remove(cred);
} else if (rpcauth_unhash_cred(cred)) {
rpcauth_lru_remove(cred);
if (atomic_dec_and_test(&cred->cr_count))
if (refcount_dec_and_test(&cred->cr_count))
goto destroy;
}
out:
Expand Down
2 changes: 1 addition & 1 deletion net/sunrpc/auth_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ struct rpc_cred null_cred = {
.cr_lru = LIST_HEAD_INIT(null_cred.cr_lru),
.cr_auth = &null_auth,
.cr_ops = &null_credops,
.cr_count = ATOMIC_INIT(2),
.cr_count = REFCOUNT_INIT(2),
.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE,
};

0 comments on commit 79b1818

Please sign in to comment.