aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorJeff Layton <jlayton@poochiereds.net>2016-04-21 20:51:56 -0400
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2016-05-09 09:05:40 -0400
commit62dbef2ae41393eba2f6853ca174130f2d09c7d3 (patch)
treec042592a7ea30cb95d46670142e06f73d7b1d545 /include/linux
parentc065d229e308ede426a3608cf480c61983b36fb8 (diff)
sunrpc: add a get_rpccred_rcu inline
Sometimes we might have a RCU managed credential pointer and don't want to use locking to handle it. Add a function that will take a reference to the cred iff the refcount is not already zero. Callers can dereference the pointer under the rcu_read_lock and use that function to take a reference only if the cred is not on its way to destruction. Signed-off-by: Jeff Layton <jeff.layton@primarydata.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/sunrpc/auth.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
index 16bd8f8fef8c..6f36b2bf3e05 100644
--- a/include/linux/sunrpc/auth.h
+++ b/include/linux/sunrpc/auth.h
@@ -206,5 +206,23 @@ struct rpc_cred * get_rpccred(struct rpc_cred *cred)
206 return cred; 206 return cred;
207} 207}
208 208
209/**
210 * get_rpccred_rcu - get a reference to a cred using rcu-protected pointer
211 * @cred: cred of which to take a reference
212 *
213 * In some cases, we may have a pointer to a credential to which we
214 * want to take a reference, but don't already have one. Because these
215 * objects are freed using RCU, we can access the cr_count while its
216 * on its way to destruction and only take a reference if it's not already
217 * zero.
218 */
219static inline struct rpc_cred *
220get_rpccred_rcu(struct rpc_cred *cred)
221{
222 if (atomic_inc_not_zero(&cred->cr_count))
223 return cred;
224 return NULL;
225}
226
209#endif /* __KERNEL__ */ 227#endif /* __KERNEL__ */
210#endif /* _LINUX_SUNRPC_AUTH_H */ 228#endif /* _LINUX_SUNRPC_AUTH_H */