Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
31be5bf1
Commit
31be5bf1
authored
Jun 24, 2007
by
Trond Myklebust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SUNRPC: Convert the credcache lookup code to use RCU
Signed-off-by:
Trond Myklebust
<
Trond.Myklebust@netapp.com
>
parent
e092bdcd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
43 deletions
+91
-43
include/linux/sunrpc/auth.h
include/linux/sunrpc/auth.h
+3
-0
net/sunrpc/auth.c
net/sunrpc/auth.c
+57
-34
net/sunrpc/auth_gss/auth_gss.c
net/sunrpc/auth_gss/auth_gss.c
+16
-6
net/sunrpc/auth_unix.c
net/sunrpc/auth_unix.c
+15
-3
No files found.
include/linux/sunrpc/auth.h
View file @
31be5bf1
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include <linux/sunrpc/xdr.h>
#include <linux/sunrpc/xdr.h>
#include <asm/atomic.h>
#include <asm/atomic.h>
#include <linux/rcupdate.h>
/* size of the nodename buffer */
/* size of the nodename buffer */
#define UNX_MAXNODENAME 32
#define UNX_MAXNODENAME 32
...
@@ -35,6 +36,7 @@ struct rpc_credops;
...
@@ -35,6 +36,7 @@ struct rpc_credops;
struct
rpc_cred
{
struct
rpc_cred
{
struct
hlist_node
cr_hash
;
/* hash chain */
struct
hlist_node
cr_hash
;
/* hash chain */
struct
list_head
cr_lru
;
/* lru garbage collection */
struct
list_head
cr_lru
;
/* lru garbage collection */
struct
rcu_head
cr_rcu
;
struct
rpc_auth
*
cr_auth
;
struct
rpc_auth
*
cr_auth
;
const
struct
rpc_credops
*
cr_ops
;
const
struct
rpc_credops
*
cr_ops
;
#ifdef RPC_DEBUG
#ifdef RPC_DEBUG
...
@@ -50,6 +52,7 @@ struct rpc_cred {
...
@@ -50,6 +52,7 @@ struct rpc_cred {
};
};
#define RPCAUTH_CRED_NEW 0
#define RPCAUTH_CRED_NEW 0
#define RPCAUTH_CRED_UPTODATE 1
#define RPCAUTH_CRED_UPTODATE 1
#define RPCAUTH_CRED_HASHED 2
#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0
#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0
...
...
net/sunrpc/auth.c
View file @
31be5bf1
...
@@ -112,6 +112,14 @@ rpcauth_release(struct rpc_auth *auth)
...
@@ -112,6 +112,14 @@ rpcauth_release(struct rpc_auth *auth)
static
DEFINE_SPINLOCK
(
rpc_credcache_lock
);
static
DEFINE_SPINLOCK
(
rpc_credcache_lock
);
static
void
rpcauth_unhash_cred_locked
(
struct
rpc_cred
*
cred
)
{
hlist_del_rcu
(
&
cred
->
cr_hash
);
smp_mb__before_clear_bit
();
clear_bit
(
RPCAUTH_CRED_HASHED
,
&
cred
->
cr_flags
);
}
/*
/*
* Initialize RPC credential cache
* Initialize RPC credential cache
*/
*/
...
@@ -166,8 +174,7 @@ rpcauth_clear_credcache(struct rpc_cred_cache *cache)
...
@@ -166,8 +174,7 @@ rpcauth_clear_credcache(struct rpc_cred_cache *cache)
cred
=
hlist_entry
(
head
->
first
,
struct
rpc_cred
,
cr_hash
);
cred
=
hlist_entry
(
head
->
first
,
struct
rpc_cred
,
cr_hash
);
get_rpccred
(
cred
);
get_rpccred
(
cred
);
list_move_tail
(
&
cred
->
cr_lru
,
&
free
);
list_move_tail
(
&
cred
->
cr_lru
,
&
free
);
smp_wmb
();
rpcauth_unhash_cred_locked
(
cred
);
hlist_del_init
(
&
cred
->
cr_hash
);
}
}
}
}
spin_unlock
(
&
rpc_credcache_lock
);
spin_unlock
(
&
rpc_credcache_lock
);
...
@@ -207,8 +214,7 @@ rpcauth_prune_expired(struct list_head *free)
...
@@ -207,8 +214,7 @@ rpcauth_prune_expired(struct list_head *free)
continue
;
continue
;
get_rpccred
(
cred
);
get_rpccred
(
cred
);
list_add_tail
(
&
cred
->
cr_lru
,
free
);
list_add_tail
(
&
cred
->
cr_lru
,
free
);
smp_wmb
();
rpcauth_unhash_cred_locked
(
cred
);
hlist_del_init
(
&
cred
->
cr_hash
);
}
}
}
}
...
@@ -218,10 +224,12 @@ rpcauth_prune_expired(struct list_head *free)
...
@@ -218,10 +224,12 @@ rpcauth_prune_expired(struct list_head *free)
static
void
static
void
rpcauth_gc_credcache
(
struct
rpc_cred_cache
*
cache
,
struct
list_head
*
free
)
rpcauth_gc_credcache
(
struct
rpc_cred_cache
*
cache
,
struct
list_head
*
free
)
{
{
if
(
time_before
(
jiffies
,
cache
->
nextgc
))
if
(
list_empty
(
&
cred_unused
)
||
time_before
(
jiffies
,
cache
->
nextgc
))
return
;
return
;
spin_lock
(
&
rpc_credcache_lock
);
cache
->
nextgc
=
jiffies
+
cache
->
expire
;
cache
->
nextgc
=
jiffies
+
cache
->
expire
;
rpcauth_prune_expired
(
free
);
rpcauth_prune_expired
(
free
);
spin_unlock
(
&
rpc_credcache_lock
);
}
}
/*
/*
...
@@ -234,42 +242,57 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
...
@@ -234,42 +242,57 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
LIST_HEAD
(
free
);
LIST_HEAD
(
free
);
struct
rpc_cred_cache
*
cache
=
auth
->
au_credcache
;
struct
rpc_cred_cache
*
cache
=
auth
->
au_credcache
;
struct
hlist_node
*
pos
;
struct
hlist_node
*
pos
;
struct
rpc_cred
*
new
=
NULL
,
struct
rpc_cred
*
cred
=
NULL
,
*
cred
=
NULL
,
*
entry
,
*
new
;
*
entry
;
int
nr
=
0
;
int
nr
=
0
;
if
(
!
(
flags
&
RPCAUTH_LOOKUP_ROOTCREDS
))
if
(
!
(
flags
&
RPCAUTH_LOOKUP_ROOTCREDS
))
nr
=
acred
->
uid
&
RPC_CREDCACHE_MASK
;
nr
=
acred
->
uid
&
RPC_CREDCACHE_MASK
;
retry:
spin_lock
(
&
rpc_credcache_lock
);
rcu_read_lock
(
);
hlist_for_each_entry
(
entry
,
pos
,
&
cache
->
hashtable
[
nr
],
cr_hash
)
{
hlist_for_each_entry
_rcu
(
entry
,
pos
,
&
cache
->
hashtable
[
nr
],
cr_hash
)
{
if
(
!
entry
->
cr_ops
->
crmatch
(
acred
,
entry
,
flags
))
if
(
!
entry
->
cr_ops
->
crmatch
(
acred
,
entry
,
flags
))
continue
;
continue
;
spin_lock
(
&
rpc_credcache_lock
);
if
(
test_bit
(
RPCAUTH_CRED_HASHED
,
&
entry
->
cr_flags
)
==
0
)
{
spin_unlock
(
&
rpc_credcache_lock
);
continue
;
}
cred
=
get_rpccred
(
entry
);
cred
=
get_rpccred
(
entry
);
hlist_del
(
&
entry
->
cr_hash
);
spin_unlock
(
&
rpc_credcache_lock
);
break
;
break
;
}
}
if
(
new
)
{
rcu_read_unlock
();
if
(
cred
)
list_add_tail
(
&
new
->
cr_lru
,
&
free
);
else
cred
=
new
;
}
if
(
cred
)
{
hlist_add_head
(
&
cred
->
cr_hash
,
&
cache
->
hashtable
[
nr
]);
}
rpcauth_gc_credcache
(
cache
,
&
free
);
spin_unlock
(
&
rpc_credcache_lock
);
rpcauth_destroy_credlist
(
&
free
);
if
(
cred
!=
NULL
)
{
rpcauth_gc_credcache
(
cache
,
&
free
);
goto
found
;
}
if
(
!
cred
)
{
new
=
auth
->
au_ops
->
crcreate
(
auth
,
acred
,
flags
);
new
=
auth
->
au_ops
->
crcreate
(
auth
,
acred
,
flags
);
if
(
!
IS_ERR
(
new
))
if
(
IS_ERR
(
new
))
{
goto
retry
;
cred
=
new
;
cred
=
new
;
}
else
if
(
test_bit
(
RPCAUTH_CRED_NEW
,
&
cred
->
cr_flags
)
goto
out
;
}
spin_lock
(
&
rpc_credcache_lock
);
hlist_for_each_entry
(
entry
,
pos
,
&
cache
->
hashtable
[
nr
],
cr_hash
)
{
if
(
!
entry
->
cr_ops
->
crmatch
(
acred
,
entry
,
flags
))
continue
;
cred
=
get_rpccred
(
entry
);
break
;
}
if
(
cred
==
NULL
)
{
cred
=
new
;
set_bit
(
RPCAUTH_CRED_HASHED
,
&
cred
->
cr_flags
);
hlist_add_head_rcu
(
&
cred
->
cr_hash
,
&
cache
->
hashtable
[
nr
]);
}
else
list_add_tail
(
&
new
->
cr_lru
,
&
free
);
rpcauth_prune_expired
(
&
free
);
cache
->
nextgc
=
jiffies
+
cache
->
expire
;
spin_unlock
(
&
rpc_credcache_lock
);
found:
if
(
test_bit
(
RPCAUTH_CRED_NEW
,
&
cred
->
cr_flags
)
&&
cred
->
cr_ops
->
cr_init
!=
NULL
&&
cred
->
cr_ops
->
cr_init
!=
NULL
&&
!
(
flags
&
RPCAUTH_LOOKUP_NEW
))
{
&&
!
(
flags
&
RPCAUTH_LOOKUP_NEW
))
{
int
res
=
cred
->
cr_ops
->
cr_init
(
auth
,
cred
);
int
res
=
cred
->
cr_ops
->
cr_init
(
auth
,
cred
);
...
@@ -278,8 +301,9 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
...
@@ -278,8 +301,9 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
cred
=
ERR_PTR
(
res
);
cred
=
ERR_PTR
(
res
);
}
}
}
}
rpcauth_destroy_credlist
(
&
free
);
return
(
struct
rpc_cred
*
)
cred
;
out:
return
cred
;
}
}
struct
rpc_cred
*
struct
rpc_cred
*
...
@@ -357,21 +381,20 @@ void
...
@@ -357,21 +381,20 @@ void
put_rpccred
(
struct
rpc_cred
*
cred
)
put_rpccred
(
struct
rpc_cred
*
cred
)
{
{
/* Fast path for unhashed credentials */
/* Fast path for unhashed credentials */
if
(
!
hlist_unhashed
(
&
cred
->
cr_hash
)
)
if
(
test_bit
(
RPCAUTH_CRED_HASHED
,
&
cred
->
cr_flags
)
!=
0
)
goto
need_lock
;
goto
need_lock
;
if
(
!
atomic_dec_and_test
(
&
cred
->
cr_count
))
if
(
!
atomic_dec_and_test
(
&
cred
->
cr_count
))
return
;
return
;
goto
out_destroy
;
goto
out_destroy
;
need_lock:
need_lock:
if
(
!
atomic_dec_and_lock
(
&
cred
->
cr_count
,
&
rpc_credcache_lock
))
if
(
!
atomic_dec_and_lock
(
&
cred
->
cr_count
,
&
rpc_credcache_lock
))
return
;
return
;
if
(
!
list_empty
(
&
cred
->
cr_lru
))
if
(
!
list_empty
(
&
cred
->
cr_lru
))
list_del_init
(
&
cred
->
cr_lru
);
list_del_init
(
&
cred
->
cr_lru
);
if
(
test_bit
(
RPCAUTH_CRED_UPTODATE
,
&
cred
->
cr_flags
)
==
0
)
if
(
test_bit
(
RPCAUTH_CRED_UPTODATE
,
&
cred
->
cr_flags
)
==
0
)
hlist_del
(
&
cred
->
cr_hash
);
rpcauth_unhash_cred_locked
(
cred
);
else
if
(
!
hlist_unhashed
(
&
cred
->
cr_hash
)
)
{
else
if
(
test_bit
(
RPCAUTH_CRED_HASHED
,
&
cred
->
cr_flags
)
!=
0
)
{
cred
->
cr_expire
=
jiffies
;
cred
->
cr_expire
=
jiffies
;
list_add_tail
(
&
cred
->
cr_lru
,
&
cred_unused
);
list_add_tail
(
&
cred
->
cr_lru
,
&
cred_unused
);
spin_unlock
(
&
rpc_credcache_lock
);
spin_unlock
(
&
rpc_credcache_lock
);
...
...
net/sunrpc/auth_gss/auth_gss.c
View file @
31be5bf1
...
@@ -694,15 +694,25 @@ gss_destroy_ctx(struct gss_cl_ctx *ctx)
...
@@ -694,15 +694,25 @@ gss_destroy_ctx(struct gss_cl_ctx *ctx)
}
}
static
void
static
void
gss_
destroy_cred
(
struct
rpc_cred
*
rc
)
gss_
free_cred
(
struct
gss_cred
*
gss_cred
)
{
{
struct
gss_cred
*
cred
=
container_of
(
rc
,
struct
gss_cred
,
gc_base
);
dprintk
(
"RPC: gss_free_cred %p
\n
"
,
gss_cred
);
if
(
gss_cred
->
gc_ctx
)
gss_put_ctx
(
gss_cred
->
gc_ctx
);
kfree
(
gss_cred
);
}
dprintk
(
"RPC: gss_destroy_cred
\n
"
);
static
void
gss_free_cred_callback
(
struct
rcu_head
*
head
)
{
struct
gss_cred
*
gss_cred
=
container_of
(
head
,
struct
gss_cred
,
gc_base
.
cr_rcu
);
gss_free_cred
(
gss_cred
);
}
if
(
cred
->
gc_ctx
)
static
void
gss_put_ctx
(
cred
->
gc_ctx
);
gss_destroy_cred
(
struct
rpc_cred
*
cred
)
kfree
(
cred
);
{
call_rcu
(
&
cred
->
cr_rcu
,
gss_free_cred_callback
);
}
}
/*
/*
...
...
net/sunrpc/auth_unix.c
View file @
31be5bf1
...
@@ -93,11 +93,23 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
...
@@ -93,11 +93,23 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
}
}
static
void
static
void
unx_
destroy_cred
(
struct
rpc_cred
*
r
cred
)
unx_
free_cred
(
struct
unx_cred
*
unx_
cred
)
{
{
struct
unx_cred
*
cred
=
container_of
(
rcred
,
struct
unx_cred
,
uc_base
);
dprintk
(
"RPC: unx_free_cred %p
\n
"
,
unx_cred
);
kfree
(
unx_cred
);
}
static
void
unx_free_cred_callback
(
struct
rcu_head
*
head
)
{
struct
unx_cred
*
unx_cred
=
container_of
(
head
,
struct
unx_cred
,
uc_base
.
cr_rcu
);
unx_free_cred
(
unx_cred
);
}
kfree
(
cred
);
static
void
unx_destroy_cred
(
struct
rpc_cred
*
cred
)
{
call_rcu
(
&
cred
->
cr_rcu
,
unx_free_cred_callback
);
}
}
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment