node.c (51a8e4dee7653698ba4c6e7de71053665f075273) node.c (8f92df6ad49da958d97e171762d0a97a3dc738f1)
1/*
2 * net/tipc/node.c: TIPC node management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005-2006, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 48 unchanged lines hidden (view full) ---

57 * net_lock for reading only. We must take node_create_lock to ensure a node
58 * isn't created twice if two different bearers discover the node at the same
59 * time. (It would be preferable to switch to holding net_lock in write mode,
60 * but this is a non-trivial change.)
61 */
62
63struct tipc_node *tipc_node_create(u32 addr)
64{
1/*
2 * net/tipc/node.c: TIPC node management routines
3 *
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2005-2006, Wind River Systems
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 48 unchanged lines hidden (view full) ---

57 * net_lock for reading only. We must take node_create_lock to ensure a node
58 * isn't created twice if two different bearers discover the node at the same
59 * time. (It would be preferable to switch to holding net_lock in write mode,
60 * but this is a non-trivial change.)
61 */
62
63struct tipc_node *tipc_node_create(u32 addr)
64{
65 struct cluster *c_ptr;
66 struct tipc_node *n_ptr;
67 struct tipc_node **curr_node;
65 struct tipc_node *n_ptr;
66 struct tipc_node **curr_node;
67 u32 n_num;
68
69 spin_lock_bh(&node_create_lock);
70
71 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
72 if (addr < n_ptr->addr)
73 break;
74 if (addr == n_ptr->addr) {
75 spin_unlock_bh(&node_create_lock);
76 return n_ptr;
77 }
78 }
79
80 n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC);
81 if (!n_ptr) {
82 spin_unlock_bh(&node_create_lock);
83 warn("Node creation failed, no memory\n");
84 return NULL;
85 }
86
68
69 spin_lock_bh(&node_create_lock);
70
71 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
72 if (addr < n_ptr->addr)
73 break;
74 if (addr == n_ptr->addr) {
75 spin_unlock_bh(&node_create_lock);
76 return n_ptr;
77 }
78 }
79
80 n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC);
81 if (!n_ptr) {
82 spin_unlock_bh(&node_create_lock);
83 warn("Node creation failed, no memory\n");
84 return NULL;
85 }
86
87 c_ptr = tipc_cltr_find(addr);
88 if (!c_ptr) {
89 c_ptr = tipc_cltr_create(addr);
90 }
91 if (!c_ptr) {
92 spin_unlock_bh(&node_create_lock);
93 kfree(n_ptr);
94 return NULL;
95 }
96
97 n_ptr->addr = addr;
98 spin_lock_init(&n_ptr->lock);
99 INIT_LIST_HEAD(&n_ptr->nsub);
87 n_ptr->addr = addr;
88 spin_lock_init(&n_ptr->lock);
89 INIT_LIST_HEAD(&n_ptr->nsub);
100 n_ptr->owner = c_ptr;
101 tipc_cltr_attach_node(c_ptr, n_ptr);
102
90
91 n_num = tipc_node(addr);
92 tipc_net.nodes[n_num] = n_ptr;
93 if (n_num > tipc_net.highest_node)
94 tipc_net.highest_node = n_num;
95
103 /* Insert node into ordered list */
104 for (curr_node = &tipc_nodes; *curr_node;
105 curr_node = &(*curr_node)->next) {
106 if (addr < (*curr_node)->addr) {
107 n_ptr->next = *curr_node;
108 break;
109 }
110 }
111 (*curr_node) = n_ptr;
112 spin_unlock_bh(&node_create_lock);
113 return n_ptr;
114}
115
116void tipc_node_delete(struct tipc_node *n_ptr)
117{
96 /* Insert node into ordered list */
97 for (curr_node = &tipc_nodes; *curr_node;
98 curr_node = &(*curr_node)->next) {
99 if (addr < (*curr_node)->addr) {
100 n_ptr->next = *curr_node;
101 break;
102 }
103 }
104 (*curr_node) = n_ptr;
105 spin_unlock_bh(&node_create_lock);
106 return n_ptr;
107}
108
109void tipc_node_delete(struct tipc_node *n_ptr)
110{
111 u32 n_num;
112
118 if (!n_ptr)
119 return;
120
121 dbg("node %x deleted\n", n_ptr->addr);
113 if (!n_ptr)
114 return;
115
116 dbg("node %x deleted\n", n_ptr->addr);
117 n_num = tipc_node(n_ptr->addr);
118 tipc_net.nodes[n_num] = NULL;
122 kfree(n_ptr);
119 kfree(n_ptr);
120
121 while (!tipc_net.nodes[tipc_net.highest_node])
122 if (--tipc_net.highest_node == 0)
123 break;
123}
124
125
126/**
127 * tipc_node_link_up - handle addition of link
128 *
129 * Link becomes active (alone or shared) or standby, depending on its priority.
130 */

--- 188 unchanged lines hidden (view full) ---

319{
320 dbg("node_established_contact:-> %x\n", n_ptr->addr);
321 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
322
323 /* Syncronize broadcast acks */
324 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
325
326 if (n_ptr->bclink.supported) {
124}
125
126
127/**
128 * tipc_node_link_up - handle addition of link
129 *
130 * Link becomes active (alone or shared) or standby, depending on its priority.
131 */

--- 188 unchanged lines hidden (view full) ---

320{
321 dbg("node_established_contact:-> %x\n", n_ptr->addr);
322 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
323
324 /* Syncronize broadcast acks */
325 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
326
327 if (n_ptr->bclink.supported) {
327 tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr);
328 tipc_nmap_add(&tipc_bcast_nmap, n_ptr->addr);
328 if (n_ptr->addr < tipc_own_addr)
329 tipc_own_tag++;
330 }
331}
332
333static void node_cleanup_finished(unsigned long node_addr)
334{
335 struct tipc_node *n_ptr;

--- 20 unchanged lines hidden (view full) ---

356 struct sk_buff* buf = n_ptr->bclink.deferred_head;
357 n_ptr->bclink.deferred_head = buf->next;
358 buf_discard(buf);
359 }
360 if (n_ptr->bclink.defragm) {
361 buf_discard(n_ptr->bclink.defragm);
362 n_ptr->bclink.defragm = NULL;
363 }
329 if (n_ptr->addr < tipc_own_addr)
330 tipc_own_tag++;
331 }
332}
333
334static void node_cleanup_finished(unsigned long node_addr)
335{
336 struct tipc_node *n_ptr;

--- 20 unchanged lines hidden (view full) ---

357 struct sk_buff* buf = n_ptr->bclink.deferred_head;
358 n_ptr->bclink.deferred_head = buf->next;
359 buf_discard(buf);
360 }
361 if (n_ptr->bclink.defragm) {
362 buf_discard(n_ptr->bclink.defragm);
363 n_ptr->bclink.defragm = NULL;
364 }
364 if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {
365 tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
366 }
367
365
368 /* Update routing tables */
369 if (n_ptr->bclink.supported) {
366 if (n_ptr->bclink.supported) {
370 tipc_nmap_remove(&tipc_cltr_bcast_nodes, n_ptr->addr);
367 tipc_bclink_acknowledge(n_ptr,
368 mod(n_ptr->bclink.acked + 10000));
369 tipc_nmap_remove(&tipc_bcast_nmap, n_ptr->addr);
371 if (n_ptr->addr < tipc_own_addr)
372 tipc_own_tag--;
373 }
374
375 info("Lost contact with %s\n",
376 tipc_addr_string_fill(addr_string, n_ptr->addr));
377
378 /* Abort link changeover */

--- 139 unchanged lines hidden ---
370 if (n_ptr->addr < tipc_own_addr)
371 tipc_own_tag--;
372 }
373
374 info("Lost contact with %s\n",
375 tipc_addr_string_fill(addr_string, n_ptr->addr));
376
377 /* Abort link changeover */

--- 139 unchanged lines hidden ---