提交 8beb9ab6 编写于 作者: O Octavian Purdila 提交者: David S. Miller

llc: convert llc_sap_list to RCU

Signed-off-by: NOctavian Purdila <opurdila@ixiacom.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 52d58aef
...@@ -93,7 +93,7 @@ struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap, ...@@ -93,7 +93,7 @@ struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,
#define LLC_DEST_CONN 2 /* Type 2 goes here */ #define LLC_DEST_CONN 2 /* Type 2 goes here */
extern struct list_head llc_sap_list; extern struct list_head llc_sap_list;
extern rwlock_t llc_sap_list_lock; extern spinlock_t llc_sap_list_lock;
extern int llc_rcv(struct sk_buff *skb, struct net_device *dev, extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev); struct packet_type *pt, struct net_device *orig_dev);
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <net/llc.h> #include <net/llc.h>
LIST_HEAD(llc_sap_list); LIST_HEAD(llc_sap_list);
DEFINE_RWLOCK(llc_sap_list_lock); DEFINE_SPINLOCK(llc_sap_list_lock);
/** /**
* llc_sap_alloc - allocates and initializes sap. * llc_sap_alloc - allocates and initializes sap.
...@@ -46,30 +46,6 @@ static struct llc_sap *llc_sap_alloc(void) ...@@ -46,30 +46,6 @@ static struct llc_sap *llc_sap_alloc(void)
return sap; return sap;
} }
/**
* llc_add_sap - add sap to station list
* @sap: Address of the sap
*
* Adds a sap to the LLC's station sap list.
*/
static void llc_add_sap(struct llc_sap *sap)
{
list_add_tail(&sap->node, &llc_sap_list);
}
/**
* llc_del_sap - del sap from station list
* @sap: Address of the sap
*
* Removes a sap to the LLC's station sap list.
*/
static void llc_del_sap(struct llc_sap *sap)
{
write_lock_bh(&llc_sap_list_lock);
list_del(&sap->node);
write_unlock_bh(&llc_sap_list_lock);
}
static struct llc_sap *__llc_sap_find(unsigned char sap_value) static struct llc_sap *__llc_sap_find(unsigned char sap_value)
{ {
struct llc_sap* sap; struct llc_sap* sap;
...@@ -93,13 +69,13 @@ static struct llc_sap *__llc_sap_find(unsigned char sap_value) ...@@ -93,13 +69,13 @@ static struct llc_sap *__llc_sap_find(unsigned char sap_value)
*/ */
struct llc_sap *llc_sap_find(unsigned char sap_value) struct llc_sap *llc_sap_find(unsigned char sap_value)
{ {
struct llc_sap* sap; struct llc_sap *sap;
read_lock_bh(&llc_sap_list_lock); rcu_read_lock_bh();
sap = __llc_sap_find(sap_value); sap = __llc_sap_find(sap_value);
if (sap) if (sap)
llc_sap_hold(sap); llc_sap_hold(sap);
read_unlock_bh(&llc_sap_list_lock); rcu_read_unlock_bh();
return sap; return sap;
} }
...@@ -120,7 +96,7 @@ struct llc_sap *llc_sap_open(unsigned char lsap, ...@@ -120,7 +96,7 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
{ {
struct llc_sap *sap = NULL; struct llc_sap *sap = NULL;
write_lock_bh(&llc_sap_list_lock); spin_lock_bh(&llc_sap_list_lock);
if (__llc_sap_find(lsap)) /* SAP already exists */ if (__llc_sap_find(lsap)) /* SAP already exists */
goto out; goto out;
sap = llc_sap_alloc(); sap = llc_sap_alloc();
...@@ -128,9 +104,9 @@ struct llc_sap *llc_sap_open(unsigned char lsap, ...@@ -128,9 +104,9 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
goto out; goto out;
sap->laddr.lsap = lsap; sap->laddr.lsap = lsap;
sap->rcv_func = func; sap->rcv_func = func;
llc_add_sap(sap); list_add_tail_rcu(&sap->node, &llc_sap_list);
out: out:
write_unlock_bh(&llc_sap_list_lock); spin_unlock_bh(&llc_sap_list_lock);
return sap; return sap;
} }
...@@ -146,7 +122,13 @@ struct llc_sap *llc_sap_open(unsigned char lsap, ...@@ -146,7 +122,13 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
void llc_sap_close(struct llc_sap *sap) void llc_sap_close(struct llc_sap *sap)
{ {
WARN_ON(sap->sk_count); WARN_ON(sap->sk_count);
llc_del_sap(sap);
spin_lock_bh(&llc_sap_list_lock);
list_del_rcu(&sap->node);
spin_unlock_bh(&llc_sap_list_lock);
synchronize_rcu();
kfree(sap); kfree(sap);
} }
......
...@@ -32,14 +32,11 @@ static void llc_ui_format_mac(struct seq_file *seq, u8 *addr) ...@@ -32,14 +32,11 @@ static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
static struct sock *llc_get_sk_idx(loff_t pos) static struct sock *llc_get_sk_idx(loff_t pos)
{ {
struct list_head *sap_entry;
struct llc_sap *sap; struct llc_sap *sap;
struct sock *sk = NULL; struct sock *sk = NULL;
int i; int i;
list_for_each(sap_entry, &llc_sap_list) { list_for_each_entry_rcu(sap, &llc_sap_list, node) {
sap = list_entry(sap_entry, struct llc_sap, node);
spin_lock_bh(&sap->sk_lock); spin_lock_bh(&sap->sk_lock);
for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) { for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
struct hlist_nulls_head *head = &sap->sk_laddr_hash[i]; struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
...@@ -62,7 +59,7 @@ static void *llc_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -62,7 +59,7 @@ static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
{ {
loff_t l = *pos; loff_t l = *pos;
read_lock_bh(&llc_sap_list_lock); rcu_read_lock_bh();
return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN; return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
} }
...@@ -102,7 +99,7 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos) ...@@ -102,7 +99,7 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
if (sk) if (sk)
goto out; goto out;
spin_unlock_bh(&sap->sk_lock); spin_unlock_bh(&sap->sk_lock);
list_for_each_entry_continue(sap, &llc_sap_list, node) { list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) {
spin_lock_bh(&sap->sk_lock); spin_lock_bh(&sap->sk_lock);
sk = laddr_hash_next(sap, -1); sk = laddr_hash_next(sap, -1);
if (sk) if (sk)
...@@ -122,7 +119,7 @@ static void llc_seq_stop(struct seq_file *seq, void *v) ...@@ -122,7 +119,7 @@ static void llc_seq_stop(struct seq_file *seq, void *v)
spin_unlock_bh(&sap->sk_lock); spin_unlock_bh(&sap->sk_lock);
} }
read_unlock_bh(&llc_sap_list_lock); rcu_read_unlock_bh();
} }
static int llc_seq_socket_show(struct seq_file *seq, void *v) static int llc_seq_socket_show(struct seq_file *seq, void *v)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册