]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
sunrpc: add a get_rpccred_rcu inline
authorJeff Layton <jlayton@poochiereds.net>
Fri, 22 Apr 2016 00:51:56 +0000 (20:51 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 9 May 2016 13:05:40 +0000 (09:05 -0400)
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>
include/linux/sunrpc/auth.h

index 16bd8f8fef8c4d829ca7ac46b14a5e00e448e3e1..6f36b2bf3e05c71e0054cfda76768debc908e2b8 100644 (file)
@@ -206,5 +206,23 @@ struct rpc_cred *  get_rpccred(struct rpc_cred *cred)
        return cred;
 }
 
+/**
+ * get_rpccred_rcu - get a reference to a cred using rcu-protected pointer
+ * @cred: cred of which to take a reference
+ *
+ * In some cases, we may have a pointer to a credential to which we
+ * want to take a reference, but don't already have one. Because these
+ * objects are freed using RCU, we can access the cr_count while its
+ * on its way to destruction and only take a reference if it's not already
+ * zero.
+ */
+static inline struct rpc_cred *
+get_rpccred_rcu(struct rpc_cred *cred)
+{
+       if (atomic_inc_not_zero(&cred->cr_count))
+               return cred;
+       return NULL;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_AUTH_H */