diff options
Diffstat (limited to 'net/tipc/name_distr.c')
-rw-r--r-- | net/tipc/name_distr.c | 130 |
1 files changed, 80 insertions, 50 deletions
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index d57da6159616..158318e67b08 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c @@ -58,7 +58,6 @@ * Note: There is no field that identifies the publishing node because it is * the same for all items contained within a publication message. */ - struct distr_item { __be32 type; __be32 lower; @@ -68,17 +67,41 @@ struct distr_item { }; /** - * List of externally visible publications by this node -- - * that is, all publications having scope > TIPC_NODE_SCOPE. + * struct publ_list - list of publications made by this node + * @list: circular list of publications + * @list_size: number of entries in list */ +struct publ_list { + struct list_head list; + u32 size; +}; + +static struct publ_list publ_zone = { + .list = LIST_HEAD_INIT(publ_zone.list), + .size = 0, +}; + +static struct publ_list publ_cluster = { + .list = LIST_HEAD_INIT(publ_cluster.list), + .size = 0, +}; + +static struct publ_list publ_node = { + .list = LIST_HEAD_INIT(publ_node.list), + .size = 0, +}; + +static struct publ_list *publ_lists[] = { + NULL, + &publ_zone, /* publ_lists[TIPC_ZONE_SCOPE] */ + &publ_cluster, /* publ_lists[TIPC_CLUSTER_SCOPE] */ + &publ_node /* publ_lists[TIPC_NODE_SCOPE] */ +}; -static LIST_HEAD(publ_root); -static u32 publ_cnt; /** * publ_to_item - add publication info to a publication message */ - static void publ_to_item(struct distr_item *i, struct publication *p) { i->type = htonl(p->type); @@ -91,7 +114,6 @@ static void publ_to_item(struct distr_item *i, struct publication *p) /** * named_prepare_buf - allocate & initialize a publication message */ - static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest) { struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size); @@ -126,14 +148,16 @@ static void named_cluster_distribute(struct sk_buff *buf) /** * tipc_named_publish - tell other nodes about a new publication by this node */ - void tipc_named_publish(struct publication *publ) { struct sk_buff *buf; struct distr_item *item; - list_add_tail(&publ->local_list, &publ_root); - publ_cnt++; + list_add_tail(&publ->local_list, &publ_lists[publ->scope]->list); + publ_lists[publ->scope]->size++; + + if (publ->scope == TIPC_NODE_SCOPE) + return; buf = named_prepare_buf(PUBLICATION, ITEM_SIZE, 0); if (!buf) { @@ -149,14 +173,16 @@ void tipc_named_publish(struct publication *publ) /** * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node */ - void tipc_named_withdraw(struct publication *publ) { struct sk_buff *buf; struct distr_item *item; list_del(&publ->local_list); - publ_cnt--; + publ_lists[publ->scope]->size--; + + if (publ->scope == TIPC_NODE_SCOPE) + return; buf = named_prepare_buf(WITHDRAWAL, ITEM_SIZE, 0); if (!buf) { @@ -169,25 +195,51 @@ void tipc_named_withdraw(struct publication *publ) named_cluster_distribute(buf); } +/* + * named_distribute - prepare name info for bulk distribution to another node + */ +static void named_distribute(struct list_head *message_list, u32 node, + struct publ_list *pls, u32 max_item_buf) +{ + struct publication *publ; + struct sk_buff *buf = NULL; + struct distr_item *item = NULL; + u32 left = 0; + u32 rest = pls->size * ITEM_SIZE; + + list_for_each_entry(publ, &pls->list, local_list) { + if (!buf) { + left = (rest <= max_item_buf) ? rest : max_item_buf; + rest -= left; + buf = named_prepare_buf(PUBLICATION, left, node); + if (!buf) { + warn("Bulk publication failure\n"); + return; + } + item = (struct distr_item *)msg_data(buf_msg(buf)); + } + publ_to_item(item, publ); + item++; + left -= ITEM_SIZE; + if (!left) { + list_add_tail((struct list_head *)buf, message_list); + buf = NULL; + } + } +} + /** * tipc_named_node_up - tell specified node about all publications by this node */ - void tipc_named_node_up(unsigned long nodearg) { struct tipc_node *n_ptr; struct tipc_link *l_ptr; - struct publication *publ; - struct distr_item *item = NULL; - struct sk_buff *buf = NULL; struct list_head message_list; u32 node = (u32)nodearg; - u32 left = 0; - u32 rest; u32 max_item_buf = 0; /* compute maximum amount of publication data to send per message */ - read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(node); if (n_ptr) { @@ -203,32 +255,11 @@ void tipc_named_node_up(unsigned long nodearg) return; /* create list of publication messages, then send them as a unit */ - INIT_LIST_HEAD(&message_list); read_lock_bh(&tipc_nametbl_lock); - rest = publ_cnt * ITEM_SIZE; - - list_for_each_entry(publ, &publ_root, local_list) { - if (!buf) { - left = (rest <= max_item_buf) ? rest : max_item_buf; - rest -= left; - buf = named_prepare_buf(PUBLICATION, left, node); - if (!buf) { - warn("Bulk publication distribution failure\n"); - goto exit; - } - item = (struct distr_item *)msg_data(buf_msg(buf)); - } - publ_to_item(item, publ); - item++; - left -= ITEM_SIZE; - if (!left) { - list_add_tail((struct list_head *)buf, &message_list); - buf = NULL; - } - } -exit: + named_distribute(&message_list, node, &publ_cluster, max_item_buf); + named_distribute(&message_list, node, &publ_zone, max_item_buf); read_unlock_bh(&tipc_nametbl_lock); tipc_link_send_names(&message_list, (u32)node); @@ -240,7 +271,6 @@ exit: * Invoked for each publication issued by a newly failed node. * Removes publication structure from name table & deletes it. */ - static void named_purge_publ(struct publication *publ) { struct publication *p; @@ -264,7 +294,6 @@ static void named_purge_publ(struct publication *publ) /** * tipc_named_recv - process name table update message sent by another node */ - void tipc_named_recv(struct sk_buff *buf) { struct publication *publ; @@ -316,21 +345,22 @@ void tipc_named_recv(struct sk_buff *buf) } /** - * tipc_named_reinit - re-initialize local publication list + * tipc_named_reinit - re-initialize local publications * * This routine is called whenever TIPC networking is enabled. - * All existing publications by this node that have "cluster" or "zone" scope - * are updated to reflect the node's new network address. + * All name table entries published by this node are updated to reflect + * the node's new network address. */ - void tipc_named_reinit(void) { struct publication *publ; + int scope; write_lock_bh(&tipc_nametbl_lock); - list_for_each_entry(publ, &publ_root, local_list) - publ->node = tipc_own_addr; + for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++) + list_for_each_entry(publ, &publ_lists[scope]->list, local_list) + publ->node = tipc_own_addr; write_unlock_bh(&tipc_nametbl_lock); } |