Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/name_table.c: TIPC name table code |
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 |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 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. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. |
| 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 |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "config.h" |
| 39 | #include "dbg.h" |
| 40 | #include "name_table.h" |
| 41 | #include "name_distr.h" |
| 42 | #include "addr.h" |
| 43 | #include "node_subscr.h" |
| 44 | #include "subscr.h" |
| 45 | #include "port.h" |
| 46 | #include "cluster.h" |
| 47 | #include "bcast.h" |
| 48 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 49 | static int tipc_nametbl_size = 1024; /* must be a power of 2 */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * struct sub_seq - container for all published instances of a name sequence |
| 53 | * @lower: name sequence lower bound |
| 54 | * @upper: name sequence upper bound |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 55 | * @node_list: circular list of publications made by own node |
| 56 | * @cluster_list: circular list of publications made by own cluster |
| 57 | * @zone_list: circular list of publications made by own zone |
| 58 | * @node_list_size: number of entries in "node_list" |
| 59 | * @cluster_list_size: number of entries in "cluster_list" |
| 60 | * @zone_list_size: number of entries in "zone_list" |
| 61 | * |
| 62 | * Note: The zone list always contains at least one entry, since all |
| 63 | * publications of the associated name sequence belong to it. |
| 64 | * (The cluster and node lists may be empty.) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 65 | */ |
| 66 | |
| 67 | struct sub_seq { |
| 68 | u32 lower; |
| 69 | u32 upper; |
| 70 | struct publication *node_list; |
| 71 | struct publication *cluster_list; |
| 72 | struct publication *zone_list; |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 73 | u32 node_list_size; |
| 74 | u32 cluster_list_size; |
| 75 | u32 zone_list_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 78 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 79 | * struct name_seq - container for all published instances of a name type |
| 80 | * @type: 32 bit 'type' value for name sequence |
| 81 | * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type'; |
| 82 | * sub-sequences are sorted in ascending order |
| 83 | * @alloc: number of sub-sequences currently in array |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 84 | * @first_free: array index of first unused sub-sequence entry |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 85 | * @ns_list: links to adjacent name sequences in hash chain |
| 86 | * @subscriptions: list of subscriptions for this 'type' |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 87 | * @lock: spinlock controlling access to publication lists of all sub-sequences |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 88 | */ |
| 89 | |
| 90 | struct name_seq { |
| 91 | u32 type; |
| 92 | struct sub_seq *sseqs; |
| 93 | u32 alloc; |
| 94 | u32 first_free; |
| 95 | struct hlist_node ns_list; |
| 96 | struct list_head subscriptions; |
| 97 | spinlock_t lock; |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * struct name_table - table containing all existing port name publications |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 102 | * @types: pointer to fixed-sized array of name sequence lists, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 103 | * accessed via hashing on 'type'; name sequence lists are *not* sorted |
| 104 | * @local_publ_count: number of publications issued by this node |
| 105 | */ |
| 106 | |
| 107 | struct name_table { |
| 108 | struct hlist_head *types; |
| 109 | u32 local_publ_count; |
| 110 | }; |
| 111 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 112 | static struct name_table table = { NULL } ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 113 | static atomic_t rsv_publ_ok = ATOMIC_INIT(0); |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 114 | DEFINE_RWLOCK(tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 115 | |
| 116 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 117 | static int hash(int x) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 118 | { |
| 119 | return(x & (tipc_nametbl_size - 1)); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * publ_create - create a publication structure |
| 124 | */ |
| 125 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 126 | static struct publication *publ_create(u32 type, u32 lower, u32 upper, |
| 127 | u32 scope, u32 node, u32 port_ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 128 | u32 key) |
| 129 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 130 | struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 131 | if (publ == NULL) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 132 | warn("Publication creation failure, no memory\n"); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 133 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | publ->type = type; |
| 137 | publ->lower = lower; |
| 138 | publ->upper = upper; |
| 139 | publ->scope = scope; |
| 140 | publ->node = node; |
| 141 | publ->ref = port_ref; |
| 142 | publ->key = key; |
| 143 | INIT_LIST_HEAD(&publ->local_list); |
| 144 | INIT_LIST_HEAD(&publ->pport_list); |
| 145 | INIT_LIST_HEAD(&publ->subscr.nodesub_list); |
| 146 | return publ; |
| 147 | } |
| 148 | |
| 149 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 150 | * tipc_subseq_alloc - allocate a specified number of sub-sequence structures |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 151 | */ |
| 152 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 153 | static struct sub_seq *tipc_subseq_alloc(u32 cnt) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 154 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 155 | struct sub_seq *sseq = kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 156 | return sseq; |
| 157 | } |
| 158 | |
| 159 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 160 | * tipc_nameseq_create - create a name sequence structure for the specified 'type' |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 161 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 162 | * Allocates a single sub-sequence structure and sets it to all 0's. |
| 163 | */ |
| 164 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 165 | static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 166 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 167 | struct name_seq *nseq = kzalloc(sizeof(*nseq), GFP_ATOMIC); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 168 | struct sub_seq *sseq = tipc_subseq_alloc(1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 169 | |
| 170 | if (!nseq || !sseq) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 171 | warn("Name sequence creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 172 | kfree(nseq); |
| 173 | kfree(sseq); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 174 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 177 | spin_lock_init(&nseq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 178 | nseq->type = type; |
| 179 | nseq->sseqs = sseq; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 180 | dbg("tipc_nameseq_create(): nseq = %p, type %u, ssseqs %p, ff: %u\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 181 | nseq, type, nseq->sseqs, nseq->first_free); |
| 182 | nseq->alloc = 1; |
| 183 | INIT_HLIST_NODE(&nseq->ns_list); |
| 184 | INIT_LIST_HEAD(&nseq->subscriptions); |
| 185 | hlist_add_head(&nseq->ns_list, seq_head); |
| 186 | return nseq; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * nameseq_find_subseq - find sub-sequence (if any) matching a name instance |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 191 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 192 | * Very time-critical, so binary searches through sub-sequence array. |
| 193 | */ |
| 194 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 195 | static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, |
| 196 | u32 instance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 197 | { |
| 198 | struct sub_seq *sseqs = nseq->sseqs; |
| 199 | int low = 0; |
| 200 | int high = nseq->first_free - 1; |
| 201 | int mid; |
| 202 | |
| 203 | while (low <= high) { |
| 204 | mid = (low + high) / 2; |
| 205 | if (instance < sseqs[mid].lower) |
| 206 | high = mid - 1; |
| 207 | else if (instance > sseqs[mid].upper) |
| 208 | low = mid + 1; |
| 209 | else |
| 210 | return &sseqs[mid]; |
| 211 | } |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 212 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * nameseq_locate_subseq - determine position of name instance in sub-sequence |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 217 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 218 | * Returns index in sub-sequence array of the entry that contains the specified |
| 219 | * instance value; if no entry contains that value, returns the position |
| 220 | * where a new entry for it would be inserted in the array. |
| 221 | * |
| 222 | * Note: Similar to binary search code for locating a sub-sequence. |
| 223 | */ |
| 224 | |
| 225 | static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance) |
| 226 | { |
| 227 | struct sub_seq *sseqs = nseq->sseqs; |
| 228 | int low = 0; |
| 229 | int high = nseq->first_free - 1; |
| 230 | int mid; |
| 231 | |
| 232 | while (low <= high) { |
| 233 | mid = (low + high) / 2; |
| 234 | if (instance < sseqs[mid].lower) |
| 235 | high = mid - 1; |
| 236 | else if (instance > sseqs[mid].upper) |
| 237 | low = mid + 1; |
| 238 | else |
| 239 | return mid; |
| 240 | } |
| 241 | return low; |
| 242 | } |
| 243 | |
| 244 | /** |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 245 | * tipc_nameseq_insert_publ - |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | */ |
| 247 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 248 | static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, |
| 249 | u32 type, u32 lower, u32 upper, |
| 250 | u32 scope, u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 251 | { |
| 252 | struct subscription *s; |
| 253 | struct subscription *st; |
| 254 | struct publication *publ; |
| 255 | struct sub_seq *sseq; |
| 256 | int created_subseq = 0; |
| 257 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | sseq = nameseq_find_subseq(nseq, lower); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 259 | dbg("nameseq_ins: for seq %p, {%u,%u}, found sseq %p\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 260 | nseq, type, lower, sseq); |
| 261 | if (sseq) { |
| 262 | |
| 263 | /* Lower end overlaps existing entry => need an exact match */ |
| 264 | |
| 265 | if ((sseq->lower != lower) || (sseq->upper != upper)) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 266 | warn("Cannot publish {%u,%u,%u}, overlap error\n", |
| 267 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 268 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 269 | } |
| 270 | } else { |
| 271 | u32 inspos; |
| 272 | struct sub_seq *freesseq; |
| 273 | |
| 274 | /* Find where lower end should be inserted */ |
| 275 | |
| 276 | inspos = nameseq_locate_subseq(nseq, lower); |
| 277 | |
| 278 | /* Fail if upper end overlaps into an existing entry */ |
| 279 | |
| 280 | if ((inspos < nseq->first_free) && |
| 281 | (upper >= nseq->sseqs[inspos].lower)) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 282 | warn("Cannot publish {%u,%u,%u}, overlap error\n", |
| 283 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 284 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* Ensure there is space for new sub-sequence */ |
| 288 | |
| 289 | if (nseq->first_free == nseq->alloc) { |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 290 | struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); |
| 291 | |
| 292 | if (!sseqs) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 293 | warn("Cannot publish {%u,%u,%u}, no memory\n", |
| 294 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 295 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 296 | } |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 297 | dbg("Allocated %u more sseqs\n", nseq->alloc); |
| 298 | memcpy(sseqs, nseq->sseqs, |
| 299 | nseq->alloc * sizeof(struct sub_seq)); |
| 300 | kfree(nseq->sseqs); |
| 301 | nseq->sseqs = sseqs; |
| 302 | nseq->alloc *= 2; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 303 | } |
| 304 | dbg("Have %u sseqs for type %u\n", nseq->alloc, type); |
| 305 | |
| 306 | /* Insert new sub-sequence */ |
| 307 | |
| 308 | dbg("ins in pos %u, ff = %u\n", inspos, nseq->first_free); |
| 309 | sseq = &nseq->sseqs[inspos]; |
| 310 | freesseq = &nseq->sseqs[nseq->first_free]; |
| 311 | memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof (*sseq)); |
| 312 | memset(sseq, 0, sizeof (*sseq)); |
| 313 | nseq->first_free++; |
| 314 | sseq->lower = lower; |
| 315 | sseq->upper = upper; |
| 316 | created_subseq = 1; |
| 317 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 318 | dbg("inserting {%u,%u,%u} from <0x%x:%u> into sseq %p(%u,%u) of seq %p\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 319 | type, lower, upper, node, port, sseq, |
| 320 | sseq->lower, sseq->upper, nseq); |
| 321 | |
| 322 | /* Insert a publication: */ |
| 323 | |
| 324 | publ = publ_create(type, lower, upper, scope, node, port, key); |
| 325 | if (!publ) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 326 | return NULL; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 327 | dbg("inserting publ %p, node=0x%x publ->node=0x%x, subscr->node=%p\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 328 | publ, node, publ->node, publ->subscr.node); |
| 329 | |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 330 | sseq->zone_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 331 | if (!sseq->zone_list) |
| 332 | sseq->zone_list = publ->zone_list_next = publ; |
| 333 | else { |
| 334 | publ->zone_list_next = sseq->zone_list->zone_list_next; |
| 335 | sseq->zone_list->zone_list_next = publ; |
| 336 | } |
| 337 | |
| 338 | if (in_own_cluster(node)) { |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 339 | sseq->cluster_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 340 | if (!sseq->cluster_list) |
| 341 | sseq->cluster_list = publ->cluster_list_next = publ; |
| 342 | else { |
| 343 | publ->cluster_list_next = |
| 344 | sseq->cluster_list->cluster_list_next; |
| 345 | sseq->cluster_list->cluster_list_next = publ; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if (node == tipc_own_addr) { |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 350 | sseq->node_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | if (!sseq->node_list) |
| 352 | sseq->node_list = publ->node_list_next = publ; |
| 353 | else { |
| 354 | publ->node_list_next = sseq->node_list->node_list_next; |
| 355 | sseq->node_list->node_list_next = publ; |
| 356 | } |
| 357 | } |
| 358 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 359 | /* |
| 360 | * Any subscriptions waiting for notification? |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 361 | */ |
| 362 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
| 363 | dbg("calling report_overlap()\n"); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 364 | tipc_subscr_report_overlap(s, |
| 365 | publ->lower, |
| 366 | publ->upper, |
| 367 | TIPC_PUBLISHED, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 368 | publ->ref, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 369 | publ->node, |
| 370 | created_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 371 | } |
| 372 | return publ; |
| 373 | } |
| 374 | |
| 375 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 376 | * tipc_nameseq_remove_publ - |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 377 | * |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 378 | * NOTE: There may be cases where TIPC is asked to remove a publication |
| 379 | * that is not in the name table. For example, if another node issues a |
| 380 | * publication for a name sequence that overlaps an existing name sequence |
| 381 | * the publication will not be recorded, which means the publication won't |
| 382 | * be found when the name sequence is later withdrawn by that node. |
| 383 | * A failed withdraw request simply returns a failure indication and lets the |
| 384 | * caller issue any error or warning messages associated with such a problem. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 385 | */ |
| 386 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 387 | static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst, |
| 388 | u32 node, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 389 | { |
| 390 | struct publication *publ; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 391 | struct publication *curr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 392 | struct publication *prev; |
| 393 | struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); |
| 394 | struct sub_seq *free; |
| 395 | struct subscription *s, *st; |
| 396 | int removed_subseq = 0; |
| 397 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 398 | if (!sseq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 399 | return NULL; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 400 | |
| 401 | dbg("tipc_nameseq_remove_publ: seq: %p, sseq %p, {%u,%u}, key %u\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 402 | nseq, sseq, nseq->type, inst, key); |
| 403 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 404 | /* Remove publication from zone scope list */ |
| 405 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 406 | prev = sseq->zone_list; |
| 407 | publ = sseq->zone_list->zone_list_next; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 408 | while ((publ->key != key) || (publ->ref != ref) || |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 409 | (publ->node && (publ->node != node))) { |
| 410 | prev = publ; |
| 411 | publ = publ->zone_list_next; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 412 | if (prev == sseq->zone_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 413 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 414 | /* Prevent endless loop if publication not found */ |
| 415 | |
| 416 | return NULL; |
| 417 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 418 | } |
| 419 | if (publ != sseq->zone_list) |
| 420 | prev->zone_list_next = publ->zone_list_next; |
| 421 | else if (publ->zone_list_next != publ) { |
| 422 | prev->zone_list_next = publ->zone_list_next; |
| 423 | sseq->zone_list = publ->zone_list_next; |
| 424 | } else { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 425 | sseq->zone_list = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 426 | } |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 427 | sseq->zone_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 428 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 429 | /* Remove publication from cluster scope list, if present */ |
| 430 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 431 | if (in_own_cluster(node)) { |
| 432 | prev = sseq->cluster_list; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 433 | curr = sseq->cluster_list->cluster_list_next; |
| 434 | while (curr != publ) { |
| 435 | prev = curr; |
| 436 | curr = curr->cluster_list_next; |
| 437 | if (prev == sseq->cluster_list) { |
| 438 | |
| 439 | /* Prevent endless loop for malformed list */ |
| 440 | |
| 441 | err("Unable to de-list cluster publication\n" |
| 442 | "{%u%u}, node=0x%x, ref=%u, key=%u)\n", |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 443 | publ->type, publ->lower, publ->node, |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 444 | publ->ref, publ->key); |
| 445 | goto end_cluster; |
| 446 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 447 | } |
| 448 | if (publ != sseq->cluster_list) |
| 449 | prev->cluster_list_next = publ->cluster_list_next; |
| 450 | else if (publ->cluster_list_next != publ) { |
| 451 | prev->cluster_list_next = publ->cluster_list_next; |
| 452 | sseq->cluster_list = publ->cluster_list_next; |
| 453 | } else { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 454 | sseq->cluster_list = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 455 | } |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 456 | sseq->cluster_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 457 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 458 | end_cluster: |
| 459 | |
| 460 | /* Remove publication from node scope list, if present */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 461 | |
| 462 | if (node == tipc_own_addr) { |
| 463 | prev = sseq->node_list; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 464 | curr = sseq->node_list->node_list_next; |
| 465 | while (curr != publ) { |
| 466 | prev = curr; |
| 467 | curr = curr->node_list_next; |
| 468 | if (prev == sseq->node_list) { |
| 469 | |
| 470 | /* Prevent endless loop for malformed list */ |
| 471 | |
| 472 | err("Unable to de-list node publication\n" |
| 473 | "{%u%u}, node=0x%x, ref=%u, key=%u)\n", |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 474 | publ->type, publ->lower, publ->node, |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 475 | publ->ref, publ->key); |
| 476 | goto end_node; |
| 477 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 478 | } |
| 479 | if (publ != sseq->node_list) |
| 480 | prev->node_list_next = publ->node_list_next; |
| 481 | else if (publ->node_list_next != publ) { |
| 482 | prev->node_list_next = publ->node_list_next; |
| 483 | sseq->node_list = publ->node_list_next; |
| 484 | } else { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 485 | sseq->node_list = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 486 | } |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 487 | sseq->node_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 488 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 489 | end_node: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 490 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 491 | /* Contract subseq list if no more publications for that subseq */ |
| 492 | |
| 493 | if (!sseq->zone_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 494 | free = &nseq->sseqs[nseq->first_free--]; |
| 495 | memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof (*sseq)); |
| 496 | removed_subseq = 1; |
| 497 | } |
| 498 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 499 | /* Notify any waiting subscriptions */ |
| 500 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 501 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 502 | tipc_subscr_report_overlap(s, |
| 503 | publ->lower, |
| 504 | publ->upper, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 505 | TIPC_WITHDRAWN, |
| 506 | publ->ref, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 507 | publ->node, |
| 508 | removed_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 509 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 510 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 511 | return publ; |
| 512 | } |
| 513 | |
| 514 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 515 | * tipc_nameseq_subscribe: attach a subscription, and issue |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 516 | * the prescribed number of events if there is any sub- |
| 517 | * sequence overlapping with the requested sequence |
| 518 | */ |
| 519 | |
Florian Westphal | 248bbf3 | 2007-08-02 19:26:23 -0700 | [diff] [blame] | 520 | static void tipc_nameseq_subscribe(struct name_seq *nseq, struct subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 521 | { |
| 522 | struct sub_seq *sseq = nseq->sseqs; |
| 523 | |
| 524 | list_add(&s->nameseq_list, &nseq->subscriptions); |
| 525 | |
| 526 | if (!sseq) |
| 527 | return; |
| 528 | |
| 529 | while (sseq != &nseq->sseqs[nseq->first_free]) { |
| 530 | struct publication *zl = sseq->zone_list; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 531 | if (zl && tipc_subscr_overlap(s,sseq->lower,sseq->upper)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 532 | struct publication *crs = zl; |
| 533 | int must_report = 1; |
| 534 | |
| 535 | do { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 536 | tipc_subscr_report_overlap(s, |
| 537 | sseq->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 538 | sseq->upper, |
| 539 | TIPC_PUBLISHED, |
| 540 | crs->ref, |
| 541 | crs->node, |
| 542 | must_report); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 543 | must_report = 0; |
| 544 | crs = crs->zone_list_next; |
| 545 | } while (crs != zl); |
| 546 | } |
| 547 | sseq++; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static struct name_seq *nametbl_find_seq(u32 type) |
| 552 | { |
| 553 | struct hlist_head *seq_head; |
| 554 | struct hlist_node *seq_node; |
| 555 | struct name_seq *ns; |
| 556 | |
| 557 | dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n", |
Harvey Harrison | f574179 | 2008-11-07 23:37:50 -0800 | [diff] [blame] | 558 | type, htonl(type), type, table.types, hash(type)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 559 | |
| 560 | seq_head = &table.types[hash(type)]; |
| 561 | hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { |
| 562 | if (ns->type == type) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 563 | dbg("found %p\n", ns); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 564 | return ns; |
| 565 | } |
| 566 | } |
| 567 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 568 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 569 | }; |
| 570 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 571 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, |
| 572 | u32 scope, u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 573 | { |
| 574 | struct name_seq *seq = nametbl_find_seq(type); |
| 575 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 576 | dbg("tipc_nametbl_insert_publ: {%u,%u,%u} found %p\n", type, lower, upper, seq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 577 | if (lower > upper) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 578 | warn("Failed to publish illegal {%u,%u,%u}\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 579 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 580 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 581 | } |
| 582 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 583 | dbg("Publishing {%u,%u,%u} from 0x%x\n", type, lower, upper, node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 584 | if (!seq) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 585 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 586 | dbg("tipc_nametbl_insert_publ: created %p\n", seq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 587 | } |
| 588 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 589 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 590 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 591 | return tipc_nameseq_insert_publ(seq, type, lower, upper, |
| 592 | scope, node, port, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 593 | } |
| 594 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 595 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 596 | u32 node, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 597 | { |
| 598 | struct publication *publ; |
| 599 | struct name_seq *seq = nametbl_find_seq(type); |
| 600 | |
| 601 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 602 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 603 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 604 | dbg("Withdrawing {%u,%u} from 0x%x\n", type, lower, node); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 605 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 606 | |
| 607 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 608 | hlist_del_init(&seq->ns_list); |
| 609 | kfree(seq->sseqs); |
| 610 | kfree(seq); |
| 611 | } |
| 612 | return publ; |
| 613 | } |
| 614 | |
| 615 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 616 | * tipc_nametbl_translate(): Translate tipc_name -> tipc_portid. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 617 | * Very time-critical. |
| 618 | * |
| 619 | * Note: on entry 'destnode' is the search domain used during translation; |
| 620 | * on exit it passes back the node address of the matching port (if any) |
| 621 | */ |
| 622 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 623 | u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 624 | { |
| 625 | struct sub_seq *sseq; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 626 | struct publication *publ = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 627 | struct name_seq *seq; |
| 628 | u32 ref; |
| 629 | |
| 630 | if (!in_scope(*destnode, tipc_own_addr)) |
| 631 | return 0; |
| 632 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 633 | read_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 634 | seq = nametbl_find_seq(type); |
| 635 | if (unlikely(!seq)) |
| 636 | goto not_found; |
| 637 | sseq = nameseq_find_subseq(seq, instance); |
| 638 | if (unlikely(!sseq)) |
| 639 | goto not_found; |
| 640 | spin_lock_bh(&seq->lock); |
| 641 | |
| 642 | /* Closest-First Algorithm: */ |
| 643 | if (likely(!*destnode)) { |
| 644 | publ = sseq->node_list; |
| 645 | if (publ) { |
| 646 | sseq->node_list = publ->node_list_next; |
| 647 | found: |
| 648 | ref = publ->ref; |
| 649 | *destnode = publ->node; |
| 650 | spin_unlock_bh(&seq->lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 651 | read_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 652 | return ref; |
| 653 | } |
| 654 | publ = sseq->cluster_list; |
| 655 | if (publ) { |
| 656 | sseq->cluster_list = publ->cluster_list_next; |
| 657 | goto found; |
| 658 | } |
| 659 | publ = sseq->zone_list; |
| 660 | if (publ) { |
| 661 | sseq->zone_list = publ->zone_list_next; |
| 662 | goto found; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | /* Round-Robin Algorithm: */ |
| 667 | else if (*destnode == tipc_own_addr) { |
| 668 | publ = sseq->node_list; |
| 669 | if (publ) { |
| 670 | sseq->node_list = publ->node_list_next; |
| 671 | goto found; |
| 672 | } |
| 673 | } else if (in_own_cluster(*destnode)) { |
| 674 | publ = sseq->cluster_list; |
| 675 | if (publ) { |
| 676 | sseq->cluster_list = publ->cluster_list_next; |
| 677 | goto found; |
| 678 | } |
| 679 | } else { |
| 680 | publ = sseq->zone_list; |
| 681 | if (publ) { |
| 682 | sseq->zone_list = publ->zone_list_next; |
| 683 | goto found; |
| 684 | } |
| 685 | } |
| 686 | spin_unlock_bh(&seq->lock); |
| 687 | not_found: |
| 688 | *destnode = 0; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 689 | read_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 694 | * tipc_nametbl_mc_translate - find multicast destinations |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 695 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 696 | * Creates list of all local ports that overlap the given multicast address; |
| 697 | * also determines if any off-node ports overlap. |
| 698 | * |
| 699 | * Note: Publications with a scope narrower than 'limit' are ignored. |
| 700 | * (i.e. local node-scope publications mustn't receive messages arriving |
| 701 | * from another node, even if the multcast link brought it here) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 702 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 703 | * Returns non-zero if any off-node ports overlap |
| 704 | */ |
| 705 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 706 | int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, |
| 707 | struct port_list *dports) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 708 | { |
| 709 | struct name_seq *seq; |
| 710 | struct sub_seq *sseq; |
| 711 | struct sub_seq *sseq_stop; |
| 712 | int res = 0; |
| 713 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 714 | read_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 715 | seq = nametbl_find_seq(type); |
| 716 | if (!seq) |
| 717 | goto exit; |
| 718 | |
| 719 | spin_lock_bh(&seq->lock); |
| 720 | |
| 721 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); |
| 722 | sseq_stop = seq->sseqs + seq->first_free; |
| 723 | for (; sseq != sseq_stop; sseq++) { |
| 724 | struct publication *publ; |
| 725 | |
| 726 | if (sseq->lower > upper) |
| 727 | break; |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 728 | |
| 729 | publ = sseq->node_list; |
| 730 | if (publ) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 731 | do { |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 732 | if (publ->scope <= limit) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 733 | tipc_port_list_add(dports, publ->ref); |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 734 | publ = publ->node_list_next; |
| 735 | } while (publ != sseq->node_list); |
| 736 | } |
| 737 | |
| 738 | if (sseq->cluster_list_size != sseq->node_list_size) |
| 739 | res = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | spin_unlock_bh(&seq->lock); |
| 743 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 744 | read_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 745 | return res; |
| 746 | } |
| 747 | |
| 748 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 749 | * tipc_nametbl_publish_rsv - publish port name using a reserved name type |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 750 | */ |
| 751 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 752 | int tipc_nametbl_publish_rsv(u32 ref, unsigned int scope, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 753 | struct tipc_name_seq const *seq) |
| 754 | { |
| 755 | int res; |
| 756 | |
| 757 | atomic_inc(&rsv_publ_ok); |
| 758 | res = tipc_publish(ref, scope, seq); |
| 759 | atomic_dec(&rsv_publ_ok); |
| 760 | return res; |
| 761 | } |
| 762 | |
| 763 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 764 | * tipc_nametbl_publish - add name publication to network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 765 | */ |
| 766 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 767 | struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 768 | u32 scope, u32 port_ref, u32 key) |
| 769 | { |
| 770 | struct publication *publ; |
| 771 | |
| 772 | if (table.local_publ_count >= tipc_max_publications) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 773 | warn("Publication failed, local publication limit reached (%u)\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 774 | tipc_max_publications); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 775 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 776 | } |
| 777 | if ((type < TIPC_RESERVED_TYPES) && !atomic_read(&rsv_publ_ok)) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 778 | warn("Publication failed, reserved name {%u,%u,%u}\n", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 779 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 780 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 783 | write_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 784 | table.local_publ_count++; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 785 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 786 | tipc_own_addr, port_ref, key); |
| 787 | if (publ && (scope != TIPC_NODE_SCOPE)) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 788 | tipc_named_publish(publ); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 789 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 790 | write_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 791 | return publ; |
| 792 | } |
| 793 | |
| 794 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 795 | * tipc_nametbl_withdraw - withdraw name publication from network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 796 | */ |
| 797 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 798 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 799 | { |
| 800 | struct publication *publ; |
| 801 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 802 | dbg("tipc_nametbl_withdraw: {%u,%u}, key=%u\n", type, lower, key); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 803 | write_lock_bh(&tipc_nametbl_lock); |
| 804 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 805 | if (likely(publ)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 806 | table.local_publ_count--; |
| 807 | if (publ->scope != TIPC_NODE_SCOPE) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 808 | tipc_named_withdraw(publ); |
| 809 | write_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 810 | list_del_init(&publ->pport_list); |
| 811 | kfree(publ); |
| 812 | return 1; |
| 813 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 814 | write_unlock_bh(&tipc_nametbl_lock); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 815 | err("Unable to remove local publication\n" |
| 816 | "(type=%u, lower=%u, ref=%u, key=%u)\n", |
| 817 | type, lower, ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 822 | * tipc_nametbl_subscribe - add a subscription object to the name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 823 | */ |
| 824 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 825 | void tipc_nametbl_subscribe(struct subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 826 | { |
| 827 | u32 type = s->seq.type; |
| 828 | struct name_seq *seq; |
| 829 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 830 | write_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 831 | seq = nametbl_find_seq(type); |
| 832 | if (!seq) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 833 | seq = tipc_nameseq_create(type, &table.types[hash(type)]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 834 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 835 | if (seq){ |
| 836 | spin_lock_bh(&seq->lock); |
| 837 | dbg("tipc_nametbl_subscribe:found %p for {%u,%u,%u}\n", |
| 838 | seq, type, s->seq.lower, s->seq.upper); |
| 839 | tipc_nameseq_subscribe(seq, s); |
| 840 | spin_unlock_bh(&seq->lock); |
| 841 | } else { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 842 | warn("Failed to create subscription for {%u,%u,%u}\n", |
| 843 | s->seq.type, s->seq.lower, s->seq.upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 844 | } |
| 845 | write_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 849 | * tipc_nametbl_unsubscribe - remove a subscription object from name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 850 | */ |
| 851 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 852 | void tipc_nametbl_unsubscribe(struct subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 853 | { |
| 854 | struct name_seq *seq; |
| 855 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 856 | write_lock_bh(&tipc_nametbl_lock); |
| 857 | seq = nametbl_find_seq(s->seq.type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 858 | if (seq != NULL){ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 859 | spin_lock_bh(&seq->lock); |
| 860 | list_del_init(&s->nameseq_list); |
| 861 | spin_unlock_bh(&seq->lock); |
| 862 | if ((seq->first_free == 0) && list_empty(&seq->subscriptions)) { |
| 863 | hlist_del_init(&seq->ns_list); |
| 864 | kfree(seq->sseqs); |
| 865 | kfree(seq); |
| 866 | } |
| 867 | } |
| 868 | write_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | /** |
| 873 | * subseq_list: print specified sub-sequence contents into the given buffer |
| 874 | */ |
| 875 | |
| 876 | static void subseq_list(struct sub_seq *sseq, struct print_buf *buf, u32 depth, |
| 877 | u32 index) |
| 878 | { |
| 879 | char portIdStr[27]; |
| 880 | char *scopeStr; |
| 881 | struct publication *publ = sseq->zone_list; |
| 882 | |
| 883 | tipc_printf(buf, "%-10u %-10u ", sseq->lower, sseq->upper); |
| 884 | |
| 885 | if (depth == 2 || !publ) { |
| 886 | tipc_printf(buf, "\n"); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | do { |
| 891 | sprintf (portIdStr, "<%u.%u.%u:%u>", |
| 892 | tipc_zone(publ->node), tipc_cluster(publ->node), |
| 893 | tipc_node(publ->node), publ->ref); |
| 894 | tipc_printf(buf, "%-26s ", portIdStr); |
| 895 | if (depth > 3) { |
| 896 | if (publ->node != tipc_own_addr) |
| 897 | scopeStr = ""; |
| 898 | else if (publ->scope == TIPC_NODE_SCOPE) |
| 899 | scopeStr = "node"; |
| 900 | else if (publ->scope == TIPC_CLUSTER_SCOPE) |
| 901 | scopeStr = "cluster"; |
| 902 | else |
| 903 | scopeStr = "zone"; |
| 904 | tipc_printf(buf, "%-10u %s", publ->key, scopeStr); |
| 905 | } |
| 906 | |
| 907 | publ = publ->zone_list_next; |
| 908 | if (publ == sseq->zone_list) |
| 909 | break; |
| 910 | |
| 911 | tipc_printf(buf, "\n%33s", " "); |
| 912 | } while (1); |
| 913 | |
| 914 | tipc_printf(buf, "\n"); |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * nameseq_list: print specified name sequence contents into the given buffer |
| 919 | */ |
| 920 | |
| 921 | static void nameseq_list(struct name_seq *seq, struct print_buf *buf, u32 depth, |
| 922 | u32 type, u32 lowbound, u32 upbound, u32 index) |
| 923 | { |
| 924 | struct sub_seq *sseq; |
| 925 | char typearea[11]; |
| 926 | |
Allan Stephens | 0f15d36 | 2008-06-04 17:37:59 -0700 | [diff] [blame] | 927 | if (seq->first_free == 0) |
| 928 | return; |
| 929 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 930 | sprintf(typearea, "%-10u", seq->type); |
| 931 | |
| 932 | if (depth == 1) { |
| 933 | tipc_printf(buf, "%s\n", typearea); |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | for (sseq = seq->sseqs; sseq != &seq->sseqs[seq->first_free]; sseq++) { |
| 938 | if ((lowbound <= sseq->upper) && (upbound >= sseq->lower)) { |
| 939 | tipc_printf(buf, "%s ", typearea); |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 940 | spin_lock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 941 | subseq_list(sseq, buf, depth, index); |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 942 | spin_unlock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 943 | sprintf(typearea, "%10s", " "); |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * nametbl_header - print name table header into the given buffer |
| 950 | */ |
| 951 | |
| 952 | static void nametbl_header(struct print_buf *buf, u32 depth) |
| 953 | { |
| 954 | tipc_printf(buf, "Type "); |
| 955 | |
| 956 | if (depth > 1) |
| 957 | tipc_printf(buf, "Lower Upper "); |
| 958 | if (depth > 2) |
| 959 | tipc_printf(buf, "Port Identity "); |
| 960 | if (depth > 3) |
| 961 | tipc_printf(buf, "Publication"); |
| 962 | |
| 963 | tipc_printf(buf, "\n-----------"); |
| 964 | |
| 965 | if (depth > 1) |
| 966 | tipc_printf(buf, "--------------------- "); |
| 967 | if (depth > 2) |
| 968 | tipc_printf(buf, "-------------------------- "); |
| 969 | if (depth > 3) |
| 970 | tipc_printf(buf, "------------------"); |
| 971 | |
| 972 | tipc_printf(buf, "\n"); |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * nametbl_list - print specified name table contents into the given buffer |
| 977 | */ |
| 978 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 979 | static void nametbl_list(struct print_buf *buf, u32 depth_info, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 980 | u32 type, u32 lowbound, u32 upbound) |
| 981 | { |
| 982 | struct hlist_head *seq_head; |
| 983 | struct hlist_node *seq_node; |
| 984 | struct name_seq *seq; |
| 985 | int all_types; |
| 986 | u32 depth; |
| 987 | u32 i; |
| 988 | |
| 989 | all_types = (depth_info & TIPC_NTQ_ALLTYPES); |
| 990 | depth = (depth_info & ~TIPC_NTQ_ALLTYPES); |
| 991 | |
| 992 | if (depth == 0) |
| 993 | return; |
| 994 | |
| 995 | if (all_types) { |
| 996 | /* display all entries in name table to specified depth */ |
| 997 | nametbl_header(buf, depth); |
| 998 | lowbound = 0; |
| 999 | upbound = ~0; |
| 1000 | for (i = 0; i < tipc_nametbl_size; i++) { |
| 1001 | seq_head = &table.types[i]; |
| 1002 | hlist_for_each_entry(seq, seq_node, seq_head, ns_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1003 | nameseq_list(seq, buf, depth, seq->type, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | lowbound, upbound, i); |
| 1005 | } |
| 1006 | } |
| 1007 | } else { |
| 1008 | /* display only the sequence that matches the specified type */ |
| 1009 | if (upbound < lowbound) { |
| 1010 | tipc_printf(buf, "invalid name sequence specified\n"); |
| 1011 | return; |
| 1012 | } |
| 1013 | nametbl_header(buf, depth); |
| 1014 | i = hash(type); |
| 1015 | seq_head = &table.types[i]; |
| 1016 | hlist_for_each_entry(seq, seq_node, seq_head, ns_list) { |
| 1017 | if (seq->type == type) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1018 | nameseq_list(seq, buf, depth, type, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1019 | lowbound, upbound, i); |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 1026 | #if 0 |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1027 | void tipc_nametbl_print(struct print_buf *buf, const char *str) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1028 | { |
| 1029 | tipc_printf(buf, str); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1030 | read_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1031 | nametbl_list(buf, 0, 0, 0, 0); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1032 | read_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1033 | } |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 1034 | #endif |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1035 | |
| 1036 | #define MAX_NAME_TBL_QUERY 32768 |
| 1037 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1038 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1039 | { |
| 1040 | struct sk_buff *buf; |
| 1041 | struct tipc_name_table_query *argv; |
| 1042 | struct tlv_desc *rep_tlv; |
| 1043 | struct print_buf b; |
| 1044 | int str_len; |
| 1045 | |
| 1046 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NAME_TBL_QUERY)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1047 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1048 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1049 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_NAME_TBL_QUERY)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1050 | if (!buf) |
| 1051 | return NULL; |
| 1052 | |
| 1053 | rep_tlv = (struct tlv_desc *)buf->data; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1054 | tipc_printbuf_init(&b, TLV_DATA(rep_tlv), MAX_NAME_TBL_QUERY); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1055 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1056 | read_lock_bh(&tipc_nametbl_lock); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 1057 | nametbl_list(&b, ntohl(argv->depth), ntohl(argv->type), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1058 | ntohl(argv->lowbound), ntohl(argv->upbound)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1059 | read_unlock_bh(&tipc_nametbl_lock); |
| 1060 | str_len = tipc_printbuf_validate(&b); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1061 | |
| 1062 | skb_put(buf, TLV_SPACE(str_len)); |
| 1063 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 1064 | |
| 1065 | return buf; |
| 1066 | } |
| 1067 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 1068 | #if 0 |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1069 | void tipc_nametbl_dump(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1070 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1071 | nametbl_list(TIPC_CONS, 0, 0, 0, 0); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1072 | } |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 1073 | #endif |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1074 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1075 | int tipc_nametbl_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1076 | { |
Allan Stephens | 4e3e6dc | 2008-05-12 15:41:53 -0700 | [diff] [blame] | 1077 | table.types = kcalloc(tipc_nametbl_size, sizeof(struct hlist_head), |
| 1078 | GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1079 | if (!table.types) |
| 1080 | return -ENOMEM; |
| 1081 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1082 | table.local_publ_count = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1083 | return 0; |
| 1084 | } |
| 1085 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1086 | void tipc_nametbl_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1087 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1088 | u32 i; |
| 1089 | |
| 1090 | if (!table.types) |
| 1091 | return; |
| 1092 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 1093 | /* Verify name table is empty, then release it */ |
| 1094 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1095 | write_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1096 | for (i = 0; i < tipc_nametbl_size; i++) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 1097 | if (!hlist_empty(&table.types[i])) |
| 1098 | err("tipc_nametbl_stop(): hash chain %u is non-null\n", i); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1099 | } |
| 1100 | kfree(table.types); |
| 1101 | table.types = NULL; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 1102 | write_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1103 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 1104 | |