2 * net/tipc/name_table.c: TIPC name table code
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2004-2005, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
40 #include "name_table.h"
41 #include "name_distr.h"
43 #include "node_subscr.h"
49 static int tipc_nametbl_size
= 1024; /* must be a power of 2 */
52 * struct sub_seq - container for all published instances of a name sequence
53 * @lower: name sequence lower bound
54 * @upper: name sequence upper bound
55 * @node_list: circular list of matching publications with >= node scope
56 * @cluster_list: circular list of matching publications with >= cluster scope
57 * @zone_list: circular list of matching publications with >= zone scope
63 struct publication
*node_list
;
64 struct publication
*cluster_list
;
65 struct publication
*zone_list
;
69 * struct name_seq - container for all published instances of a name type
70 * @type: 32 bit 'type' value for name sequence
71 * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type';
72 * sub-sequences are sorted in ascending order
73 * @alloc: number of sub-sequences currently in array
74 * @first_free: upper bound of highest sub-sequence + 1
75 * @ns_list: links to adjacent name sequences in hash chain
76 * @subscriptions: list of subscriptions for this 'type'
77 * @lock: spinlock controlling access to name sequence structure
82 struct sub_seq
*sseqs
;
85 struct hlist_node ns_list
;
86 struct list_head subscriptions
;
91 * struct name_table - table containing all existing port name publications
92 * @types: pointer to fixed-sized array of name sequence lists,
93 * accessed via hashing on 'type'; name sequence lists are *not* sorted
94 * @local_publ_count: number of publications issued by this node
98 struct hlist_head
*types
;
102 static struct name_table table
= { NULL
} ;
103 static atomic_t rsv_publ_ok
= ATOMIC_INIT(0);
104 rwlock_t tipc_nametbl_lock
= RW_LOCK_UNLOCKED
;
107 static int hash(int x
)
109 return(x
& (tipc_nametbl_size
- 1));
113 * publ_create - create a publication structure
116 static struct publication
*publ_create(u32 type
, u32 lower
, u32 upper
,
117 u32 scope
, u32 node
, u32 port_ref
,
120 struct publication
*publ
=
121 (struct publication
*)kmalloc(sizeof(*publ
), GFP_ATOMIC
);
123 warn("Memory squeeze; failed to create publication\n");
127 memset(publ
, 0, sizeof(*publ
));
133 publ
->ref
= port_ref
;
135 INIT_LIST_HEAD(&publ
->local_list
);
136 INIT_LIST_HEAD(&publ
->pport_list
);
137 INIT_LIST_HEAD(&publ
->subscr
.nodesub_list
);
142 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures
145 static struct sub_seq
*tipc_subseq_alloc(u32 cnt
)
147 u32 sz
= cnt
* sizeof(struct sub_seq
);
148 struct sub_seq
*sseq
= (struct sub_seq
*)kmalloc(sz
, GFP_ATOMIC
);
156 * tipc_nameseq_create - create a name sequence structure for the specified 'type'
158 * Allocates a single sub-sequence structure and sets it to all 0's.
161 static struct name_seq
*tipc_nameseq_create(u32 type
, struct hlist_head
*seq_head
)
163 struct name_seq
*nseq
=
164 (struct name_seq
*)kmalloc(sizeof(*nseq
), GFP_ATOMIC
);
165 struct sub_seq
*sseq
= tipc_subseq_alloc(1);
167 if (!nseq
|| !sseq
) {
168 warn("Memory squeeze; failed to create name sequence\n");
174 memset(nseq
, 0, sizeof(*nseq
));
175 nseq
->lock
= SPIN_LOCK_UNLOCKED
;
178 dbg("tipc_nameseq_create() nseq = %x type %u, ssseqs %x, ff: %u\n",
179 nseq
, type
, nseq
->sseqs
, nseq
->first_free
);
181 INIT_HLIST_NODE(&nseq
->ns_list
);
182 INIT_LIST_HEAD(&nseq
->subscriptions
);
183 hlist_add_head(&nseq
->ns_list
, seq_head
);
188 * nameseq_find_subseq - find sub-sequence (if any) matching a name instance
190 * Very time-critical, so binary searches through sub-sequence array.
193 static struct sub_seq
*nameseq_find_subseq(struct name_seq
*nseq
,
196 struct sub_seq
*sseqs
= nseq
->sseqs
;
198 int high
= nseq
->first_free
- 1;
201 while (low
<= high
) {
202 mid
= (low
+ high
) / 2;
203 if (instance
< sseqs
[mid
].lower
)
205 else if (instance
> sseqs
[mid
].upper
)
214 * nameseq_locate_subseq - determine position of name instance in sub-sequence
216 * Returns index in sub-sequence array of the entry that contains the specified
217 * instance value; if no entry contains that value, returns the position
218 * where a new entry for it would be inserted in the array.
220 * Note: Similar to binary search code for locating a sub-sequence.
223 static u32
nameseq_locate_subseq(struct name_seq
*nseq
, u32 instance
)
225 struct sub_seq
*sseqs
= nseq
->sseqs
;
227 int high
= nseq
->first_free
- 1;
230 while (low
<= high
) {
231 mid
= (low
+ high
) / 2;
232 if (instance
< sseqs
[mid
].lower
)
234 else if (instance
> sseqs
[mid
].upper
)
243 * tipc_nameseq_insert_publ -
246 static struct publication
*tipc_nameseq_insert_publ(struct name_seq
*nseq
,
247 u32 type
, u32 lower
, u32 upper
,
248 u32 scope
, u32 node
, u32 port
, u32 key
)
250 struct subscription
*s
;
251 struct subscription
*st
;
252 struct publication
*publ
;
253 struct sub_seq
*sseq
;
254 int created_subseq
= 0;
256 assert(nseq
->first_free
<= nseq
->alloc
);
257 sseq
= nameseq_find_subseq(nseq
, lower
);
258 dbg("nameseq_ins: for seq %x,<%u,%u>, found sseq %x\n",
259 nseq
, type
, lower
, sseq
);
262 /* Lower end overlaps existing entry => need an exact match */
264 if ((sseq
->lower
!= lower
) || (sseq
->upper
!= upper
)) {
265 warn("Overlapping publ <%u,%u,%u>\n", type
, lower
, upper
);
270 struct sub_seq
*freesseq
;
272 /* Find where lower end should be inserted */
274 inspos
= nameseq_locate_subseq(nseq
, lower
);
276 /* Fail if upper end overlaps into an existing entry */
278 if ((inspos
< nseq
->first_free
) &&
279 (upper
>= nseq
->sseqs
[inspos
].lower
)) {
280 warn("Overlapping publ <%u,%u,%u>\n", type
, lower
, upper
);
284 /* Ensure there is space for new sub-sequence */
286 if (nseq
->first_free
== nseq
->alloc
) {
287 struct sub_seq
*sseqs
= nseq
->sseqs
;
288 nseq
->sseqs
= tipc_subseq_alloc(nseq
->alloc
* 2);
289 if (nseq
->sseqs
!= NULL
) {
290 memcpy(nseq
->sseqs
, sseqs
,
291 nseq
->alloc
* sizeof (struct sub_seq
));
293 dbg("Allocated %u sseqs\n", nseq
->alloc
);
296 warn("Memory squeeze; failed to create sub-sequence\n");
300 dbg("Have %u sseqs for type %u\n", nseq
->alloc
, type
);
302 /* Insert new sub-sequence */
304 dbg("ins in pos %u, ff = %u\n", inspos
, nseq
->first_free
);
305 sseq
= &nseq
->sseqs
[inspos
];
306 freesseq
= &nseq
->sseqs
[nseq
->first_free
];
307 memmove(sseq
+ 1, sseq
, (freesseq
- sseq
) * sizeof (*sseq
));
308 memset(sseq
, 0, sizeof (*sseq
));
314 dbg("inserting (%u %u %u) from %x:%u into sseq %x(%u,%u) of seq %x\n",
315 type
, lower
, upper
, node
, port
, sseq
,
316 sseq
->lower
, sseq
->upper
, nseq
);
318 /* Insert a publication: */
320 publ
= publ_create(type
, lower
, upper
, scope
, node
, port
, key
);
323 dbg("inserting publ %x, node=%x publ->node=%x, subscr->node=%x\n",
324 publ
, node
, publ
->node
, publ
->subscr
.node
);
326 if (!sseq
->zone_list
)
327 sseq
->zone_list
= publ
->zone_list_next
= publ
;
329 publ
->zone_list_next
= sseq
->zone_list
->zone_list_next
;
330 sseq
->zone_list
->zone_list_next
= publ
;
333 if (in_own_cluster(node
)) {
334 if (!sseq
->cluster_list
)
335 sseq
->cluster_list
= publ
->cluster_list_next
= publ
;
337 publ
->cluster_list_next
=
338 sseq
->cluster_list
->cluster_list_next
;
339 sseq
->cluster_list
->cluster_list_next
= publ
;
343 if (node
== tipc_own_addr
) {
344 if (!sseq
->node_list
)
345 sseq
->node_list
= publ
->node_list_next
= publ
;
347 publ
->node_list_next
= sseq
->node_list
->node_list_next
;
348 sseq
->node_list
->node_list_next
= publ
;
353 * Any subscriptions waiting for notification?
355 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
356 dbg("calling report_overlap()\n");
357 tipc_subscr_report_overlap(s
,
369 * tipc_nameseq_remove_publ -
372 static struct publication
*tipc_nameseq_remove_publ(struct name_seq
*nseq
, u32 inst
,
373 u32 node
, u32 ref
, u32 key
)
375 struct publication
*publ
;
376 struct publication
*prev
;
377 struct sub_seq
*sseq
= nameseq_find_subseq(nseq
, inst
);
378 struct sub_seq
*free
;
379 struct subscription
*s
, *st
;
380 int removed_subseq
= 0;
387 warn("Withdraw unknown <%u,%u>?\n", nseq
->type
, inst
);
389 dbg("Dumping subseqs %x for %x, alloc = %u,ff=%u\n",
390 nseq
->sseqs
, nseq
, nseq
->alloc
,
392 for (i
= 0; i
< nseq
->first_free
; i
++) {
393 dbg("Subseq %u(%x): lower = %u,upper = %u\n",
394 i
, &nseq
->sseqs
[i
], nseq
->sseqs
[i
].lower
,
395 nseq
->sseqs
[i
].upper
);
399 dbg("nameseq_remove: seq: %x, sseq %x, <%u,%u> key %u\n",
400 nseq
, sseq
, nseq
->type
, inst
, key
);
402 prev
= sseq
->zone_list
;
403 publ
= sseq
->zone_list
->zone_list_next
;
404 while ((publ
->key
!= key
) || (publ
->ref
!= ref
) ||
405 (publ
->node
&& (publ
->node
!= node
))) {
407 publ
= publ
->zone_list_next
;
408 assert(prev
!= sseq
->zone_list
);
410 if (publ
!= sseq
->zone_list
)
411 prev
->zone_list_next
= publ
->zone_list_next
;
412 else if (publ
->zone_list_next
!= publ
) {
413 prev
->zone_list_next
= publ
->zone_list_next
;
414 sseq
->zone_list
= publ
->zone_list_next
;
416 sseq
->zone_list
= NULL
;
419 if (in_own_cluster(node
)) {
420 prev
= sseq
->cluster_list
;
421 publ
= sseq
->cluster_list
->cluster_list_next
;
422 while ((publ
->key
!= key
) || (publ
->ref
!= ref
) ||
423 (publ
->node
&& (publ
->node
!= node
))) {
425 publ
= publ
->cluster_list_next
;
426 assert(prev
!= sseq
->cluster_list
);
428 if (publ
!= sseq
->cluster_list
)
429 prev
->cluster_list_next
= publ
->cluster_list_next
;
430 else if (publ
->cluster_list_next
!= publ
) {
431 prev
->cluster_list_next
= publ
->cluster_list_next
;
432 sseq
->cluster_list
= publ
->cluster_list_next
;
434 sseq
->cluster_list
= NULL
;
438 if (node
== tipc_own_addr
) {
439 prev
= sseq
->node_list
;
440 publ
= sseq
->node_list
->node_list_next
;
441 while ((publ
->key
!= key
) || (publ
->ref
!= ref
) ||
442 (publ
->node
&& (publ
->node
!= node
))) {
444 publ
= publ
->node_list_next
;
445 assert(prev
!= sseq
->node_list
);
447 if (publ
!= sseq
->node_list
)
448 prev
->node_list_next
= publ
->node_list_next
;
449 else if (publ
->node_list_next
!= publ
) {
450 prev
->node_list_next
= publ
->node_list_next
;
451 sseq
->node_list
= publ
->node_list_next
;
453 sseq
->node_list
= NULL
;
456 assert(!publ
->node
|| (publ
->node
== node
));
457 assert(publ
->ref
== ref
);
458 assert(publ
->key
== key
);
461 * Contract subseq list if no more publications:
463 if (!sseq
->node_list
&& !sseq
->cluster_list
&& !sseq
->zone_list
) {
464 free
= &nseq
->sseqs
[nseq
->first_free
--];
465 memmove(sseq
, sseq
+ 1, (free
- (sseq
+ 1)) * sizeof (*sseq
));
470 * Any subscriptions waiting ?
472 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
473 tipc_subscr_report_overlap(s
,
485 * tipc_nameseq_subscribe: attach a subscription, and issue
486 * the prescribed number of events if there is any sub-
487 * sequence overlapping with the requested sequence
490 void tipc_nameseq_subscribe(struct name_seq
*nseq
, struct subscription
*s
)
492 struct sub_seq
*sseq
= nseq
->sseqs
;
494 list_add(&s
->nameseq_list
, &nseq
->subscriptions
);
499 while (sseq
!= &nseq
->sseqs
[nseq
->first_free
]) {
500 struct publication
*zl
= sseq
->zone_list
;
501 if (zl
&& tipc_subscr_overlap(s
,sseq
->lower
,sseq
->upper
)) {
502 struct publication
*crs
= zl
;
506 tipc_subscr_report_overlap(s
,
514 crs
= crs
->zone_list_next
;
521 static struct name_seq
*nametbl_find_seq(u32 type
)
523 struct hlist_head
*seq_head
;
524 struct hlist_node
*seq_node
;
527 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n",
528 type
, ntohl(type
), type
, table
.types
, hash(type
));
530 seq_head
= &table
.types
[hash(type
)];
531 hlist_for_each_entry(ns
, seq_node
, seq_head
, ns_list
) {
532 if (ns
->type
== type
) {
533 dbg("found %x\n", ns
);
541 struct publication
*tipc_nametbl_insert_publ(u32 type
, u32 lower
, u32 upper
,
542 u32 scope
, u32 node
, u32 port
, u32 key
)
544 struct name_seq
*seq
= nametbl_find_seq(type
);
546 dbg("ins_publ: <%u,%x,%x> found %x\n", type
, lower
, upper
, seq
);
548 warn("Failed to publish illegal <%u,%u,%u>\n",
553 dbg("Publishing <%u,%u,%u> from %x\n", type
, lower
, upper
, node
);
555 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
556 dbg("tipc_nametbl_insert_publ: created %x\n", seq
);
561 assert(seq
->type
== type
);
562 return tipc_nameseq_insert_publ(seq
, type
, lower
, upper
,
563 scope
, node
, port
, key
);
566 struct publication
*tipc_nametbl_remove_publ(u32 type
, u32 lower
,
567 u32 node
, u32 ref
, u32 key
)
569 struct publication
*publ
;
570 struct name_seq
*seq
= nametbl_find_seq(type
);
575 dbg("Withdrawing <%u,%u> from %x\n", type
, lower
, node
);
576 publ
= tipc_nameseq_remove_publ(seq
, lower
, node
, ref
, key
);
578 if (!seq
->first_free
&& list_empty(&seq
->subscriptions
)) {
579 hlist_del_init(&seq
->ns_list
);
587 * tipc_nametbl_translate(): Translate tipc_name -> tipc_portid.
588 * Very time-critical.
590 * Note: on entry 'destnode' is the search domain used during translation;
591 * on exit it passes back the node address of the matching port (if any)
594 u32
tipc_nametbl_translate(u32 type
, u32 instance
, u32
*destnode
)
596 struct sub_seq
*sseq
;
597 struct publication
*publ
= NULL
;
598 struct name_seq
*seq
;
601 if (!in_scope(*destnode
, tipc_own_addr
))
604 read_lock_bh(&tipc_nametbl_lock
);
605 seq
= nametbl_find_seq(type
);
608 sseq
= nameseq_find_subseq(seq
, instance
);
611 spin_lock_bh(&seq
->lock
);
613 /* Closest-First Algorithm: */
614 if (likely(!*destnode
)) {
615 publ
= sseq
->node_list
;
617 sseq
->node_list
= publ
->node_list_next
;
620 *destnode
= publ
->node
;
621 spin_unlock_bh(&seq
->lock
);
622 read_unlock_bh(&tipc_nametbl_lock
);
625 publ
= sseq
->cluster_list
;
627 sseq
->cluster_list
= publ
->cluster_list_next
;
630 publ
= sseq
->zone_list
;
632 sseq
->zone_list
= publ
->zone_list_next
;
637 /* Round-Robin Algorithm: */
638 else if (*destnode
== tipc_own_addr
) {
639 publ
= sseq
->node_list
;
641 sseq
->node_list
= publ
->node_list_next
;
644 } else if (in_own_cluster(*destnode
)) {
645 publ
= sseq
->cluster_list
;
647 sseq
->cluster_list
= publ
->cluster_list_next
;
651 publ
= sseq
->zone_list
;
653 sseq
->zone_list
= publ
->zone_list_next
;
657 spin_unlock_bh(&seq
->lock
);
660 read_unlock_bh(&tipc_nametbl_lock
);
665 * tipc_nametbl_mc_translate - find multicast destinations
667 * Creates list of all local ports that overlap the given multicast address;
668 * also determines if any off-node ports overlap.
670 * Note: Publications with a scope narrower than 'limit' are ignored.
671 * (i.e. local node-scope publications mustn't receive messages arriving
672 * from another node, even if the multcast link brought it here)
674 * Returns non-zero if any off-node ports overlap
677 int tipc_nametbl_mc_translate(u32 type
, u32 lower
, u32 upper
, u32 limit
,
678 struct port_list
*dports
)
680 struct name_seq
*seq
;
681 struct sub_seq
*sseq
;
682 struct sub_seq
*sseq_stop
;
685 read_lock_bh(&tipc_nametbl_lock
);
686 seq
= nametbl_find_seq(type
);
690 spin_lock_bh(&seq
->lock
);
692 sseq
= seq
->sseqs
+ nameseq_locate_subseq(seq
, lower
);
693 sseq_stop
= seq
->sseqs
+ seq
->first_free
;
694 for (; sseq
!= sseq_stop
; sseq
++) {
695 struct publication
*publ
;
697 if (sseq
->lower
> upper
)
699 publ
= sseq
->cluster_list
;
700 if (publ
&& (publ
->scope
<= limit
))
702 if (publ
->node
== tipc_own_addr
)
703 tipc_port_list_add(dports
, publ
->ref
);
706 publ
= publ
->cluster_list_next
;
707 } while (publ
!= sseq
->cluster_list
);
710 spin_unlock_bh(&seq
->lock
);
712 read_unlock_bh(&tipc_nametbl_lock
);
717 * tipc_nametbl_publish_rsv - publish port name using a reserved name type
720 int tipc_nametbl_publish_rsv(u32 ref
, unsigned int scope
,
721 struct tipc_name_seq
const *seq
)
725 atomic_inc(&rsv_publ_ok
);
726 res
= tipc_publish(ref
, scope
, seq
);
727 atomic_dec(&rsv_publ_ok
);
732 * tipc_nametbl_publish - add name publication to network name tables
735 struct publication
*tipc_nametbl_publish(u32 type
, u32 lower
, u32 upper
,
736 u32 scope
, u32 port_ref
, u32 key
)
738 struct publication
*publ
;
740 if (table
.local_publ_count
>= tipc_max_publications
) {
741 warn("Failed publish: max %u local publication\n",
742 tipc_max_publications
);
745 if ((type
< TIPC_RESERVED_TYPES
) && !atomic_read(&rsv_publ_ok
)) {
746 warn("Failed to publish reserved name <%u,%u,%u>\n",
751 write_lock_bh(&tipc_nametbl_lock
);
752 table
.local_publ_count
++;
753 publ
= tipc_nametbl_insert_publ(type
, lower
, upper
, scope
,
754 tipc_own_addr
, port_ref
, key
);
755 if (publ
&& (scope
!= TIPC_NODE_SCOPE
)) {
756 tipc_named_publish(publ
);
758 write_unlock_bh(&tipc_nametbl_lock
);
763 * tipc_nametbl_withdraw - withdraw name publication from network name tables
766 int tipc_nametbl_withdraw(u32 type
, u32 lower
, u32 ref
, u32 key
)
768 struct publication
*publ
;
770 dbg("tipc_nametbl_withdraw:<%d,%d,%d>\n", type
, lower
, key
);
771 write_lock_bh(&tipc_nametbl_lock
);
772 publ
= tipc_nametbl_remove_publ(type
, lower
, tipc_own_addr
, ref
, key
);
774 table
.local_publ_count
--;
775 if (publ
->scope
!= TIPC_NODE_SCOPE
)
776 tipc_named_withdraw(publ
);
777 write_unlock_bh(&tipc_nametbl_lock
);
778 list_del_init(&publ
->pport_list
);
782 write_unlock_bh(&tipc_nametbl_lock
);
787 * tipc_nametbl_subscribe - add a subscription object to the name table
791 tipc_nametbl_subscribe(struct subscription
*s
)
793 u32 type
= s
->seq
.type
;
794 struct name_seq
*seq
;
796 write_lock_bh(&tipc_nametbl_lock
);
797 seq
= nametbl_find_seq(type
);
799 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
802 spin_lock_bh(&seq
->lock
);
803 dbg("tipc_nametbl_subscribe:found %x for <%u,%u,%u>\n",
804 seq
, type
, s
->seq
.lower
, s
->seq
.upper
);
805 assert(seq
->type
== type
);
806 tipc_nameseq_subscribe(seq
, s
);
807 spin_unlock_bh(&seq
->lock
);
809 write_unlock_bh(&tipc_nametbl_lock
);
813 * tipc_nametbl_unsubscribe - remove a subscription object from name table
817 tipc_nametbl_unsubscribe(struct subscription
*s
)
819 struct name_seq
*seq
;
821 write_lock_bh(&tipc_nametbl_lock
);
822 seq
= nametbl_find_seq(s
->seq
.type
);
824 spin_lock_bh(&seq
->lock
);
825 list_del_init(&s
->nameseq_list
);
826 spin_unlock_bh(&seq
->lock
);
827 if ((seq
->first_free
== 0) && list_empty(&seq
->subscriptions
)) {
828 hlist_del_init(&seq
->ns_list
);
833 write_unlock_bh(&tipc_nametbl_lock
);
838 * subseq_list: print specified sub-sequence contents into the given buffer
841 static void subseq_list(struct sub_seq
*sseq
, struct print_buf
*buf
, u32 depth
,
846 struct publication
*publ
= sseq
->zone_list
;
848 tipc_printf(buf
, "%-10u %-10u ", sseq
->lower
, sseq
->upper
);
850 if (depth
== 2 || !publ
) {
851 tipc_printf(buf
, "\n");
856 sprintf (portIdStr
, "<%u.%u.%u:%u>",
857 tipc_zone(publ
->node
), tipc_cluster(publ
->node
),
858 tipc_node(publ
->node
), publ
->ref
);
859 tipc_printf(buf
, "%-26s ", portIdStr
);
861 if (publ
->node
!= tipc_own_addr
)
863 else if (publ
->scope
== TIPC_NODE_SCOPE
)
865 else if (publ
->scope
== TIPC_CLUSTER_SCOPE
)
866 scopeStr
= "cluster";
869 tipc_printf(buf
, "%-10u %s", publ
->key
, scopeStr
);
872 publ
= publ
->zone_list_next
;
873 if (publ
== sseq
->zone_list
)
876 tipc_printf(buf
, "\n%33s", " ");
879 tipc_printf(buf
, "\n");
883 * nameseq_list: print specified name sequence contents into the given buffer
886 static void nameseq_list(struct name_seq
*seq
, struct print_buf
*buf
, u32 depth
,
887 u32 type
, u32 lowbound
, u32 upbound
, u32 index
)
889 struct sub_seq
*sseq
;
892 sprintf(typearea
, "%-10u", seq
->type
);
895 tipc_printf(buf
, "%s\n", typearea
);
899 for (sseq
= seq
->sseqs
; sseq
!= &seq
->sseqs
[seq
->first_free
]; sseq
++) {
900 if ((lowbound
<= sseq
->upper
) && (upbound
>= sseq
->lower
)) {
901 tipc_printf(buf
, "%s ", typearea
);
902 subseq_list(sseq
, buf
, depth
, index
);
903 sprintf(typearea
, "%10s", " ");
909 * nametbl_header - print name table header into the given buffer
912 static void nametbl_header(struct print_buf
*buf
, u32 depth
)
914 tipc_printf(buf
, "Type ");
917 tipc_printf(buf
, "Lower Upper ");
919 tipc_printf(buf
, "Port Identity ");
921 tipc_printf(buf
, "Publication");
923 tipc_printf(buf
, "\n-----------");
926 tipc_printf(buf
, "--------------------- ");
928 tipc_printf(buf
, "-------------------------- ");
930 tipc_printf(buf
, "------------------");
932 tipc_printf(buf
, "\n");
936 * nametbl_list - print specified name table contents into the given buffer
939 static void nametbl_list(struct print_buf
*buf
, u32 depth_info
,
940 u32 type
, u32 lowbound
, u32 upbound
)
942 struct hlist_head
*seq_head
;
943 struct hlist_node
*seq_node
;
944 struct name_seq
*seq
;
949 all_types
= (depth_info
& TIPC_NTQ_ALLTYPES
);
950 depth
= (depth_info
& ~TIPC_NTQ_ALLTYPES
);
956 /* display all entries in name table to specified depth */
957 nametbl_header(buf
, depth
);
960 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
961 seq_head
= &table
.types
[i
];
962 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
963 nameseq_list(seq
, buf
, depth
, seq
->type
,
964 lowbound
, upbound
, i
);
968 /* display only the sequence that matches the specified type */
969 if (upbound
< lowbound
) {
970 tipc_printf(buf
, "invalid name sequence specified\n");
973 nametbl_header(buf
, depth
);
975 seq_head
= &table
.types
[i
];
976 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
977 if (seq
->type
== type
) {
978 nameseq_list(seq
, buf
, depth
, type
,
979 lowbound
, upbound
, i
);
987 void tipc_nametbl_print(struct print_buf
*buf
, const char *str
)
989 tipc_printf(buf
, str
);
990 read_lock_bh(&tipc_nametbl_lock
);
991 nametbl_list(buf
, 0, 0, 0, 0);
992 read_unlock_bh(&tipc_nametbl_lock
);
996 #define MAX_NAME_TBL_QUERY 32768
998 struct sk_buff
*tipc_nametbl_get(const void *req_tlv_area
, int req_tlv_space
)
1000 struct sk_buff
*buf
;
1001 struct tipc_name_table_query
*argv
;
1002 struct tlv_desc
*rep_tlv
;
1006 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_NAME_TBL_QUERY
))
1007 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
1009 buf
= tipc_cfg_reply_alloc(TLV_SPACE(MAX_NAME_TBL_QUERY
));
1013 rep_tlv
= (struct tlv_desc
*)buf
->data
;
1014 tipc_printbuf_init(&b
, TLV_DATA(rep_tlv
), MAX_NAME_TBL_QUERY
);
1015 argv
= (struct tipc_name_table_query
*)TLV_DATA(req_tlv_area
);
1016 read_lock_bh(&tipc_nametbl_lock
);
1017 nametbl_list(&b
, ntohl(argv
->depth
), ntohl(argv
->type
),
1018 ntohl(argv
->lowbound
), ntohl(argv
->upbound
));
1019 read_unlock_bh(&tipc_nametbl_lock
);
1020 str_len
= tipc_printbuf_validate(&b
);
1022 skb_put(buf
, TLV_SPACE(str_len
));
1023 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
1029 void tipc_nametbl_dump(void)
1031 nametbl_list(TIPC_CONS
, 0, 0, 0, 0);
1035 int tipc_nametbl_init(void)
1037 int array_size
= sizeof(struct hlist_head
) * tipc_nametbl_size
;
1039 table
.types
= (struct hlist_head
*)kmalloc(array_size
, GFP_ATOMIC
);
1043 write_lock_bh(&tipc_nametbl_lock
);
1044 memset(table
.types
, 0, array_size
);
1045 table
.local_publ_count
= 0;
1046 write_unlock_bh(&tipc_nametbl_lock
);
1050 void tipc_nametbl_stop(void)
1052 struct hlist_head
*seq_head
;
1053 struct hlist_node
*seq_node
;
1054 struct hlist_node
*tmp
;
1055 struct name_seq
*seq
;
1061 write_lock_bh(&tipc_nametbl_lock
);
1062 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
1063 seq_head
= &table
.types
[i
];
1064 hlist_for_each_entry_safe(seq
, seq_node
, tmp
, seq_head
, ns_list
) {
1065 struct sub_seq
*sseq
= seq
->sseqs
;
1067 for (; sseq
!= &seq
->sseqs
[seq
->first_free
]; sseq
++) {
1068 struct publication
*publ
= sseq
->zone_list
;
1071 struct publication
*next
=
1072 publ
->zone_list_next
;
1076 while (publ
!= sseq
->zone_list
);
1082 write_unlock_bh(&tipc_nametbl_lock
);