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