blob: ba6f5bfa0cdb96bebb3f97a978e5c6819767da1d [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/cluster.c: TIPC cluster management routines
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Per Liden593a5f22006-01-11 19:14:19 +01004 * Copyright (c) 2000-2006, Ericsson AB
Per Lidenb97bf3f2006-01-02 19:04:38 +01005 * Copyright (c) 2005, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 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.
19 *
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.
Per Lidenb97bf3f2006-01-02 19:04:38 +010023 *
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.
35 */
36
37#include "core.h"
38#include "cluster.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010039#include "link.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040
David S. Miller6c000552008-09-02 23:38:32 -070041struct tipc_node **tipc_local_nodes = NULL;
42struct tipc_node_map tipc_cltr_bcast_nodes = {0,{0,}};
Per Lidenb97bf3f2006-01-02 19:04:38 +010043
Per Liden4323add2006-01-18 00:38:21 +010044struct cluster *tipc_cltr_create(u32 addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010045{
Per Lidenb97bf3f2006-01-02 19:04:38 +010046 struct cluster *c_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090047 int max_nodes;
Per Lidenb97bf3f2006-01-02 19:04:38 +010048
Panagiotis Issaris0da974f2006-07-21 14:51:30 -070049 c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -070050 if (c_ptr == NULL) {
51 warn("Cluster creation failure, no memory\n");
Sam Ravnborg1fc54d82006-03-20 22:36:47 -080052 return NULL;
Allan Stephensa10bd922006-06-25 23:52:17 -070053 }
Per Lidenb97bf3f2006-01-02 19:04:38 +010054
55 c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
Allan Stephens08c80e92010-12-31 18:59:17 +000056 max_nodes = tipc_max_nodes + 1;
Allan Stephensa10bd922006-06-25 23:52:17 -070057
Panagiotis Issaris0da974f2006-07-21 14:51:30 -070058 c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +010059 if (c_ptr->nodes == NULL) {
Allan Stephensa10bd922006-06-25 23:52:17 -070060 warn("Cluster creation failure, no memory for node area\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +010061 kfree(c_ptr);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -080062 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +010063 }
Allan Stephensa10bd922006-06-25 23:52:17 -070064
Allan Stephens51a8e4d2010-12-31 18:59:18 +000065 tipc_local_nodes = c_ptr->nodes;
Per Lidenb97bf3f2006-01-02 19:04:38 +010066 c_ptr->highest_node = 0;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090067
Allan Stephens51f98a82010-12-31 18:59:16 +000068 tipc_net.clusters[1] = c_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +010069 return c_ptr;
70}
71
Per Liden4323add2006-01-18 00:38:21 +010072void tipc_cltr_delete(struct cluster *c_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010073{
74 u32 n_num;
75
76 if (!c_ptr)
77 return;
78 for (n_num = 1; n_num <= c_ptr->highest_node; n_num++) {
Per Liden4323add2006-01-18 00:38:21 +010079 tipc_node_delete(c_ptr->nodes[n_num]);
Per Lidenb97bf3f2006-01-02 19:04:38 +010080 }
Per Lidenb97bf3f2006-01-02 19:04:38 +010081 kfree(c_ptr->nodes);
82 kfree(c_ptr);
83}
84
Per Lidenb97bf3f2006-01-02 19:04:38 +010085
David S. Miller6c000552008-09-02 23:38:32 -070086void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010087{
88 u32 n_num = tipc_node(n_ptr->addr);
89 u32 max_n_num = tipc_max_nodes;
90
Per Lidenb97bf3f2006-01-02 19:04:38 +010091 assert(n_num > 0);
92 assert(n_num <= max_n_num);
Harvey Harrison5f2f40a2008-02-24 18:38:31 -080093 assert(c_ptr->nodes[n_num] == NULL);
Per Lidenb97bf3f2006-01-02 19:04:38 +010094 c_ptr->nodes[n_num] = n_ptr;
95 if (n_num > c_ptr->highest_node)
96 c_ptr->highest_node = n_num;
97}
98
99/**
Per Liden4323add2006-01-18 00:38:21 +0100100 * tipc_cltr_broadcast - broadcast message to all nodes within cluster
Per Lidenb97bf3f2006-01-02 19:04:38 +0100101 */
102
Per Liden4323add2006-01-18 00:38:21 +0100103void tipc_cltr_broadcast(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100104{
105 struct sk_buff *buf_copy;
106 struct cluster *c_ptr;
David S. Miller6c000552008-09-02 23:38:32 -0700107 struct tipc_node *n_ptr;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108 u32 n_num;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100109
110 if (tipc_mode == TIPC_NET_MODE) {
Per Liden4323add2006-01-18 00:38:21 +0100111 c_ptr = tipc_cltr_find(tipc_own_addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100112
Allan Stephens08c80e92010-12-31 18:59:17 +0000113 /* Send to nodes */
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)
119 goto exit;
120 msg_set_destnode(buf_msg(buf_copy),
121 n_ptr->addr);
122 tipc_link_send(buf_copy, n_ptr->addr,
123 n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100124 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100125 }
126 }
127exit:
128 buf_discard(buf);
129}
130
Per Liden4323add2006-01-18 00:38:21 +0100131int tipc_cltr_init(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100132{
Allan Stephens0e35fd52008-07-14 22:44:01 -0700133 return tipc_cltr_create(tipc_own_addr) ? 0 : -ENOMEM;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100134}
135