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