Commit 37b9c08a88f9a82456bb11fa050cccb544e8dc60
Committed by
Paul Gortmaker
1 parent
fa2bae2d5b
Exists in
master
and in
39 other branches
tipc: Optimizations to link creation code
Enhances link creation code as follows: 1) Detects illegal attempts to add a requested link earlier in the link creation process. This prevents TIPC from wasting time initializing a link object it then throws away, and also eliminates the code needed to do the throwing away. 2) Passes in the node object associated with the requested link. This allows TIPC to eliminate a search to locate the node object, as well as code that attempted to create the node if it doesn't exist. Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Showing 5 changed files with 28 additions and 36 deletions Side-by-side Diff
net/tipc/discover.c
... | ... | @@ -169,7 +169,7 @@ |
169 | 169 | |
170 | 170 | /* Create a link endpoint for this bearer, if necessary */ |
171 | 171 | if (!link) { |
172 | - link = tipc_link_create(b_ptr, orig, &media_addr); | |
172 | + link = tipc_link_create(n_ptr, b_ptr, &media_addr); | |
173 | 173 | if (!link) { |
174 | 174 | tipc_node_unlock(n_ptr); |
175 | 175 | return; |
net/tipc/link.c
... | ... | @@ -293,20 +293,36 @@ |
293 | 293 | |
294 | 294 | /** |
295 | 295 | * tipc_link_create - create a new link |
296 | + * @n_ptr: pointer to associated node | |
296 | 297 | * @b_ptr: pointer to associated bearer |
297 | - * @peer: network address of node at other end of link | |
298 | 298 | * @media_addr: media address to use when sending messages over link |
299 | 299 | * |
300 | 300 | * Returns pointer to link. |
301 | 301 | */ |
302 | 302 | |
303 | -struct link *tipc_link_create(struct tipc_bearer *b_ptr, const u32 peer, | |
303 | +struct link *tipc_link_create(struct tipc_node *n_ptr, | |
304 | + struct tipc_bearer *b_ptr, | |
304 | 305 | const struct tipc_media_addr *media_addr) |
305 | 306 | { |
306 | 307 | struct link *l_ptr; |
307 | 308 | struct tipc_msg *msg; |
308 | 309 | char *if_name; |
310 | + char addr_string[16]; | |
311 | + u32 peer = n_ptr->addr; | |
309 | 312 | |
313 | + if (n_ptr->link_cnt >= 2) { | |
314 | + tipc_addr_string_fill(addr_string, n_ptr->addr); | |
315 | + err("Attempt to establish third link to %s\n", addr_string); | |
316 | + return NULL; | |
317 | + } | |
318 | + | |
319 | + if (n_ptr->links[b_ptr->identity]) { | |
320 | + tipc_addr_string_fill(addr_string, n_ptr->addr); | |
321 | + err("Attempt to establish second link on <%s> to %s\n", | |
322 | + b_ptr->name, addr_string); | |
323 | + return NULL; | |
324 | + } | |
325 | + | |
310 | 326 | l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC); |
311 | 327 | if (!l_ptr) { |
312 | 328 | warn("Link creation failed, no memory\n"); |
... | ... | @@ -322,6 +338,7 @@ |
322 | 338 | tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); |
323 | 339 | /* note: peer i/f is appended to link name by reset/activate */ |
324 | 340 | memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr)); |
341 | + l_ptr->owner = n_ptr; | |
325 | 342 | l_ptr->checkpoint = 1; |
326 | 343 | l_ptr->b_ptr = b_ptr; |
327 | 344 | link_set_supervision_props(l_ptr, b_ptr->media->tolerance); |
... | ... | @@ -345,11 +362,7 @@ |
345 | 362 | |
346 | 363 | link_reset_statistics(l_ptr); |
347 | 364 | |
348 | - l_ptr->owner = tipc_node_attach_link(l_ptr); | |
349 | - if (!l_ptr->owner) { | |
350 | - kfree(l_ptr); | |
351 | - return NULL; | |
352 | - } | |
365 | + tipc_node_attach_link(n_ptr, l_ptr); | |
353 | 366 | |
354 | 367 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr); |
355 | 368 | list_add_tail(&l_ptr->link_list, &b_ptr->links); |
net/tipc/link.h
... | ... | @@ -207,7 +207,8 @@ |
207 | 207 | |
208 | 208 | struct tipc_port; |
209 | 209 | |
210 | -struct link *tipc_link_create(struct tipc_bearer *b_ptr, const u32 peer, | |
210 | +struct link *tipc_link_create(struct tipc_node *n_ptr, | |
211 | + struct tipc_bearer *b_ptr, | |
211 | 212 | const struct tipc_media_addr *media_addr); |
212 | 213 | void tipc_link_delete(struct link *l_ptr); |
213 | 214 | void tipc_link_changeover(struct link *l_ptr); |
net/tipc/node.c
... | ... | @@ -238,33 +238,11 @@ |
238 | 238 | return tipc_node_active_links(n_ptr); |
239 | 239 | } |
240 | 240 | |
241 | -struct tipc_node *tipc_node_attach_link(struct link *l_ptr) | |
241 | +void tipc_node_attach_link(struct tipc_node *n_ptr, struct link *l_ptr) | |
242 | 242 | { |
243 | - struct tipc_node *n_ptr = tipc_node_find(l_ptr->addr); | |
244 | - | |
245 | - if (!n_ptr) | |
246 | - n_ptr = tipc_node_create(l_ptr->addr); | |
247 | - if (n_ptr) { | |
248 | - u32 bearer_id = l_ptr->b_ptr->identity; | |
249 | - char addr_string[16]; | |
250 | - | |
251 | - if (n_ptr->link_cnt >= 2) { | |
252 | - err("Attempt to create third link to %s\n", | |
253 | - tipc_addr_string_fill(addr_string, n_ptr->addr)); | |
254 | - return NULL; | |
255 | - } | |
256 | - | |
257 | - if (!n_ptr->links[bearer_id]) { | |
258 | - n_ptr->links[bearer_id] = l_ptr; | |
259 | - atomic_inc(&tipc_num_links); | |
260 | - n_ptr->link_cnt++; | |
261 | - return n_ptr; | |
262 | - } | |
263 | - err("Attempt to establish second link on <%s> to %s\n", | |
264 | - l_ptr->b_ptr->name, | |
265 | - tipc_addr_string_fill(addr_string, l_ptr->addr)); | |
266 | - } | |
267 | - return NULL; | |
243 | + n_ptr->links[l_ptr->b_ptr->identity] = l_ptr; | |
244 | + atomic_inc(&tipc_num_links); | |
245 | + n_ptr->link_cnt++; | |
268 | 246 | } |
269 | 247 | |
270 | 248 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr) |
net/tipc/node.h
... | ... | @@ -111,7 +111,7 @@ |
111 | 111 | struct tipc_node *tipc_node_find(u32 addr); |
112 | 112 | struct tipc_node *tipc_node_create(u32 addr); |
113 | 113 | void tipc_node_delete(struct tipc_node *n_ptr); |
114 | -struct tipc_node *tipc_node_attach_link(struct link *l_ptr); | |
114 | +void tipc_node_attach_link(struct tipc_node *n_ptr, struct link *l_ptr); | |
115 | 115 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr); |
116 | 116 | void tipc_node_link_down(struct tipc_node *n_ptr, struct link *l_ptr); |
117 | 117 | void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr); |