Skip to content

Commit 993bfe5

Browse files
ying-xuedavem330
authored andcommitted
tipc: make name table allocated dynamically
Name table locking policy is going to be adjusted from read-write lock protection to RCU lock protection in the future commits. But its essential precondition is to convert the allocation way of name table from static to dynamic mode. Signed-off-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Jon Maloy <jon.maloy@ericsson.com> Tested-by: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1b61e70 commit 993bfe5

File tree

3 files changed

+55
-65
lines changed

3 files changed

+55
-65
lines changed

net/tipc/name_distr.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,6 @@
3838
#include "link.h"
3939
#include "name_distr.h"
4040

41-
/**
42-
* struct publ_list - list of publications made by this node
43-
* @list: circular list of publications
44-
*/
45-
struct publ_list {
46-
struct list_head list;
47-
};
48-
49-
static struct publ_list publ_zone = {
50-
.list = LIST_HEAD_INIT(publ_zone.list),
51-
};
52-
53-
static struct publ_list publ_cluster = {
54-
.list = LIST_HEAD_INIT(publ_cluster.list),
55-
};
56-
57-
static struct publ_list publ_node = {
58-
.list = LIST_HEAD_INIT(publ_node.list),
59-
};
60-
61-
static struct publ_list *publ_lists[] = {
62-
NULL,
63-
&publ_zone, /* publ_lists[TIPC_ZONE_SCOPE] */
64-
&publ_cluster, /* publ_lists[TIPC_CLUSTER_SCOPE] */
65-
&publ_node /* publ_lists[TIPC_NODE_SCOPE] */
66-
};
67-
68-
6941
int sysctl_tipc_named_timeout __read_mostly = 2000;
7042

7143
/**
@@ -141,7 +113,8 @@ struct sk_buff *tipc_named_publish(struct publication *publ)
141113
struct sk_buff *buf;
142114
struct distr_item *item;
143115

144-
list_add_tail(&publ->local_list, &publ_lists[publ->scope]->list);
116+
list_add_tail(&publ->local_list,
117+
&tipc_nametbl->publ_list[publ->scope]);
145118

146119
if (publ->scope == TIPC_NODE_SCOPE)
147120
return NULL;
@@ -188,15 +161,15 @@ struct sk_buff *tipc_named_withdraw(struct publication *publ)
188161
* @pls: linked list of publication items to be packed into buffer chain
189162
*/
190163
static void named_distribute(struct sk_buff_head *list, u32 dnode,
191-
struct publ_list *pls)
164+
struct list_head *pls)
192165
{
193166
struct publication *publ;
194167
struct sk_buff *skb = NULL;
195168
struct distr_item *item = NULL;
196169
uint msg_dsz = (tipc_node_get_mtu(dnode, 0) / ITEM_SIZE) * ITEM_SIZE;
197170
uint msg_rem = msg_dsz;
198171

199-
list_for_each_entry(publ, &pls->list, local_list) {
172+
list_for_each_entry(publ, pls, local_list) {
200173
/* Prepare next buffer: */
201174
if (!skb) {
202175
skb = named_prepare_buf(PUBLICATION, msg_rem, dnode);
@@ -236,8 +209,10 @@ void tipc_named_node_up(u32 dnode)
236209
__skb_queue_head_init(&head);
237210

238211
read_lock_bh(&tipc_nametbl_lock);
239-
named_distribute(&head, dnode, &publ_cluster);
240-
named_distribute(&head, dnode, &publ_zone);
212+
named_distribute(&head, dnode,
213+
&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
214+
named_distribute(&head, dnode,
215+
&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
241216
read_unlock_bh(&tipc_nametbl_lock);
242217

243218
tipc_link_xmit(&head, dnode, dnode);
@@ -427,7 +402,8 @@ void tipc_named_reinit(void)
427402
write_lock_bh(&tipc_nametbl_lock);
428403

429404
for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++)
430-
list_for_each_entry(publ, &publ_lists[scope]->list, local_list)
405+
list_for_each_entry(publ, &tipc_nametbl->publ_list[scope],
406+
local_list)
431407
publ->node = tipc_own_addr;
432408

433409
write_unlock_bh(&tipc_nametbl_lock);

net/tipc/name_table.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* net/tipc/name_table.c: TIPC name table code
33
*
44
* Copyright (c) 2000-2006, 2014, Ericsson AB
5-
* Copyright (c) 2004-2008, 2010-2011, Wind River Systems
5+
* Copyright (c) 2004-2008, 2010-2014, Wind River Systems
66
* All rights reserved.
77
*
88
* Redistribution and use in source and binary forms, with or without
@@ -103,18 +103,7 @@ struct name_seq {
103103
spinlock_t lock;
104104
};
105105

106-
/**
107-
* struct name_table - table containing all existing port name publications
108-
* @types: pointer to fixed-sized array of name sequence lists,
109-
* accessed via hashing on 'type'; name sequence lists are *not* sorted
110-
* @local_publ_count: number of publications issued by this node
111-
*/
112-
struct name_table {
113-
struct hlist_head *types;
114-
u32 local_publ_count;
115-
};
116-
117-
static struct name_table table;
106+
struct name_table *tipc_nametbl;
118107
DEFINE_RWLOCK(tipc_nametbl_lock);
119108

120109
static int hash(int x)
@@ -475,7 +464,7 @@ static struct name_seq *nametbl_find_seq(u32 type)
475464
struct hlist_head *seq_head;
476465
struct name_seq *ns;
477466

478-
seq_head = &table.types[hash(type)];
467+
seq_head = &tipc_nametbl->seq_hlist[hash(type)];
479468
hlist_for_each_entry(ns, seq_head, ns_list) {
480469
if (ns->type == type)
481470
return ns;
@@ -488,6 +477,7 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
488477
u32 scope, u32 node, u32 port, u32 key)
489478
{
490479
struct name_seq *seq = nametbl_find_seq(type);
480+
int index = hash(type);
491481

492482
if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) ||
493483
(lower > upper)) {
@@ -497,7 +487,8 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
497487
}
498488

499489
if (!seq)
500-
seq = tipc_nameseq_create(type, &table.types[hash(type)]);
490+
seq = tipc_nameseq_create(type,
491+
&tipc_nametbl->seq_hlist[index]);
501492
if (!seq)
502493
return NULL;
503494

@@ -667,7 +658,7 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
667658
struct publication *publ;
668659
struct sk_buff *buf = NULL;
669660

670-
if (table.local_publ_count >= TIPC_MAX_PUBLICATIONS) {
661+
if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) {
671662
pr_warn("Publication failed, local publication limit reached (%u)\n",
672663
TIPC_MAX_PUBLICATIONS);
673664
return NULL;
@@ -677,7 +668,7 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
677668
publ = tipc_nametbl_insert_publ(type, lower, upper, scope,
678669
tipc_own_addr, port_ref, key);
679670
if (likely(publ)) {
680-
table.local_publ_count++;
671+
tipc_nametbl->local_publ_count++;
681672
buf = tipc_named_publish(publ);
682673
/* Any pending external events? */
683674
tipc_named_process_backlog();
@@ -700,7 +691,7 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
700691
write_lock_bh(&tipc_nametbl_lock);
701692
publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key);
702693
if (likely(publ)) {
703-
table.local_publ_count--;
694+
tipc_nametbl->local_publ_count--;
704695
buf = tipc_named_withdraw(publ);
705696
/* Any pending external events? */
706697
tipc_named_process_backlog();
@@ -725,12 +716,14 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
725716
void tipc_nametbl_subscribe(struct tipc_subscription *s)
726717
{
727718
u32 type = s->seq.type;
719+
int index = hash(type);
728720
struct name_seq *seq;
729721

730722
write_lock_bh(&tipc_nametbl_lock);
731723
seq = nametbl_find_seq(type);
732724
if (!seq)
733-
seq = tipc_nameseq_create(type, &table.types[hash(type)]);
725+
seq = tipc_nameseq_create(type,
726+
&tipc_nametbl->seq_hlist[index]);
734727
if (seq) {
735728
spin_lock_bh(&seq->lock);
736729
tipc_nameseq_subscribe(seq, s);
@@ -882,7 +875,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info,
882875
lowbound = 0;
883876
upbound = ~0;
884877
for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
885-
seq_head = &table.types[i];
878+
seq_head = &tipc_nametbl->seq_hlist[i];
886879
hlist_for_each_entry(seq, seq_head, ns_list) {
887880
ret += nameseq_list(seq, buf + ret, len - ret,
888881
depth, seq->type,
@@ -898,7 +891,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info,
898891
}
899892
ret += nametbl_header(buf + ret, len - ret, depth);
900893
i = hash(type);
901-
seq_head = &table.types[i];
894+
seq_head = &tipc_nametbl->seq_hlist[i];
902895
hlist_for_each_entry(seq, seq_head, ns_list) {
903896
if (seq->type == type) {
904897
ret += nameseq_list(seq, buf + ret, len - ret,
@@ -945,12 +938,18 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space)
945938

946939
int tipc_nametbl_init(void)
947940
{
948-
table.types = kcalloc(TIPC_NAMETBL_SIZE, sizeof(struct hlist_head),
949-
GFP_ATOMIC);
950-
if (!table.types)
941+
int i;
942+
943+
tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC);
944+
if (!tipc_nametbl)
951945
return -ENOMEM;
952946

953-
table.local_publ_count = 0;
947+
for (i = 0; i < TIPC_NAMETBL_SIZE; i++)
948+
INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]);
949+
950+
INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
951+
INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
952+
INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]);
954953
return 0;
955954
}
956955

@@ -990,16 +989,17 @@ void tipc_nametbl_stop(void)
990989
*/
991990
write_lock_bh(&tipc_nametbl_lock);
992991
for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
993-
if (hlist_empty(&table.types[i]))
992+
if (hlist_empty(&tipc_nametbl->seq_hlist[i]))
994993
continue;
995-
seq_head = &table.types[i];
994+
seq_head = &tipc_nametbl->seq_hlist[i];
996995
hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
997996
tipc_purge_publications(seq);
998997
}
999998
}
1000-
kfree(table.types);
1001-
table.types = NULL;
1002999
write_unlock_bh(&tipc_nametbl_lock);
1000+
1001+
kfree(tipc_nametbl);
1002+
10031003
}
10041004

10051005
static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg,
@@ -1113,7 +1113,7 @@ static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type,
11131113
i = 0;
11141114

11151115
for (; i < TIPC_NAMETBL_SIZE; i++) {
1116-
seq_head = &table.types[i];
1116+
seq_head = &tipc_nametbl->seq_hlist[i];
11171117

11181118
if (*last_type) {
11191119
seq = nametbl_find_seq(*last_type);

net/tipc/name_table.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ struct tipc_port_list;
4343
/*
4444
* TIPC name types reserved for internal TIPC use (both current and planned)
4545
*/
46-
#define TIPC_ZM_SRV 3 /* zone master service name type */
46+
#define TIPC_ZM_SRV 3 /* zone master service name type */
47+
#define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1)
48+
#define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */
4749

4850
/**
4951
* struct publication - info about a published (name or) name sequence
@@ -79,8 +81,20 @@ struct publication {
7981
struct list_head zone_list;
8082
};
8183

84+
/**
85+
* struct name_table - table containing all existing port name publications
86+
* @seq_hlist: name sequence hash lists
87+
* @publ_list: pulication lists
88+
* @local_publ_count: number of publications issued by this node
89+
*/
90+
struct name_table {
91+
struct hlist_head seq_hlist[TIPC_NAMETBL_SIZE];
92+
struct list_head publ_list[TIPC_PUBL_SCOPE_NUM];
93+
u32 local_publ_count;
94+
};
8295

8396
extern rwlock_t tipc_nametbl_lock;
97+
extern struct name_table *tipc_nametbl;
8498

8599
int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
86100

0 commit comments

Comments
 (0)