Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/cluster.c: TIPC cluster management routines |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Per Liden | 593a5f2 | 2006-01-11 19:14:19 +0100 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, Ericsson AB |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 5 | * Copyright (c) 2005, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * 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 Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. |
| 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 23 | * |
| 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "link.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 40 | |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 41 | struct tipc_node **tipc_local_nodes = NULL; |
| 42 | struct tipc_node_map tipc_cltr_bcast_nodes = {0,{0,}}; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 43 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 44 | struct cluster *tipc_cltr_create(u32 addr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 45 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 46 | struct cluster *c_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 47 | int max_nodes; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 48 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 49 | c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 50 | if (c_ptr == NULL) { |
| 51 | warn("Cluster creation failure, no memory\n"); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 52 | return NULL; |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 53 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 54 | |
| 55 | c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0); |
Allan Stephens | 08c80e9 | 2010-12-31 18:59:17 +0000 | [diff] [blame] | 56 | max_nodes = tipc_max_nodes + 1; |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 57 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 58 | c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 59 | if (c_ptr->nodes == NULL) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 60 | warn("Cluster creation failure, no memory for node area\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 61 | kfree(c_ptr); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 62 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 63 | } |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 64 | |
Allan Stephens | 51a8e4d | 2010-12-31 18:59:18 +0000 | [diff] [blame^] | 65 | tipc_local_nodes = c_ptr->nodes; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 66 | c_ptr->highest_node = 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 67 | |
Allan Stephens | 51f98a8 | 2010-12-31 18:59:16 +0000 | [diff] [blame] | 68 | tipc_net.clusters[1] = c_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 69 | return c_ptr; |
| 70 | } |
| 71 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 72 | void tipc_cltr_delete(struct cluster *c_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 73 | { |
| 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 Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 79 | tipc_node_delete(c_ptr->nodes[n_num]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 80 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 81 | kfree(c_ptr->nodes); |
| 82 | kfree(c_ptr); |
| 83 | } |
| 84 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 85 | |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 86 | void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 87 | { |
| 88 | u32 n_num = tipc_node(n_ptr->addr); |
| 89 | u32 max_n_num = tipc_max_nodes; |
| 90 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 91 | assert(n_num > 0); |
| 92 | assert(n_num <= max_n_num); |
Harvey Harrison | 5f2f40a | 2008-02-24 18:38:31 -0800 | [diff] [blame] | 93 | assert(c_ptr->nodes[n_num] == NULL); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 94 | 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 Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 100 | * tipc_cltr_broadcast - broadcast message to all nodes within cluster |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | */ |
| 102 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 103 | void tipc_cltr_broadcast(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 104 | { |
| 105 | struct sk_buff *buf_copy; |
| 106 | struct cluster *c_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 107 | struct tipc_node *n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 108 | u32 n_num; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 109 | |
| 110 | if (tipc_mode == TIPC_NET_MODE) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 111 | c_ptr = tipc_cltr_find(tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 112 | |
Allan Stephens | 08c80e9 | 2010-12-31 18:59:17 +0000 | [diff] [blame] | 113 | /* 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 124 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | exit: |
| 128 | buf_discard(buf); |
| 129 | } |
| 130 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 131 | int tipc_cltr_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 132 | { |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 133 | return tipc_cltr_create(tipc_own_addr) ? 0 : -ENOMEM; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 134 | } |
| 135 | |