Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
raspberrypi-kernel
提交
e092bdcd
R
raspberrypi-kernel
项目概览
openeuler
/
raspberrypi-kernel
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
raspberrypi-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e092bdcd
编写于
6月 23, 2007
作者:
T
Trond Myklebust
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SUNRPC: cleanup rpc credential cache garbage collection
Signed-off-by:
N
Trond Myklebust
<
Trond.Myklebust@netapp.com
>
上级
fc432dd9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
49 deletion
+74
-49
include/linux/sunrpc/auth.h
include/linux/sunrpc/auth.h
+1
-0
net/sunrpc/auth.c
net/sunrpc/auth.c
+72
-49
net/sunrpc/auth_null.c
net/sunrpc/auth_null.c
+1
-0
未找到文件。
include/linux/sunrpc/auth.h
浏览文件 @
e092bdcd
...
...
@@ -34,6 +34,7 @@ struct rpc_auth;
struct
rpc_credops
;
struct
rpc_cred
{
struct
hlist_node
cr_hash
;
/* hash chain */
struct
list_head
cr_lru
;
/* lru garbage collection */
struct
rpc_auth
*
cr_auth
;
const
struct
rpc_credops
*
cr_ops
;
#ifdef RPC_DEBUG
...
...
net/sunrpc/auth.c
浏览文件 @
e092bdcd
...
...
@@ -25,6 +25,8 @@ static const struct rpc_authops *auth_flavors[RPC_AUTH_MAXFLAVOR] = {
NULL
,
/* others can be loadable modules */
};
static
LIST_HEAD
(
cred_unused
);
static
u32
pseudoflavor_to_flavor
(
u32
flavor
)
{
if
(
flavor
>=
RPC_AUTH_MAXFLAVOR
)
...
...
@@ -134,13 +136,13 @@ rpcauth_init_credcache(struct rpc_auth *auth, unsigned long expire)
* Destroy a list of credentials
*/
static
inline
void
rpcauth_destroy_credlist
(
struct
h
list_head
*
head
)
void
rpcauth_destroy_credlist
(
struct
list_head
*
head
)
{
struct
rpc_cred
*
cred
;
while
(
!
h
list_empty
(
head
))
{
cred
=
hlist_entry
(
head
->
first
,
struct
rpc_cred
,
cr_hash
);
hlist_del_init
(
&
cred
->
cr_hash
);
while
(
!
list_empty
(
head
))
{
cred
=
list_entry
(
head
->
next
,
struct
rpc_cred
,
cr_lru
);
list_del_init
(
&
cred
->
cr_lru
);
put_rpccred
(
cred
);
}
}
...
...
@@ -152,17 +154,20 @@ void rpcauth_destroy_credlist(struct hlist_head *head)
void
rpcauth_clear_credcache
(
struct
rpc_cred_cache
*
cache
)
{
H
LIST_HEAD
(
free
);
struct
hlist_
node
*
pos
,
*
next
;
LIST_HEAD
(
free
);
struct
hlist_
head
*
head
;
struct
rpc_cred
*
cred
;
int
i
;
spin_lock
(
&
rpc_credcache_lock
);
for
(
i
=
0
;
i
<
RPC_CREDCACHE_NR
;
i
++
)
{
hlist_for_each_safe
(
pos
,
next
,
&
cache
->
hashtable
[
i
])
{
cred
=
hlist_entry
(
pos
,
struct
rpc_cred
,
cr_hash
);
__hlist_del
(
&
cred
->
cr_hash
);
hlist_add_head
(
&
cred
->
cr_hash
,
&
free
);
head
=
&
cache
->
hashtable
[
i
];
while
(
!
hlist_empty
(
head
))
{
cred
=
hlist_entry
(
head
->
first
,
struct
rpc_cred
,
cr_hash
);
get_rpccred
(
cred
);
list_move_tail
(
&
cred
->
cr_lru
,
&
free
);
smp_wmb
();
hlist_del_init
(
&
cred
->
cr_hash
);
}
}
spin_unlock
(
&
rpc_credcache_lock
);
...
...
@@ -184,38 +189,39 @@ rpcauth_destroy_credcache(struct rpc_auth *auth)
}
}
/*
* Remove stale credentials. Avoid sleeping inside the loop.
*/
static
void
rpcauth_prune_expired
(
struct
rpc_auth
*
auth
,
struct
rpc_cred
*
cred
,
struct
h
list_head
*
free
)
rpcauth_prune_expired
(
struct
list_head
*
free
)
{
if
(
atomic_read
(
&
cred
->
cr_count
)
!=
1
)
return
;
if
(
time_after
(
jiffies
,
cred
->
cr_expire
+
auth
->
au_credcache
->
expire
))
clear_bit
(
RPCAUTH_CRED_UPTODATE
,
&
cred
->
cr_flags
);
if
(
test_bit
(
RPCAUTH_CRED_UPTODATE
,
&
cred
->
cr_flags
)
==
0
)
{
__hlist_del
(
&
cred
->
cr_hash
);
hlist_add_head
(
&
cred
->
cr_hash
,
free
);
struct
rpc_cred
*
cred
;
while
(
!
list_empty
(
&
cred_unused
))
{
cred
=
list_entry
(
cred_unused
.
next
,
struct
rpc_cred
,
cr_lru
);
if
(
time_after
(
jiffies
,
cred
->
cr_expire
+
cred
->
cr_auth
->
au_credcache
->
expire
))
break
;
list_del_init
(
&
cred
->
cr_lru
);
if
(
atomic_read
(
&
cred
->
cr_count
)
!=
0
)
continue
;
get_rpccred
(
cred
);
list_add_tail
(
&
cred
->
cr_lru
,
free
);
smp_wmb
();
hlist_del_init
(
&
cred
->
cr_hash
);
}
}
/*
* R
emove stale credentials. Avoid sleeping inside the loop
.
* R
un garbage collector
.
*/
static
void
rpcauth_gc_credcache
(
struct
rpc_
auth
*
auth
,
struct
h
list_head
*
free
)
rpcauth_gc_credcache
(
struct
rpc_
cred_cache
*
cache
,
struct
list_head
*
free
)
{
struct
rpc_cred_cache
*
cache
=
auth
->
au_credcache
;
struct
hlist_node
*
pos
,
*
next
;
struct
rpc_cred
*
cred
;
int
i
;
dprintk
(
"RPC: gc'ing RPC credentials for auth %p
\n
"
,
auth
);
for
(
i
=
0
;
i
<
RPC_CREDCACHE_NR
;
i
++
)
{
hlist_for_each_safe
(
pos
,
next
,
&
cache
->
hashtable
[
i
])
{
cred
=
hlist_entry
(
pos
,
struct
rpc_cred
,
cr_hash
);
rpcauth_prune_expired
(
auth
,
cred
,
free
);
}
}
if
(
time_before
(
jiffies
,
cache
->
nextgc
))
return
;
cache
->
nextgc
=
jiffies
+
cache
->
expire
;
rpcauth_prune_expired
(
free
);
}
/*
...
...
@@ -225,39 +231,35 @@ struct rpc_cred *
rpcauth_lookup_credcache
(
struct
rpc_auth
*
auth
,
struct
auth_cred
*
acred
,
int
flags
)
{
LIST_HEAD
(
free
);
struct
rpc_cred_cache
*
cache
=
auth
->
au_credcache
;
HLIST_HEAD
(
free
);
struct
hlist_node
*
pos
,
*
next
;
struct
hlist_node
*
pos
;
struct
rpc_cred
*
new
=
NULL
,
*
cred
=
NULL
;
*
cred
=
NULL
,
*
entry
;
int
nr
=
0
;
if
(
!
(
flags
&
RPCAUTH_LOOKUP_ROOTCREDS
))
nr
=
acred
->
uid
&
RPC_CREDCACHE_MASK
;
retry:
spin_lock
(
&
rpc_credcache_lock
);
if
(
time_before
(
cache
->
nextgc
,
jiffies
))
rpcauth_gc_credcache
(
auth
,
&
free
);
hlist_for_each_safe
(
pos
,
next
,
&
cache
->
hashtable
[
nr
])
{
struct
rpc_cred
*
entry
;
entry
=
hlist_entry
(
pos
,
struct
rpc_cred
,
cr_hash
);
if
(
entry
->
cr_ops
->
crmatch
(
acred
,
entry
,
flags
))
{
hlist_del
(
&
entry
->
cr_hash
);
cred
=
entry
;
break
;
}
rpcauth_prune_expired
(
auth
,
entry
,
&
free
);
hlist_for_each_entry
(
entry
,
pos
,
&
cache
->
hashtable
[
nr
],
cr_hash
)
{
if
(
!
entry
->
cr_ops
->
crmatch
(
acred
,
entry
,
flags
))
continue
;
cred
=
get_rpccred
(
entry
);
hlist_del
(
&
entry
->
cr_hash
);
break
;
}
if
(
new
)
{
if
(
cred
)
hlist_add_head
(
&
new
->
cr_hash
,
&
free
);
list_add_tail
(
&
new
->
cr_lru
,
&
free
);
else
cred
=
new
;
}
if
(
cred
)
{
hlist_add_head
(
&
cred
->
cr_hash
,
&
cache
->
hashtable
[
nr
]);
get_rpccred
(
cred
);
}
rpcauth_gc_credcache
(
cache
,
&
free
);
spin_unlock
(
&
rpc_credcache_lock
);
rpcauth_destroy_credlist
(
&
free
);
...
...
@@ -303,6 +305,7 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
struct
rpc_auth
*
auth
,
const
struct
rpc_credops
*
ops
)
{
INIT_HLIST_NODE
(
&
cred
->
cr_hash
);
INIT_LIST_HEAD
(
&
cred
->
cr_lru
);
atomic_set
(
&
cred
->
cr_count
,
1
);
cred
->
cr_auth
=
auth
;
cred
->
cr_ops
=
ops
;
...
...
@@ -353,9 +356,29 @@ rpcauth_holdcred(struct rpc_task *task)
void
put_rpccred
(
struct
rpc_cred
*
cred
)
{
cred
->
cr_expire
=
jiffies
;
/* Fast path for unhashed credentials */
if
(
!
hlist_unhashed
(
&
cred
->
cr_hash
))
goto
need_lock
;
if
(
!
atomic_dec_and_test
(
&
cred
->
cr_count
))
return
;
goto
out_destroy
;
need_lock:
if
(
!
atomic_dec_and_lock
(
&
cred
->
cr_count
,
&
rpc_credcache_lock
))
return
;
if
(
!
list_empty
(
&
cred
->
cr_lru
))
list_del_init
(
&
cred
->
cr_lru
);
if
(
test_bit
(
RPCAUTH_CRED_UPTODATE
,
&
cred
->
cr_flags
)
==
0
)
hlist_del
(
&
cred
->
cr_hash
);
else
if
(
!
hlist_unhashed
(
&
cred
->
cr_hash
))
{
cred
->
cr_expire
=
jiffies
;
list_add_tail
(
&
cred
->
cr_lru
,
&
cred_unused
);
spin_unlock
(
&
rpc_credcache_lock
);
return
;
}
spin_unlock
(
&
rpc_credcache_lock
);
out_destroy:
cred
->
cr_ops
->
crdestroy
(
cred
);
}
...
...
net/sunrpc/auth_null.c
浏览文件 @
e092bdcd
...
...
@@ -133,6 +133,7 @@ const struct rpc_credops null_credops = {
static
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
(
1
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录