2 * net/tipc/cluster.c: TIPC cluster management routines
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 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.
41 struct tipc_node **tipc_local_nodes = NULL;
42 struct tipc_node_map tipc_cltr_bcast_nodes = {0,{0,}};
44 struct cluster *tipc_cltr_create(u32 addr)
46 struct cluster *c_ptr;
49 c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC);
51 warn("Cluster creation failure, no memory\n");
55 c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
56 max_nodes = tipc_max_nodes + 1;
58 c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC);
59 if (c_ptr->nodes == NULL) {
60 warn("Cluster creation failure, no memory for node area\n");
65 tipc_local_nodes = c_ptr->nodes;
66 c_ptr->highest_node = 0;
68 tipc_net.clusters[1] = c_ptr;
72 void tipc_cltr_delete(struct cluster *c_ptr)
78 for (n_num = 1; n_num <= c_ptr->highest_node; n_num++) {
79 tipc_node_delete(c_ptr->nodes[n_num]);
86 void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr)
88 u32 n_num = tipc_node(n_ptr->addr);
89 u32 max_n_num = tipc_max_nodes;
92 assert(n_num <= max_n_num);
93 assert(c_ptr->nodes[n_num] == NULL);
94 c_ptr->nodes[n_num] = n_ptr;
95 if (n_num > c_ptr->highest_node)
96 c_ptr->highest_node = n_num;
100 * tipc_cltr_broadcast - broadcast message to all nodes within cluster
103 void tipc_cltr_broadcast(struct sk_buff *buf)
105 struct sk_buff *buf_copy;
106 struct cluster *c_ptr;
107 struct tipc_node *n_ptr;
110 if (tipc_mode == TIPC_NET_MODE) {
111 c_ptr = tipc_cltr_find(tipc_own_addr);
114 for (n_num = 1; n_num <= c_ptr->highest_node; n_num++) {
115 n_ptr = c_ptr->nodes[n_num];
116 if (n_ptr && tipc_node_has_active_links(n_ptr)) {
117 buf_copy = skb_copy(buf, GFP_ATOMIC);
118 if (buf_copy == NULL)
120 msg_set_destnode(buf_msg(buf_copy),
122 tipc_link_send(buf_copy, n_ptr->addr,
131 int tipc_cltr_init(void)
133 return tipc_cltr_create(tipc_own_addr) ? 0 : -ENOMEM;