diff options
Diffstat (limited to 'net/tipc/name_table.c')
| -rw-r--r-- | net/tipc/name_table.c | 382 |
1 files changed, 287 insertions, 95 deletions
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 9d7d37d95187..c8df0223371a 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * net/tipc/name_table.c: TIPC name table code | 2 | * net/tipc/name_table.c: TIPC name table code |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2000-2006, Ericsson AB | 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 | * All rights reserved. | 6 | * All rights reserved. |
| 7 | * | 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
| @@ -39,10 +39,15 @@ | |||
| 39 | #include "name_table.h" | 39 | #include "name_table.h" |
| 40 | #include "name_distr.h" | 40 | #include "name_distr.h" |
| 41 | #include "subscr.h" | 41 | #include "subscr.h" |
| 42 | #include "port.h" | ||
| 43 | 42 | ||
| 44 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ | 43 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ |
| 45 | 44 | ||
| 45 | static const struct nla_policy | ||
| 46 | tipc_nl_name_table_policy[TIPC_NLA_NAME_TABLE_MAX + 1] = { | ||
| 47 | [TIPC_NLA_NAME_TABLE_UNSPEC] = { .type = NLA_UNSPEC }, | ||
| 48 | [TIPC_NLA_NAME_TABLE_PUBL] = { .type = NLA_NESTED } | ||
| 49 | }; | ||
| 50 | |||
| 46 | /** | 51 | /** |
| 47 | * struct name_info - name sequence publication info | 52 | * struct name_info - name sequence publication info |
| 48 | * @node_list: circular list of publications made by own node | 53 | * @node_list: circular list of publications made by own node |
| @@ -87,6 +92,7 @@ struct sub_seq { | |||
| 87 | * @ns_list: links to adjacent name sequences in hash chain | 92 | * @ns_list: links to adjacent name sequences in hash chain |
| 88 | * @subscriptions: list of subscriptions for this 'type' | 93 | * @subscriptions: list of subscriptions for this 'type' |
| 89 | * @lock: spinlock controlling access to publication lists of all sub-sequences | 94 | * @lock: spinlock controlling access to publication lists of all sub-sequences |
| 95 | * @rcu: RCU callback head used for deferred freeing | ||
| 90 | */ | 96 | */ |
| 91 | struct name_seq { | 97 | struct name_seq { |
| 92 | u32 type; | 98 | u32 type; |
| @@ -96,21 +102,11 @@ struct name_seq { | |||
| 96 | struct hlist_node ns_list; | 102 | struct hlist_node ns_list; |
| 97 | struct list_head subscriptions; | 103 | struct list_head subscriptions; |
| 98 | spinlock_t lock; | 104 | spinlock_t lock; |
| 105 | struct rcu_head rcu; | ||
| 99 | }; | 106 | }; |
| 100 | 107 | ||
| 101 | /** | 108 | struct name_table *tipc_nametbl; |
| 102 | * struct name_table - table containing all existing port name publications | 109 | DEFINE_SPINLOCK(tipc_nametbl_lock); |
| 103 | * @types: pointer to fixed-sized array of name sequence lists, | ||
| 104 | * accessed via hashing on 'type'; name sequence lists are *not* sorted | ||
| 105 | * @local_publ_count: number of publications issued by this node | ||
| 106 | */ | ||
| 107 | struct name_table { | ||
| 108 | struct hlist_head *types; | ||
| 109 | u32 local_publ_count; | ||
| 110 | }; | ||
| 111 | |||
| 112 | static struct name_table table; | ||
| 113 | DEFINE_RWLOCK(tipc_nametbl_lock); | ||
| 114 | 110 | ||
| 115 | static int hash(int x) | 111 | static int hash(int x) |
| 116 | { | 112 | { |
| @@ -137,9 +133,7 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper, | |||
| 137 | publ->node = node; | 133 | publ->node = node; |
| 138 | publ->ref = port_ref; | 134 | publ->ref = port_ref; |
| 139 | publ->key = key; | 135 | publ->key = key; |
| 140 | INIT_LIST_HEAD(&publ->local_list); | ||
| 141 | INIT_LIST_HEAD(&publ->pport_list); | 136 | INIT_LIST_HEAD(&publ->pport_list); |
| 142 | INIT_LIST_HEAD(&publ->subscr.nodesub_list); | ||
| 143 | return publ; | 137 | return publ; |
| 144 | } | 138 | } |
| 145 | 139 | ||
| @@ -174,22 +168,10 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea | |||
| 174 | nseq->alloc = 1; | 168 | nseq->alloc = 1; |
| 175 | INIT_HLIST_NODE(&nseq->ns_list); | 169 | INIT_HLIST_NODE(&nseq->ns_list); |
| 176 | INIT_LIST_HEAD(&nseq->subscriptions); | 170 | INIT_LIST_HEAD(&nseq->subscriptions); |
| 177 | hlist_add_head(&nseq->ns_list, seq_head); | 171 | hlist_add_head_rcu(&nseq->ns_list, seq_head); |
| 178 | return nseq; | 172 | return nseq; |
| 179 | } | 173 | } |
| 180 | 174 | ||
| 181 | /* | ||
| 182 | * nameseq_delete_empty - deletes a name sequence structure if now unused | ||
| 183 | */ | ||
| 184 | static void nameseq_delete_empty(struct name_seq *seq) | ||
| 185 | { | ||
| 186 | if (!seq->first_free && list_empty(&seq->subscriptions)) { | ||
| 187 | hlist_del_init(&seq->ns_list); | ||
| 188 | kfree(seq->sseqs); | ||
| 189 | kfree(seq); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | /** | 175 | /** |
| 194 | * nameseq_find_subseq - find sub-sequence (if any) matching a name instance | 176 | * nameseq_find_subseq - find sub-sequence (if any) matching a name instance |
| 195 | * | 177 | * |
| @@ -262,8 +244,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
| 262 | 244 | ||
| 263 | /* Lower end overlaps existing entry => need an exact match */ | 245 | /* Lower end overlaps existing entry => need an exact match */ |
| 264 | if ((sseq->lower != lower) || (sseq->upper != upper)) { | 246 | if ((sseq->lower != lower) || (sseq->upper != upper)) { |
| 265 | pr_warn("Cannot publish {%u,%u,%u}, overlap error\n", | ||
| 266 | type, lower, upper); | ||
| 267 | return NULL; | 247 | return NULL; |
| 268 | } | 248 | } |
| 269 | 249 | ||
| @@ -285,8 +265,6 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
| 285 | /* Fail if upper end overlaps into an existing entry */ | 265 | /* Fail if upper end overlaps into an existing entry */ |
| 286 | if ((inspos < nseq->first_free) && | 266 | if ((inspos < nseq->first_free) && |
| 287 | (upper >= nseq->sseqs[inspos].lower)) { | 267 | (upper >= nseq->sseqs[inspos].lower)) { |
| 288 | pr_warn("Cannot publish {%u,%u,%u}, overlap error\n", | ||
| 289 | type, lower, upper); | ||
| 290 | return NULL; | 268 | return NULL; |
| 291 | } | 269 | } |
| 292 | 270 | ||
| @@ -474,8 +452,8 @@ static struct name_seq *nametbl_find_seq(u32 type) | |||
| 474 | struct hlist_head *seq_head; | 452 | struct hlist_head *seq_head; |
| 475 | struct name_seq *ns; | 453 | struct name_seq *ns; |
| 476 | 454 | ||
| 477 | seq_head = &table.types[hash(type)]; | 455 | seq_head = &tipc_nametbl->seq_hlist[hash(type)]; |
| 478 | hlist_for_each_entry(ns, seq_head, ns_list) { | 456 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { |
| 479 | if (ns->type == type) | 457 | if (ns->type == type) |
| 480 | return ns; | 458 | return ns; |
| 481 | } | 459 | } |
| @@ -486,7 +464,9 @@ static struct name_seq *nametbl_find_seq(u32 type) | |||
| 486 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | 464 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, |
| 487 | u32 scope, u32 node, u32 port, u32 key) | 465 | u32 scope, u32 node, u32 port, u32 key) |
| 488 | { | 466 | { |
| 467 | struct publication *publ; | ||
| 489 | struct name_seq *seq = nametbl_find_seq(type); | 468 | struct name_seq *seq = nametbl_find_seq(type); |
| 469 | int index = hash(type); | ||
| 490 | 470 | ||
| 491 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || | 471 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || |
| 492 | (lower > upper)) { | 472 | (lower > upper)) { |
| @@ -496,12 +476,16 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | |||
| 496 | } | 476 | } |
| 497 | 477 | ||
| 498 | if (!seq) | 478 | if (!seq) |
| 499 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); | 479 | seq = tipc_nameseq_create(type, |
| 480 | &tipc_nametbl->seq_hlist[index]); | ||
| 500 | if (!seq) | 481 | if (!seq) |
| 501 | return NULL; | 482 | return NULL; |
| 502 | 483 | ||
| 503 | return tipc_nameseq_insert_publ(seq, type, lower, upper, | 484 | spin_lock_bh(&seq->lock); |
| 485 | publ = tipc_nameseq_insert_publ(seq, type, lower, upper, | ||
| 504 | scope, node, port, key); | 486 | scope, node, port, key); |
| 487 | spin_unlock_bh(&seq->lock); | ||
| 488 | return publ; | ||
| 505 | } | 489 | } |
| 506 | 490 | ||
| 507 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | 491 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, |
| @@ -513,8 +497,16 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | |||
| 513 | if (!seq) | 497 | if (!seq) |
| 514 | return NULL; | 498 | return NULL; |
| 515 | 499 | ||
| 500 | spin_lock_bh(&seq->lock); | ||
| 516 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); | 501 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); |
| 517 | nameseq_delete_empty(seq); | 502 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 503 | hlist_del_init_rcu(&seq->ns_list); | ||
| 504 | kfree(seq->sseqs); | ||
| 505 | spin_unlock_bh(&seq->lock); | ||
| 506 | kfree_rcu(seq, rcu); | ||
| 507 | return publ; | ||
| 508 | } | ||
| 509 | spin_unlock_bh(&seq->lock); | ||
| 518 | return publ; | 510 | return publ; |
| 519 | } | 511 | } |
| 520 | 512 | ||
| @@ -543,14 +535,14 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 543 | if (!tipc_in_scope(*destnode, tipc_own_addr)) | 535 | if (!tipc_in_scope(*destnode, tipc_own_addr)) |
| 544 | return 0; | 536 | return 0; |
| 545 | 537 | ||
| 546 | read_lock_bh(&tipc_nametbl_lock); | 538 | rcu_read_lock(); |
| 547 | seq = nametbl_find_seq(type); | 539 | seq = nametbl_find_seq(type); |
| 548 | if (unlikely(!seq)) | 540 | if (unlikely(!seq)) |
| 549 | goto not_found; | 541 | goto not_found; |
| 542 | spin_lock_bh(&seq->lock); | ||
| 550 | sseq = nameseq_find_subseq(seq, instance); | 543 | sseq = nameseq_find_subseq(seq, instance); |
| 551 | if (unlikely(!sseq)) | 544 | if (unlikely(!sseq)) |
| 552 | goto not_found; | 545 | goto no_match; |
| 553 | spin_lock_bh(&seq->lock); | ||
| 554 | info = sseq->info; | 546 | info = sseq->info; |
| 555 | 547 | ||
| 556 | /* Closest-First Algorithm */ | 548 | /* Closest-First Algorithm */ |
| @@ -600,7 +592,7 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 600 | no_match: | 592 | no_match: |
| 601 | spin_unlock_bh(&seq->lock); | 593 | spin_unlock_bh(&seq->lock); |
| 602 | not_found: | 594 | not_found: |
| 603 | read_unlock_bh(&tipc_nametbl_lock); | 595 | rcu_read_unlock(); |
| 604 | *destnode = node; | 596 | *destnode = node; |
| 605 | return ref; | 597 | return ref; |
| 606 | } | 598 | } |
| @@ -626,13 +618,12 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | |||
| 626 | struct name_info *info; | 618 | struct name_info *info; |
| 627 | int res = 0; | 619 | int res = 0; |
| 628 | 620 | ||
| 629 | read_lock_bh(&tipc_nametbl_lock); | 621 | rcu_read_lock(); |
| 630 | seq = nametbl_find_seq(type); | 622 | seq = nametbl_find_seq(type); |
| 631 | if (!seq) | 623 | if (!seq) |
| 632 | goto exit; | 624 | goto exit; |
| 633 | 625 | ||
| 634 | spin_lock_bh(&seq->lock); | 626 | spin_lock_bh(&seq->lock); |
| 635 | |||
| 636 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); | 627 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); |
| 637 | sseq_stop = seq->sseqs + seq->first_free; | 628 | sseq_stop = seq->sseqs + seq->first_free; |
| 638 | for (; sseq != sseq_stop; sseq++) { | 629 | for (; sseq != sseq_stop; sseq++) { |
| @@ -650,10 +641,9 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | |||
| 650 | if (info->cluster_list_size != info->node_list_size) | 641 | if (info->cluster_list_size != info->node_list_size) |
| 651 | res = 1; | 642 | res = 1; |
| 652 | } | 643 | } |
| 653 | |||
| 654 | spin_unlock_bh(&seq->lock); | 644 | spin_unlock_bh(&seq->lock); |
| 655 | exit: | 645 | exit: |
| 656 | read_unlock_bh(&tipc_nametbl_lock); | 646 | rcu_read_unlock(); |
| 657 | return res; | 647 | return res; |
| 658 | } | 648 | } |
| 659 | 649 | ||
| @@ -666,20 +656,23 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | |||
| 666 | struct publication *publ; | 656 | struct publication *publ; |
| 667 | struct sk_buff *buf = NULL; | 657 | struct sk_buff *buf = NULL; |
| 668 | 658 | ||
| 669 | if (table.local_publ_count >= TIPC_MAX_PUBLICATIONS) { | 659 | spin_lock_bh(&tipc_nametbl_lock); |
| 660 | if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { | ||
| 670 | pr_warn("Publication failed, local publication limit reached (%u)\n", | 661 | pr_warn("Publication failed, local publication limit reached (%u)\n", |
| 671 | TIPC_MAX_PUBLICATIONS); | 662 | TIPC_MAX_PUBLICATIONS); |
| 663 | spin_unlock_bh(&tipc_nametbl_lock); | ||
| 672 | return NULL; | 664 | return NULL; |
| 673 | } | 665 | } |
| 674 | 666 | ||
| 675 | write_lock_bh(&tipc_nametbl_lock); | ||
| 676 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, | 667 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, |
| 677 | tipc_own_addr, port_ref, key); | 668 | tipc_own_addr, port_ref, key); |
| 678 | if (likely(publ)) { | 669 | if (likely(publ)) { |
| 679 | table.local_publ_count++; | 670 | tipc_nametbl->local_publ_count++; |
| 680 | buf = tipc_named_publish(publ); | 671 | buf = tipc_named_publish(publ); |
| 672 | /* Any pending external events? */ | ||
| 673 | tipc_named_process_backlog(); | ||
| 681 | } | 674 | } |
| 682 | write_unlock_bh(&tipc_nametbl_lock); | 675 | spin_unlock_bh(&tipc_nametbl_lock); |
| 683 | 676 | ||
| 684 | if (buf) | 677 | if (buf) |
| 685 | named_cluster_distribute(buf); | 678 | named_cluster_distribute(buf); |
| @@ -692,25 +685,28 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | |||
| 692 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | 685 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) |
| 693 | { | 686 | { |
| 694 | struct publication *publ; | 687 | struct publication *publ; |
| 695 | struct sk_buff *buf; | 688 | struct sk_buff *skb = NULL; |
| 696 | 689 | ||
| 697 | write_lock_bh(&tipc_nametbl_lock); | 690 | spin_lock_bh(&tipc_nametbl_lock); |
| 698 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); | 691 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); |
| 699 | if (likely(publ)) { | 692 | if (likely(publ)) { |
| 700 | table.local_publ_count--; | 693 | tipc_nametbl->local_publ_count--; |
| 701 | buf = tipc_named_withdraw(publ); | 694 | skb = tipc_named_withdraw(publ); |
| 702 | write_unlock_bh(&tipc_nametbl_lock); | 695 | /* Any pending external events? */ |
| 696 | tipc_named_process_backlog(); | ||
| 703 | list_del_init(&publ->pport_list); | 697 | list_del_init(&publ->pport_list); |
| 704 | kfree(publ); | 698 | kfree_rcu(publ, rcu); |
| 699 | } else { | ||
| 700 | pr_err("Unable to remove local publication\n" | ||
| 701 | "(type=%u, lower=%u, ref=%u, key=%u)\n", | ||
| 702 | type, lower, ref, key); | ||
| 703 | } | ||
| 704 | spin_unlock_bh(&tipc_nametbl_lock); | ||
| 705 | 705 | ||
| 706 | if (buf) | 706 | if (skb) { |
| 707 | named_cluster_distribute(buf); | 707 | named_cluster_distribute(skb); |
| 708 | return 1; | 708 | return 1; |
| 709 | } | 709 | } |
| 710 | write_unlock_bh(&tipc_nametbl_lock); | ||
| 711 | pr_err("Unable to remove local publication\n" | ||
| 712 | "(type=%u, lower=%u, ref=%u, key=%u)\n", | ||
| 713 | type, lower, ref, key); | ||
| 714 | return 0; | 710 | return 0; |
| 715 | } | 711 | } |
| 716 | 712 | ||
| @@ -720,12 +716,14 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
| 720 | void tipc_nametbl_subscribe(struct tipc_subscription *s) | 716 | void tipc_nametbl_subscribe(struct tipc_subscription *s) |
| 721 | { | 717 | { |
| 722 | u32 type = s->seq.type; | 718 | u32 type = s->seq.type; |
| 719 | int index = hash(type); | ||
| 723 | struct name_seq *seq; | 720 | struct name_seq *seq; |
| 724 | 721 | ||
| 725 | write_lock_bh(&tipc_nametbl_lock); | 722 | spin_lock_bh(&tipc_nametbl_lock); |
| 726 | seq = nametbl_find_seq(type); | 723 | seq = nametbl_find_seq(type); |
| 727 | if (!seq) | 724 | if (!seq) |
| 728 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); | 725 | seq = tipc_nameseq_create(type, |
| 726 | &tipc_nametbl->seq_hlist[index]); | ||
| 729 | if (seq) { | 727 | if (seq) { |
| 730 | spin_lock_bh(&seq->lock); | 728 | spin_lock_bh(&seq->lock); |
| 731 | tipc_nameseq_subscribe(seq, s); | 729 | tipc_nameseq_subscribe(seq, s); |
| @@ -734,7 +732,7 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s) | |||
| 734 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", | 732 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", |
| 735 | s->seq.type, s->seq.lower, s->seq.upper); | 733 | s->seq.type, s->seq.lower, s->seq.upper); |
| 736 | } | 734 | } |
| 737 | write_unlock_bh(&tipc_nametbl_lock); | 735 | spin_unlock_bh(&tipc_nametbl_lock); |
| 738 | } | 736 | } |
| 739 | 737 | ||
| 740 | /** | 738 | /** |
| @@ -744,18 +742,23 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s) | |||
| 744 | { | 742 | { |
| 745 | struct name_seq *seq; | 743 | struct name_seq *seq; |
| 746 | 744 | ||
| 747 | write_lock_bh(&tipc_nametbl_lock); | 745 | spin_lock_bh(&tipc_nametbl_lock); |
| 748 | seq = nametbl_find_seq(s->seq.type); | 746 | seq = nametbl_find_seq(s->seq.type); |
| 749 | if (seq != NULL) { | 747 | if (seq != NULL) { |
| 750 | spin_lock_bh(&seq->lock); | 748 | spin_lock_bh(&seq->lock); |
| 751 | list_del_init(&s->nameseq_list); | 749 | list_del_init(&s->nameseq_list); |
| 752 | spin_unlock_bh(&seq->lock); | 750 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 753 | nameseq_delete_empty(seq); | 751 | hlist_del_init_rcu(&seq->ns_list); |
| 752 | kfree(seq->sseqs); | ||
| 753 | spin_unlock_bh(&seq->lock); | ||
| 754 | kfree_rcu(seq, rcu); | ||
| 755 | } else { | ||
| 756 | spin_unlock_bh(&seq->lock); | ||
| 757 | } | ||
| 754 | } | 758 | } |
| 755 | write_unlock_bh(&tipc_nametbl_lock); | 759 | spin_unlock_bh(&tipc_nametbl_lock); |
| 756 | } | 760 | } |
| 757 | 761 | ||
| 758 | |||
| 759 | /** | 762 | /** |
| 760 | * subseq_list - print specified sub-sequence contents into the given buffer | 763 | * subseq_list - print specified sub-sequence contents into the given buffer |
| 761 | */ | 764 | */ |
| @@ -877,8 +880,8 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 877 | lowbound = 0; | 880 | lowbound = 0; |
| 878 | upbound = ~0; | 881 | upbound = ~0; |
| 879 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 882 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 880 | seq_head = &table.types[i]; | 883 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 881 | hlist_for_each_entry(seq, seq_head, ns_list) { | 884 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 882 | ret += nameseq_list(seq, buf + ret, len - ret, | 885 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 883 | depth, seq->type, | 886 | depth, seq->type, |
| 884 | lowbound, upbound, i); | 887 | lowbound, upbound, i); |
| @@ -893,8 +896,8 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 893 | } | 896 | } |
| 894 | ret += nametbl_header(buf + ret, len - ret, depth); | 897 | ret += nametbl_header(buf + ret, len - ret, depth); |
| 895 | i = hash(type); | 898 | i = hash(type); |
| 896 | seq_head = &table.types[i]; | 899 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 897 | hlist_for_each_entry(seq, seq_head, ns_list) { | 900 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 898 | if (seq->type == type) { | 901 | if (seq->type == type) { |
| 899 | ret += nameseq_list(seq, buf + ret, len - ret, | 902 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 900 | depth, type, | 903 | depth, type, |
| @@ -926,11 +929,11 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
| 926 | pb = TLV_DATA(rep_tlv); | 929 | pb = TLV_DATA(rep_tlv); |
| 927 | pb_len = ULTRA_STRING_MAX_LEN; | 930 | pb_len = ULTRA_STRING_MAX_LEN; |
| 928 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); | 931 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); |
| 929 | read_lock_bh(&tipc_nametbl_lock); | 932 | rcu_read_lock(); |
| 930 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), | 933 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), |
| 931 | ntohl(argv->type), | 934 | ntohl(argv->type), |
| 932 | ntohl(argv->lowbound), ntohl(argv->upbound)); | 935 | ntohl(argv->lowbound), ntohl(argv->upbound)); |
| 933 | read_unlock_bh(&tipc_nametbl_lock); | 936 | rcu_read_unlock(); |
| 934 | str_len += 1; /* for "\0" */ | 937 | str_len += 1; /* for "\0" */ |
| 935 | skb_put(buf, TLV_SPACE(str_len)); | 938 | skb_put(buf, TLV_SPACE(str_len)); |
| 936 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | 939 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| @@ -940,12 +943,18 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
| 940 | 943 | ||
| 941 | int tipc_nametbl_init(void) | 944 | int tipc_nametbl_init(void) |
| 942 | { | 945 | { |
| 943 | table.types = kcalloc(TIPC_NAMETBL_SIZE, sizeof(struct hlist_head), | 946 | int i; |
| 944 | GFP_ATOMIC); | 947 | |
| 945 | if (!table.types) | 948 | tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); |
| 949 | if (!tipc_nametbl) | ||
| 946 | return -ENOMEM; | 950 | return -ENOMEM; |
| 947 | 951 | ||
| 948 | table.local_publ_count = 0; | 952 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) |
| 953 | INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]); | ||
| 954 | |||
| 955 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); | ||
| 956 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); | ||
| 957 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]); | ||
| 949 | return 0; | 958 | return 0; |
| 950 | } | 959 | } |
| 951 | 960 | ||
| @@ -960,17 +969,19 @@ static void tipc_purge_publications(struct name_seq *seq) | |||
| 960 | struct sub_seq *sseq; | 969 | struct sub_seq *sseq; |
| 961 | struct name_info *info; | 970 | struct name_info *info; |
| 962 | 971 | ||
| 963 | if (!seq->sseqs) { | 972 | spin_lock_bh(&seq->lock); |
| 964 | nameseq_delete_empty(seq); | ||
| 965 | return; | ||
| 966 | } | ||
| 967 | sseq = seq->sseqs; | 973 | sseq = seq->sseqs; |
| 968 | info = sseq->info; | 974 | info = sseq->info; |
| 969 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { | 975 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { |
| 970 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, | 976 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, |
| 971 | publ->ref, publ->key); | 977 | publ->ref, publ->key); |
| 972 | kfree(publ); | 978 | kfree_rcu(publ, rcu); |
| 973 | } | 979 | } |
| 980 | hlist_del_init_rcu(&seq->ns_list); | ||
| 981 | kfree(seq->sseqs); | ||
| 982 | spin_unlock_bh(&seq->lock); | ||
| 983 | |||
| 984 | kfree_rcu(seq, rcu); | ||
| 974 | } | 985 | } |
| 975 | 986 | ||
| 976 | void tipc_nametbl_stop(void) | 987 | void tipc_nametbl_stop(void) |
| @@ -978,21 +989,202 @@ void tipc_nametbl_stop(void) | |||
| 978 | u32 i; | 989 | u32 i; |
| 979 | struct name_seq *seq; | 990 | struct name_seq *seq; |
| 980 | struct hlist_head *seq_head; | 991 | struct hlist_head *seq_head; |
| 981 | struct hlist_node *safe; | ||
| 982 | 992 | ||
| 983 | /* Verify name table is empty and purge any lingering | 993 | /* Verify name table is empty and purge any lingering |
| 984 | * publications, then release the name table | 994 | * publications, then release the name table |
| 985 | */ | 995 | */ |
| 986 | write_lock_bh(&tipc_nametbl_lock); | 996 | spin_lock_bh(&tipc_nametbl_lock); |
| 987 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 997 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 988 | if (hlist_empty(&table.types[i])) | 998 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) |
| 989 | continue; | 999 | continue; |
| 990 | seq_head = &table.types[i]; | 1000 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 991 | hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) { | 1001 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 992 | tipc_purge_publications(seq); | 1002 | tipc_purge_publications(seq); |
| 993 | } | 1003 | } |
| 994 | } | 1004 | } |
| 995 | kfree(table.types); | 1005 | spin_unlock_bh(&tipc_nametbl_lock); |
| 996 | table.types = NULL; | 1006 | |
| 997 | write_unlock_bh(&tipc_nametbl_lock); | 1007 | synchronize_net(); |
| 1008 | kfree(tipc_nametbl); | ||
| 1009 | |||
| 1010 | } | ||
| 1011 | |||
| 1012 | static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg, | ||
| 1013 | struct name_seq *seq, | ||
| 1014 | struct sub_seq *sseq, u32 *last_publ) | ||
| 1015 | { | ||
| 1016 | void *hdr; | ||
| 1017 | struct nlattr *attrs; | ||
| 1018 | struct nlattr *publ; | ||
| 1019 | struct publication *p; | ||
| 1020 | |||
| 1021 | if (*last_publ) { | ||
| 1022 | list_for_each_entry(p, &sseq->info->zone_list, zone_list) | ||
| 1023 | if (p->key == *last_publ) | ||
| 1024 | break; | ||
| 1025 | if (p->key != *last_publ) | ||
| 1026 | return -EPIPE; | ||
| 1027 | } else { | ||
| 1028 | p = list_first_entry(&sseq->info->zone_list, struct publication, | ||
| 1029 | zone_list); | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | list_for_each_entry_from(p, &sseq->info->zone_list, zone_list) { | ||
| 1033 | *last_publ = p->key; | ||
| 1034 | |||
| 1035 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, | ||
| 1036 | &tipc_genl_v2_family, NLM_F_MULTI, | ||
| 1037 | TIPC_NL_NAME_TABLE_GET); | ||
| 1038 | if (!hdr) | ||
| 1039 | return -EMSGSIZE; | ||
| 1040 | |||
| 1041 | attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); | ||
| 1042 | if (!attrs) | ||
| 1043 | goto msg_full; | ||
| 1044 | |||
| 1045 | publ = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); | ||
| 1046 | if (!publ) | ||
| 1047 | goto attr_msg_full; | ||
| 1048 | |||
| 1049 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, seq->type)) | ||
| 1050 | goto publ_msg_full; | ||
| 1051 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sseq->lower)) | ||
| 1052 | goto publ_msg_full; | ||
| 1053 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sseq->upper)) | ||
| 1054 | goto publ_msg_full; | ||
| 1055 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope)) | ||
| 1056 | goto publ_msg_full; | ||
| 1057 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node)) | ||
| 1058 | goto publ_msg_full; | ||
| 1059 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->ref)) | ||
| 1060 | goto publ_msg_full; | ||
| 1061 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key)) | ||
| 1062 | goto publ_msg_full; | ||
| 1063 | |||
| 1064 | nla_nest_end(msg->skb, publ); | ||
| 1065 | nla_nest_end(msg->skb, attrs); | ||
| 1066 | genlmsg_end(msg->skb, hdr); | ||
| 1067 | } | ||
| 1068 | *last_publ = 0; | ||
| 1069 | |||
| 1070 | return 0; | ||
| 1071 | |||
| 1072 | publ_msg_full: | ||
| 1073 | nla_nest_cancel(msg->skb, publ); | ||
| 1074 | attr_msg_full: | ||
| 1075 | nla_nest_cancel(msg->skb, attrs); | ||
| 1076 | msg_full: | ||
| 1077 | genlmsg_cancel(msg->skb, hdr); | ||
| 1078 | |||
| 1079 | return -EMSGSIZE; | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq, | ||
| 1083 | u32 *last_lower, u32 *last_publ) | ||
| 1084 | { | ||
| 1085 | struct sub_seq *sseq; | ||
| 1086 | struct sub_seq *sseq_start; | ||
| 1087 | int err; | ||
| 1088 | |||
| 1089 | if (*last_lower) { | ||
| 1090 | sseq_start = nameseq_find_subseq(seq, *last_lower); | ||
| 1091 | if (!sseq_start) | ||
| 1092 | return -EPIPE; | ||
| 1093 | } else { | ||
| 1094 | sseq_start = seq->sseqs; | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | for (sseq = sseq_start; sseq != &seq->sseqs[seq->first_free]; sseq++) { | ||
| 1098 | err = __tipc_nl_add_nametable_publ(msg, seq, sseq, last_publ); | ||
| 1099 | if (err) { | ||
| 1100 | *last_lower = sseq->lower; | ||
| 1101 | return err; | ||
| 1102 | } | ||
| 1103 | } | ||
| 1104 | *last_lower = 0; | ||
| 1105 | |||
| 1106 | return 0; | ||
| 1107 | } | ||
| 1108 | |||
| 1109 | static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, | ||
| 1110 | u32 *last_lower, u32 *last_publ) | ||
| 1111 | { | ||
| 1112 | struct hlist_head *seq_head; | ||
| 1113 | struct name_seq *seq = NULL; | ||
| 1114 | int err; | ||
| 1115 | int i; | ||
| 1116 | |||
| 1117 | if (*last_type) | ||
| 1118 | i = hash(*last_type); | ||
| 1119 | else | ||
| 1120 | i = 0; | ||
| 1121 | |||
| 1122 | for (; i < TIPC_NAMETBL_SIZE; i++) { | ||
| 1123 | seq_head = &tipc_nametbl->seq_hlist[i]; | ||
| 1124 | |||
| 1125 | if (*last_type) { | ||
| 1126 | seq = nametbl_find_seq(*last_type); | ||
| 1127 | if (!seq) | ||
| 1128 | return -EPIPE; | ||
| 1129 | } else { | ||
| 1130 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) | ||
| 1131 | break; | ||
| 1132 | if (!seq) | ||
| 1133 | continue; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | hlist_for_each_entry_from_rcu(seq, ns_list) { | ||
| 1137 | spin_lock_bh(&seq->lock); | ||
| 1138 | err = __tipc_nl_subseq_list(msg, seq, last_lower, | ||
| 1139 | last_publ); | ||
| 1140 | |||
| 1141 | if (err) { | ||
| 1142 | *last_type = seq->type; | ||
| 1143 | spin_unlock_bh(&seq->lock); | ||
| 1144 | return err; | ||
| 1145 | } | ||
| 1146 | spin_unlock_bh(&seq->lock); | ||
| 1147 | } | ||
| 1148 | *last_type = 0; | ||
| 1149 | } | ||
| 1150 | return 0; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
| 1154 | { | ||
| 1155 | int err; | ||
| 1156 | int done = cb->args[3]; | ||
| 1157 | u32 last_type = cb->args[0]; | ||
| 1158 | u32 last_lower = cb->args[1]; | ||
| 1159 | u32 last_publ = cb->args[2]; | ||
| 1160 | struct tipc_nl_msg msg; | ||
| 1161 | |||
| 1162 | if (done) | ||
| 1163 | return 0; | ||
| 1164 | |||
| 1165 | msg.skb = skb; | ||
| 1166 | msg.portid = NETLINK_CB(cb->skb).portid; | ||
| 1167 | msg.seq = cb->nlh->nlmsg_seq; | ||
| 1168 | |||
| 1169 | rcu_read_lock(); | ||
| 1170 | err = __tipc_nl_seq_list(&msg, &last_type, &last_lower, &last_publ); | ||
| 1171 | if (!err) { | ||
| 1172 | done = 1; | ||
| 1173 | } else if (err != -EMSGSIZE) { | ||
| 1174 | /* We never set seq or call nl_dump_check_consistent() this | ||
| 1175 | * means that setting prev_seq here will cause the consistence | ||
| 1176 | * check to fail in the netlink callback handler. Resulting in | ||
| 1177 | * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if | ||
| 1178 | * we got an error. | ||
| 1179 | */ | ||
| 1180 | cb->prev_seq = 1; | ||
| 1181 | } | ||
| 1182 | rcu_read_unlock(); | ||
| 1183 | |||
| 1184 | cb->args[0] = last_type; | ||
| 1185 | cb->args[1] = last_lower; | ||
| 1186 | cb->args[2] = last_publ; | ||
| 1187 | cb->args[3] = done; | ||
| 1188 | |||
| 1189 | return skb->len; | ||
| 998 | } | 1190 | } |
