2
2
* net/tipc/name_table.c: TIPC name table code
3
3
*
4
4
* 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
6
6
* All rights reserved.
7
7
*
8
8
* Redistribution and use in source and binary forms, with or without
@@ -103,18 +103,7 @@ struct name_seq {
103
103
spinlock_t lock ;
104
104
};
105
105
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 ;
118
107
DEFINE_RWLOCK (tipc_nametbl_lock );
119
108
120
109
static int hash (int x )
@@ -475,7 +464,7 @@ static struct name_seq *nametbl_find_seq(u32 type)
475
464
struct hlist_head * seq_head ;
476
465
struct name_seq * ns ;
477
466
478
- seq_head = & table . types [hash (type )];
467
+ seq_head = & tipc_nametbl -> seq_hlist [hash (type )];
479
468
hlist_for_each_entry (ns , seq_head , ns_list ) {
480
469
if (ns -> type == type )
481
470
return ns ;
@@ -488,6 +477,7 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
488
477
u32 scope , u32 node , u32 port , u32 key )
489
478
{
490
479
struct name_seq * seq = nametbl_find_seq (type );
480
+ int index = hash (type );
491
481
492
482
if ((scope < TIPC_ZONE_SCOPE ) || (scope > TIPC_NODE_SCOPE ) ||
493
483
(lower > upper )) {
@@ -497,7 +487,8 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
497
487
}
498
488
499
489
if (!seq )
500
- seq = tipc_nameseq_create (type , & table .types [hash (type )]);
490
+ seq = tipc_nameseq_create (type ,
491
+ & tipc_nametbl -> seq_hlist [index ]);
501
492
if (!seq )
502
493
return NULL ;
503
494
@@ -667,7 +658,7 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
667
658
struct publication * publ ;
668
659
struct sk_buff * buf = NULL ;
669
660
670
- if (table . local_publ_count >= TIPC_MAX_PUBLICATIONS ) {
661
+ if (tipc_nametbl -> local_publ_count >= TIPC_MAX_PUBLICATIONS ) {
671
662
pr_warn ("Publication failed, local publication limit reached (%u)\n" ,
672
663
TIPC_MAX_PUBLICATIONS );
673
664
return NULL ;
@@ -677,7 +668,7 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
677
668
publ = tipc_nametbl_insert_publ (type , lower , upper , scope ,
678
669
tipc_own_addr , port_ref , key );
679
670
if (likely (publ )) {
680
- table . local_publ_count ++ ;
671
+ tipc_nametbl -> local_publ_count ++ ;
681
672
buf = tipc_named_publish (publ );
682
673
/* Any pending external events? */
683
674
tipc_named_process_backlog ();
@@ -700,7 +691,7 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
700
691
write_lock_bh (& tipc_nametbl_lock );
701
692
publ = tipc_nametbl_remove_publ (type , lower , tipc_own_addr , ref , key );
702
693
if (likely (publ )) {
703
- table . local_publ_count -- ;
694
+ tipc_nametbl -> local_publ_count -- ;
704
695
buf = tipc_named_withdraw (publ );
705
696
/* Any pending external events? */
706
697
tipc_named_process_backlog ();
@@ -725,12 +716,14 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
725
716
void tipc_nametbl_subscribe (struct tipc_subscription * s )
726
717
{
727
718
u32 type = s -> seq .type ;
719
+ int index = hash (type );
728
720
struct name_seq * seq ;
729
721
730
722
write_lock_bh (& tipc_nametbl_lock );
731
723
seq = nametbl_find_seq (type );
732
724
if (!seq )
733
- seq = tipc_nameseq_create (type , & table .types [hash (type )]);
725
+ seq = tipc_nameseq_create (type ,
726
+ & tipc_nametbl -> seq_hlist [index ]);
734
727
if (seq ) {
735
728
spin_lock_bh (& seq -> lock );
736
729
tipc_nameseq_subscribe (seq , s );
@@ -882,7 +875,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info,
882
875
lowbound = 0 ;
883
876
upbound = ~0 ;
884
877
for (i = 0 ; i < TIPC_NAMETBL_SIZE ; i ++ ) {
885
- seq_head = & table . types [i ];
878
+ seq_head = & tipc_nametbl -> seq_hlist [i ];
886
879
hlist_for_each_entry (seq , seq_head , ns_list ) {
887
880
ret += nameseq_list (seq , buf + ret , len - ret ,
888
881
depth , seq -> type ,
@@ -898,7 +891,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info,
898
891
}
899
892
ret += nametbl_header (buf + ret , len - ret , depth );
900
893
i = hash (type );
901
- seq_head = & table . types [i ];
894
+ seq_head = & tipc_nametbl -> seq_hlist [i ];
902
895
hlist_for_each_entry (seq , seq_head , ns_list ) {
903
896
if (seq -> type == type ) {
904
897
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)
945
938
946
939
int tipc_nametbl_init (void )
947
940
{
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 )
951
945
return - ENOMEM ;
952
946
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 ]);
954
953
return 0 ;
955
954
}
956
955
@@ -990,16 +989,17 @@ void tipc_nametbl_stop(void)
990
989
*/
991
990
write_lock_bh (& tipc_nametbl_lock );
992
991
for (i = 0 ; i < TIPC_NAMETBL_SIZE ; i ++ ) {
993
- if (hlist_empty (& table . types [i ]))
992
+ if (hlist_empty (& tipc_nametbl -> seq_hlist [i ]))
994
993
continue ;
995
- seq_head = & table . types [i ];
994
+ seq_head = & tipc_nametbl -> seq_hlist [i ];
996
995
hlist_for_each_entry_safe (seq , safe , seq_head , ns_list ) {
997
996
tipc_purge_publications (seq );
998
997
}
999
998
}
1000
- kfree (table .types );
1001
- table .types = NULL ;
1002
999
write_unlock_bh (& tipc_nametbl_lock );
1000
+
1001
+ kfree (tipc_nametbl );
1002
+
1003
1003
}
1004
1004
1005
1005
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,
1113
1113
i = 0 ;
1114
1114
1115
1115
for (; i < TIPC_NAMETBL_SIZE ; i ++ ) {
1116
- seq_head = & table . types [i ];
1116
+ seq_head = & tipc_nametbl -> seq_hlist [i ];
1117
1117
1118
1118
if (* last_type ) {
1119
1119
seq = nametbl_find_seq (* last_type );
0 commit comments