diff options
Diffstat (limited to 'net/tipc/name_table.c')
-rw-r--r-- | net/tipc/name_table.c | 127 |
1 files changed, 30 insertions, 97 deletions
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 8ba79620db3f..205ed4a4e186 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
@@ -36,15 +36,10 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "dbg.h" | ||
40 | #include "name_table.h" | 39 | #include "name_table.h" |
41 | #include "name_distr.h" | 40 | #include "name_distr.h" |
42 | #include "addr.h" | ||
43 | #include "node_subscr.h" | ||
44 | #include "subscr.h" | 41 | #include "subscr.h" |
45 | #include "port.h" | 42 | #include "port.h" |
46 | #include "cluster.h" | ||
47 | #include "bcast.h" | ||
48 | 43 | ||
49 | static int tipc_nametbl_size = 1024; /* must be a power of 2 */ | 44 | static int tipc_nametbl_size = 1024; /* must be a power of 2 */ |
50 | 45 | ||
@@ -109,14 +104,14 @@ struct name_table { | |||
109 | u32 local_publ_count; | 104 | u32 local_publ_count; |
110 | }; | 105 | }; |
111 | 106 | ||
112 | static struct name_table table = { NULL } ; | 107 | static struct name_table table; |
113 | static atomic_t rsv_publ_ok = ATOMIC_INIT(0); | 108 | static atomic_t rsv_publ_ok = ATOMIC_INIT(0); |
114 | DEFINE_RWLOCK(tipc_nametbl_lock); | 109 | DEFINE_RWLOCK(tipc_nametbl_lock); |
115 | 110 | ||
116 | 111 | ||
117 | static int hash(int x) | 112 | static int hash(int x) |
118 | { | 113 | { |
119 | return(x & (tipc_nametbl_size - 1)); | 114 | return x & (tipc_nametbl_size - 1); |
120 | } | 115 | } |
121 | 116 | ||
122 | /** | 117 | /** |
@@ -177,8 +172,6 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea | |||
177 | spin_lock_init(&nseq->lock); | 172 | spin_lock_init(&nseq->lock); |
178 | nseq->type = type; | 173 | nseq->type = type; |
179 | nseq->sseqs = sseq; | 174 | nseq->sseqs = sseq; |
180 | dbg("tipc_nameseq_create(): nseq = %p, type %u, ssseqs %p, ff: %u\n", | ||
181 | nseq, type, nseq->sseqs, nseq->first_free); | ||
182 | nseq->alloc = 1; | 175 | nseq->alloc = 1; |
183 | INIT_HLIST_NODE(&nseq->ns_list); | 176 | INIT_HLIST_NODE(&nseq->ns_list); |
184 | INIT_LIST_HEAD(&nseq->subscriptions); | 177 | INIT_LIST_HEAD(&nseq->subscriptions); |
@@ -256,8 +249,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
256 | int created_subseq = 0; | 249 | int created_subseq = 0; |
257 | 250 | ||
258 | sseq = nameseq_find_subseq(nseq, lower); | 251 | sseq = nameseq_find_subseq(nseq, lower); |
259 | dbg("nameseq_ins: for seq %p, {%u,%u}, found sseq %p\n", | ||
260 | nseq, type, lower, sseq); | ||
261 | if (sseq) { | 252 | if (sseq) { |
262 | 253 | ||
263 | /* Lower end overlaps existing entry => need an exact match */ | 254 | /* Lower end overlaps existing entry => need an exact match */ |
@@ -294,38 +285,30 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
294 | type, lower, upper); | 285 | type, lower, upper); |
295 | return NULL; | 286 | return NULL; |
296 | } | 287 | } |
297 | dbg("Allocated %u more sseqs\n", nseq->alloc); | ||
298 | memcpy(sseqs, nseq->sseqs, | 288 | memcpy(sseqs, nseq->sseqs, |
299 | nseq->alloc * sizeof(struct sub_seq)); | 289 | nseq->alloc * sizeof(struct sub_seq)); |
300 | kfree(nseq->sseqs); | 290 | kfree(nseq->sseqs); |
301 | nseq->sseqs = sseqs; | 291 | nseq->sseqs = sseqs; |
302 | nseq->alloc *= 2; | 292 | nseq->alloc *= 2; |
303 | } | 293 | } |
304 | dbg("Have %u sseqs for type %u\n", nseq->alloc, type); | ||
305 | 294 | ||
306 | /* Insert new sub-sequence */ | 295 | /* Insert new sub-sequence */ |
307 | 296 | ||
308 | dbg("ins in pos %u, ff = %u\n", inspos, nseq->first_free); | ||
309 | sseq = &nseq->sseqs[inspos]; | 297 | sseq = &nseq->sseqs[inspos]; |
310 | freesseq = &nseq->sseqs[nseq->first_free]; | 298 | freesseq = &nseq->sseqs[nseq->first_free]; |
311 | memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof (*sseq)); | 299 | memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq)); |
312 | memset(sseq, 0, sizeof (*sseq)); | 300 | memset(sseq, 0, sizeof(*sseq)); |
313 | nseq->first_free++; | 301 | nseq->first_free++; |
314 | sseq->lower = lower; | 302 | sseq->lower = lower; |
315 | sseq->upper = upper; | 303 | sseq->upper = upper; |
316 | created_subseq = 1; | 304 | created_subseq = 1; |
317 | } | 305 | } |
318 | dbg("inserting {%u,%u,%u} from <0x%x:%u> into sseq %p(%u,%u) of seq %p\n", | ||
319 | type, lower, upper, node, port, sseq, | ||
320 | sseq->lower, sseq->upper, nseq); | ||
321 | 306 | ||
322 | /* Insert a publication: */ | 307 | /* Insert a publication: */ |
323 | 308 | ||
324 | publ = publ_create(type, lower, upper, scope, node, port, key); | 309 | publ = publ_create(type, lower, upper, scope, node, port, key); |
325 | if (!publ) | 310 | if (!publ) |
326 | return NULL; | 311 | return NULL; |
327 | dbg("inserting publ %p, node=0x%x publ->node=0x%x, subscr->node=%p\n", | ||
328 | publ, node, publ->node, publ->subscr.node); | ||
329 | 312 | ||
330 | sseq->zone_list_size++; | 313 | sseq->zone_list_size++; |
331 | if (!sseq->zone_list) | 314 | if (!sseq->zone_list) |
@@ -360,7 +343,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
360 | * Any subscriptions waiting for notification? | 343 | * Any subscriptions waiting for notification? |
361 | */ | 344 | */ |
362 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { | 345 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
363 | dbg("calling report_overlap()\n"); | ||
364 | tipc_subscr_report_overlap(s, | 346 | tipc_subscr_report_overlap(s, |
365 | publ->lower, | 347 | publ->lower, |
366 | publ->upper, | 348 | publ->upper, |
@@ -398,9 +380,6 @@ static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 i | |||
398 | if (!sseq) | 380 | if (!sseq) |
399 | return NULL; | 381 | return NULL; |
400 | 382 | ||
401 | dbg("tipc_nameseq_remove_publ: seq: %p, sseq %p, {%u,%u}, key %u\n", | ||
402 | nseq, sseq, nseq->type, inst, key); | ||
403 | |||
404 | /* Remove publication from zone scope list */ | 383 | /* Remove publication from zone scope list */ |
405 | 384 | ||
406 | prev = sseq->zone_list; | 385 | prev = sseq->zone_list; |
@@ -492,7 +471,7 @@ end_node: | |||
492 | 471 | ||
493 | if (!sseq->zone_list) { | 472 | if (!sseq->zone_list) { |
494 | free = &nseq->sseqs[nseq->first_free--]; | 473 | free = &nseq->sseqs[nseq->first_free--]; |
495 | memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof (*sseq)); | 474 | memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq)); |
496 | removed_subseq = 1; | 475 | removed_subseq = 1; |
497 | } | 476 | } |
498 | 477 | ||
@@ -528,7 +507,7 @@ static void tipc_nameseq_subscribe(struct name_seq *nseq, struct subscription *s | |||
528 | 507 | ||
529 | while (sseq != &nseq->sseqs[nseq->first_free]) { | 508 | while (sseq != &nseq->sseqs[nseq->first_free]) { |
530 | struct publication *zl = sseq->zone_list; | 509 | struct publication *zl = sseq->zone_list; |
531 | if (zl && tipc_subscr_overlap(s,sseq->lower,sseq->upper)) { | 510 | if (zl && tipc_subscr_overlap(s, sseq->lower, sseq->upper)) { |
532 | struct publication *crs = zl; | 511 | struct publication *crs = zl; |
533 | int must_report = 1; | 512 | int must_report = 1; |
534 | 513 | ||
@@ -554,15 +533,10 @@ static struct name_seq *nametbl_find_seq(u32 type) | |||
554 | struct hlist_node *seq_node; | 533 | struct hlist_node *seq_node; |
555 | struct name_seq *ns; | 534 | struct name_seq *ns; |
556 | 535 | ||
557 | dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n", | ||
558 | type, htonl(type), type, table.types, hash(type)); | ||
559 | |||
560 | seq_head = &table.types[hash(type)]; | 536 | seq_head = &table.types[hash(type)]; |
561 | hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { | 537 | hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { |
562 | if (ns->type == type) { | 538 | if (ns->type == type) |
563 | dbg("found %p\n", ns); | ||
564 | return ns; | 539 | return ns; |
565 | } | ||
566 | } | 540 | } |
567 | 541 | ||
568 | return NULL; | 542 | return NULL; |
@@ -573,18 +547,14 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | |||
573 | { | 547 | { |
574 | struct name_seq *seq = nametbl_find_seq(type); | 548 | struct name_seq *seq = nametbl_find_seq(type); |
575 | 549 | ||
576 | dbg("tipc_nametbl_insert_publ: {%u,%u,%u} found %p\n", type, lower, upper, seq); | ||
577 | if (lower > upper) { | 550 | if (lower > upper) { |
578 | warn("Failed to publish illegal {%u,%u,%u}\n", | 551 | warn("Failed to publish illegal {%u,%u,%u}\n", |
579 | type, lower, upper); | 552 | type, lower, upper); |
580 | return NULL; | 553 | return NULL; |
581 | } | 554 | } |
582 | 555 | ||
583 | dbg("Publishing {%u,%u,%u} from 0x%x\n", type, lower, upper, node); | 556 | if (!seq) |
584 | if (!seq) { | ||
585 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); | 557 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); |
586 | dbg("tipc_nametbl_insert_publ: created %p\n", seq); | ||
587 | } | ||
588 | if (!seq) | 558 | if (!seq) |
589 | return NULL; | 559 | return NULL; |
590 | 560 | ||
@@ -601,7 +571,6 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | |||
601 | if (!seq) | 571 | if (!seq) |
602 | return NULL; | 572 | return NULL; |
603 | 573 | ||
604 | dbg("Withdrawing {%u,%u} from 0x%x\n", type, lower, node); | ||
605 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); | 574 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); |
606 | 575 | ||
607 | if (!seq->first_free && list_empty(&seq->subscriptions)) { | 576 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
@@ -613,8 +582,7 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | |||
613 | } | 582 | } |
614 | 583 | ||
615 | /* | 584 | /* |
616 | * tipc_nametbl_translate(): Translate tipc_name -> tipc_portid. | 585 | * tipc_nametbl_translate - translate name to port id |
617 | * Very time-critical. | ||
618 | * | 586 | * |
619 | * Note: on entry 'destnode' is the search domain used during translation; | 587 | * Note: on entry 'destnode' is the search domain used during translation; |
620 | * on exit it passes back the node address of the matching port (if any) | 588 | * on exit it passes back the node address of the matching port (if any) |
@@ -685,7 +653,6 @@ found: | |||
685 | } | 653 | } |
686 | spin_unlock_bh(&seq->lock); | 654 | spin_unlock_bh(&seq->lock); |
687 | not_found: | 655 | not_found: |
688 | *destnode = 0; | ||
689 | read_unlock_bh(&tipc_nametbl_lock); | 656 | read_unlock_bh(&tipc_nametbl_lock); |
690 | return 0; | 657 | return 0; |
691 | } | 658 | } |
@@ -784,9 +751,8 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | |||
784 | table.local_publ_count++; | 751 | table.local_publ_count++; |
785 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, | 752 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, |
786 | tipc_own_addr, port_ref, key); | 753 | tipc_own_addr, port_ref, key); |
787 | if (publ && (scope != TIPC_NODE_SCOPE)) { | 754 | if (publ && (scope != TIPC_NODE_SCOPE)) |
788 | tipc_named_publish(publ); | 755 | tipc_named_publish(publ); |
789 | } | ||
790 | write_unlock_bh(&tipc_nametbl_lock); | 756 | write_unlock_bh(&tipc_nametbl_lock); |
791 | return publ; | 757 | return publ; |
792 | } | 758 | } |
@@ -799,7 +765,6 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
799 | { | 765 | { |
800 | struct publication *publ; | 766 | struct publication *publ; |
801 | 767 | ||
802 | dbg("tipc_nametbl_withdraw: {%u,%u}, key=%u\n", type, lower, key); | ||
803 | write_lock_bh(&tipc_nametbl_lock); | 768 | write_lock_bh(&tipc_nametbl_lock); |
804 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); | 769 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); |
805 | if (likely(publ)) { | 770 | if (likely(publ)) { |
@@ -829,13 +794,10 @@ void tipc_nametbl_subscribe(struct subscription *s) | |||
829 | 794 | ||
830 | write_lock_bh(&tipc_nametbl_lock); | 795 | write_lock_bh(&tipc_nametbl_lock); |
831 | seq = nametbl_find_seq(type); | 796 | seq = nametbl_find_seq(type); |
832 | if (!seq) { | 797 | if (!seq) |
833 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); | 798 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); |
834 | } | 799 | if (seq) { |
835 | if (seq){ | ||
836 | spin_lock_bh(&seq->lock); | 800 | spin_lock_bh(&seq->lock); |
837 | dbg("tipc_nametbl_subscribe:found %p for {%u,%u,%u}\n", | ||
838 | seq, type, s->seq.lower, s->seq.upper); | ||
839 | tipc_nameseq_subscribe(seq, s); | 801 | tipc_nameseq_subscribe(seq, s); |
840 | spin_unlock_bh(&seq->lock); | 802 | spin_unlock_bh(&seq->lock); |
841 | } else { | 803 | } else { |
@@ -855,7 +817,7 @@ void tipc_nametbl_unsubscribe(struct subscription *s) | |||
855 | 817 | ||
856 | write_lock_bh(&tipc_nametbl_lock); | 818 | write_lock_bh(&tipc_nametbl_lock); |
857 | seq = nametbl_find_seq(s->seq.type); | 819 | seq = nametbl_find_seq(s->seq.type); |
858 | if (seq != NULL){ | 820 | if (seq != NULL) { |
859 | spin_lock_bh(&seq->lock); | 821 | spin_lock_bh(&seq->lock); |
860 | list_del_init(&s->nameseq_list); | 822 | list_del_init(&s->nameseq_list); |
861 | spin_unlock_bh(&seq->lock); | 823 | spin_unlock_bh(&seq->lock); |
@@ -877,7 +839,7 @@ static void subseq_list(struct sub_seq *sseq, struct print_buf *buf, u32 depth, | |||
877 | u32 index) | 839 | u32 index) |
878 | { | 840 | { |
879 | char portIdStr[27]; | 841 | char portIdStr[27]; |
880 | char *scopeStr; | 842 | const char *scope_str[] = {"", " zone", " cluster", " node"}; |
881 | struct publication *publ = sseq->zone_list; | 843 | struct publication *publ = sseq->zone_list; |
882 | 844 | ||
883 | tipc_printf(buf, "%-10u %-10u ", sseq->lower, sseq->upper); | 845 | tipc_printf(buf, "%-10u %-10u ", sseq->lower, sseq->upper); |
@@ -888,20 +850,13 @@ static void subseq_list(struct sub_seq *sseq, struct print_buf *buf, u32 depth, | |||
888 | } | 850 | } |
889 | 851 | ||
890 | do { | 852 | do { |
891 | sprintf (portIdStr, "<%u.%u.%u:%u>", | 853 | sprintf(portIdStr, "<%u.%u.%u:%u>", |
892 | tipc_zone(publ->node), tipc_cluster(publ->node), | 854 | tipc_zone(publ->node), tipc_cluster(publ->node), |
893 | tipc_node(publ->node), publ->ref); | 855 | tipc_node(publ->node), publ->ref); |
894 | tipc_printf(buf, "%-26s ", portIdStr); | 856 | tipc_printf(buf, "%-26s ", portIdStr); |
895 | if (depth > 3) { | 857 | if (depth > 3) { |
896 | if (publ->node != tipc_own_addr) | 858 | tipc_printf(buf, "%-10u %s", publ->key, |
897 | scopeStr = ""; | 859 | scope_str[publ->scope]); |
898 | else if (publ->scope == TIPC_NODE_SCOPE) | ||
899 | scopeStr = "node"; | ||
900 | else if (publ->scope == TIPC_CLUSTER_SCOPE) | ||
901 | scopeStr = "cluster"; | ||
902 | else | ||
903 | scopeStr = "zone"; | ||
904 | tipc_printf(buf, "%-10u %s", publ->key, scopeStr); | ||
905 | } | 860 | } |
906 | 861 | ||
907 | publ = publ->zone_list_next; | 862 | publ = publ->zone_list_next; |
@@ -951,24 +906,19 @@ static void nameseq_list(struct name_seq *seq, struct print_buf *buf, u32 depth, | |||
951 | 906 | ||
952 | static void nametbl_header(struct print_buf *buf, u32 depth) | 907 | static void nametbl_header(struct print_buf *buf, u32 depth) |
953 | { | 908 | { |
954 | tipc_printf(buf, "Type "); | 909 | const char *header[] = { |
955 | 910 | "Type ", | |
956 | if (depth > 1) | 911 | "Lower Upper ", |
957 | tipc_printf(buf, "Lower Upper "); | 912 | "Port Identity ", |
958 | if (depth > 2) | 913 | "Publication Scope" |
959 | tipc_printf(buf, "Port Identity "); | 914 | }; |
960 | if (depth > 3) | 915 | |
961 | tipc_printf(buf, "Publication"); | 916 | int i; |
962 | 917 | ||
963 | tipc_printf(buf, "\n-----------"); | 918 | if (depth > 4) |
964 | 919 | depth = 4; | |
965 | if (depth > 1) | 920 | for (i = 0; i < depth; i++) |
966 | tipc_printf(buf, "--------------------- "); | 921 | tipc_printf(buf, header[i]); |
967 | if (depth > 2) | ||
968 | tipc_printf(buf, "-------------------------- "); | ||
969 | if (depth > 3) | ||
970 | tipc_printf(buf, "------------------"); | ||
971 | |||
972 | tipc_printf(buf, "\n"); | 922 | tipc_printf(buf, "\n"); |
973 | } | 923 | } |
974 | 924 | ||
@@ -1023,16 +973,6 @@ static void nametbl_list(struct print_buf *buf, u32 depth_info, | |||
1023 | } | 973 | } |
1024 | } | 974 | } |
1025 | 975 | ||
1026 | #if 0 | ||
1027 | void tipc_nametbl_print(struct print_buf *buf, const char *str) | ||
1028 | { | ||
1029 | tipc_printf(buf, str); | ||
1030 | read_lock_bh(&tipc_nametbl_lock); | ||
1031 | nametbl_list(buf, 0, 0, 0, 0); | ||
1032 | read_unlock_bh(&tipc_nametbl_lock); | ||
1033 | } | ||
1034 | #endif | ||
1035 | |||
1036 | #define MAX_NAME_TBL_QUERY 32768 | 976 | #define MAX_NAME_TBL_QUERY 32768 |
1037 | 977 | ||
1038 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | 978 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) |
@@ -1065,13 +1005,6 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
1065 | return buf; | 1005 | return buf; |
1066 | } | 1006 | } |
1067 | 1007 | ||
1068 | #if 0 | ||
1069 | void tipc_nametbl_dump(void) | ||
1070 | { | ||
1071 | nametbl_list(TIPC_CONS, 0, 0, 0, 0); | ||
1072 | } | ||
1073 | #endif | ||
1074 | |||
1075 | int tipc_nametbl_init(void) | 1008 | int tipc_nametbl_init(void) |
1076 | { | 1009 | { |
1077 | table.types = kcalloc(tipc_nametbl_size, sizeof(struct hlist_head), | 1010 | table.types = kcalloc(tipc_nametbl_size, sizeof(struct hlist_head), |