aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/originator.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2011-02-18 07:28:09 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 06:52:00 -0500
commit7aadf889e897155c45cda230d2a6701ad1fbff61 (patch)
tree4a31df411c29844afe25ccde17d2ff9e618241c1 /net/batman-adv/originator.c
parent39901e716275da4e831b40f9e45a1b61d6a776dc (diff)
batman-adv: remove extra layer between hash and hash element - hash bucket
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/originator.c')
-rw-r--r--net/batman-adv/originator.c73
1 files changed, 21 insertions, 52 deletions
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index d9a8e316c249..bdcb399329dd 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -140,9 +140,8 @@ void orig_node_free_ref(struct kref *refcount)
140void originator_free(struct bat_priv *bat_priv) 140void originator_free(struct bat_priv *bat_priv)
141{ 141{
142 struct hashtable_t *hash = bat_priv->orig_hash; 142 struct hashtable_t *hash = bat_priv->orig_hash;
143 struct hlist_node *walk, *safe; 143 struct hlist_node *node, *node_tmp;
144 struct hlist_head *head; 144 struct hlist_head *head;
145 struct element_t *bucket;
146 spinlock_t *list_lock; /* spinlock to protect write access */ 145 spinlock_t *list_lock; /* spinlock to protect write access */
147 struct orig_node *orig_node; 146 struct orig_node *orig_node;
148 int i; 147 int i;
@@ -160,11 +159,10 @@ void originator_free(struct bat_priv *bat_priv)
160 list_lock = &hash->list_locks[i]; 159 list_lock = &hash->list_locks[i];
161 160
162 spin_lock_bh(list_lock); 161 spin_lock_bh(list_lock);
163 hlist_for_each_entry_safe(bucket, walk, safe, head, hlist) { 162 hlist_for_each_entry_safe(orig_node, node, node_tmp,
164 orig_node = bucket->data; 163 head, hash_entry) {
165 164
166 hlist_del_rcu(walk); 165 hlist_del_rcu(node);
167 call_rcu(&bucket->rcu, bucket_free_rcu);
168 kref_put(&orig_node->refcount, orig_node_free_ref); 166 kref_put(&orig_node->refcount, orig_node_free_ref);
169 } 167 }
170 spin_unlock_bh(list_lock); 168 spin_unlock_bh(list_lock);
@@ -174,18 +172,6 @@ void originator_free(struct bat_priv *bat_priv)
174 spin_unlock_bh(&bat_priv->orig_hash_lock); 172 spin_unlock_bh(&bat_priv->orig_hash_lock);
175} 173}
176 174
177static void bucket_free_orig_rcu(struct rcu_head *rcu)
178{
179 struct element_t *bucket;
180 struct orig_node *orig_node;
181
182 bucket = container_of(rcu, struct element_t, rcu);
183 orig_node = bucket->data;
184
185 kref_put(&orig_node->refcount, orig_node_free_ref);
186 kfree(bucket);
187}
188
189/* this function finds or creates an originator entry for the given 175/* this function finds or creates an originator entry for the given
190 * address if it does not exits */ 176 * address if it does not exits */
191struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr) 177struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
@@ -194,16 +180,9 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
194 int size; 180 int size;
195 int hash_added; 181 int hash_added;
196 182
197 rcu_read_lock(); 183 orig_node = orig_hash_find(bat_priv, addr);
198 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash, 184 if (orig_node)
199 compare_orig, choose_orig,
200 addr));
201 rcu_read_unlock();
202
203 if (orig_node) {
204 kref_get(&orig_node->refcount);
205 return orig_node; 185 return orig_node;
206 }
207 186
208 bat_dbg(DBG_BATMAN, bat_priv, 187 bat_dbg(DBG_BATMAN, bat_priv,
209 "Creating new originator: %pM\n", addr); 188 "Creating new originator: %pM\n", addr);
@@ -245,8 +224,8 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
245 if (!orig_node->bcast_own_sum) 224 if (!orig_node->bcast_own_sum)
246 goto free_bcast_own; 225 goto free_bcast_own;
247 226
248 hash_added = hash_add(bat_priv->orig_hash, compare_orig, choose_orig, 227 hash_added = hash_add(bat_priv->orig_hash, compare_orig,
249 orig_node); 228 choose_orig, orig_node, &orig_node->hash_entry);
250 if (hash_added < 0) 229 if (hash_added < 0)
251 goto free_bcast_own_sum; 230 goto free_bcast_own_sum;
252 231
@@ -346,9 +325,8 @@ static bool purge_orig_node(struct bat_priv *bat_priv,
346static void _purge_orig(struct bat_priv *bat_priv) 325static void _purge_orig(struct bat_priv *bat_priv)
347{ 326{
348 struct hashtable_t *hash = bat_priv->orig_hash; 327 struct hashtable_t *hash = bat_priv->orig_hash;
349 struct hlist_node *walk, *safe; 328 struct hlist_node *node, *node_tmp;
350 struct hlist_head *head; 329 struct hlist_head *head;
351 struct element_t *bucket;
352 spinlock_t *list_lock; /* spinlock to protect write access */ 330 spinlock_t *list_lock; /* spinlock to protect write access */
353 struct orig_node *orig_node; 331 struct orig_node *orig_node;
354 int i; 332 int i;
@@ -364,14 +342,14 @@ static void _purge_orig(struct bat_priv *bat_priv)
364 list_lock = &hash->list_locks[i]; 342 list_lock = &hash->list_locks[i];
365 343
366 spin_lock_bh(list_lock); 344 spin_lock_bh(list_lock);
367 hlist_for_each_entry_safe(bucket, walk, safe, head, hlist) { 345 hlist_for_each_entry_safe(orig_node, node, node_tmp,
368 orig_node = bucket->data; 346 head, hash_entry) {
369
370 if (purge_orig_node(bat_priv, orig_node)) { 347 if (purge_orig_node(bat_priv, orig_node)) {
371 if (orig_node->gw_flags) 348 if (orig_node->gw_flags)
372 gw_node_delete(bat_priv, orig_node); 349 gw_node_delete(bat_priv, orig_node);
373 hlist_del_rcu(walk); 350 hlist_del_rcu(node);
374 call_rcu(&bucket->rcu, bucket_free_orig_rcu); 351 kref_put(&orig_node->refcount,
352 orig_node_free_ref);
375 continue; 353 continue;
376 } 354 }
377 355
@@ -411,9 +389,8 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
411 struct net_device *net_dev = (struct net_device *)seq->private; 389 struct net_device *net_dev = (struct net_device *)seq->private;
412 struct bat_priv *bat_priv = netdev_priv(net_dev); 390 struct bat_priv *bat_priv = netdev_priv(net_dev);
413 struct hashtable_t *hash = bat_priv->orig_hash; 391 struct hashtable_t *hash = bat_priv->orig_hash;
414 struct hlist_node *walk, *node; 392 struct hlist_node *node, *node_tmp;
415 struct hlist_head *head; 393 struct hlist_head *head;
416 struct element_t *bucket;
417 struct orig_node *orig_node; 394 struct orig_node *orig_node;
418 struct neigh_node *neigh_node; 395 struct neigh_node *neigh_node;
419 int batman_count = 0; 396 int batman_count = 0;
@@ -447,9 +424,7 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
447 head = &hash->table[i]; 424 head = &hash->table[i];
448 425
449 rcu_read_lock(); 426 rcu_read_lock();
450 hlist_for_each_entry_rcu(bucket, walk, head, hlist) { 427 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
451 orig_node = bucket->data;
452
453 if (!orig_node->router) 428 if (!orig_node->router)
454 continue; 429 continue;
455 430
@@ -468,7 +443,7 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
468 neigh_node->addr, 443 neigh_node->addr,
469 neigh_node->if_incoming->net_dev->name); 444 neigh_node->if_incoming->net_dev->name);
470 445
471 hlist_for_each_entry_rcu(neigh_node, node, 446 hlist_for_each_entry_rcu(neigh_node, node_tmp,
472 &orig_node->neigh_list, list) { 447 &orig_node->neigh_list, list) {
473 seq_printf(seq, " %pM (%3i)", neigh_node->addr, 448 seq_printf(seq, " %pM (%3i)", neigh_node->addr,
474 neigh_node->tq_avg); 449 neigh_node->tq_avg);
@@ -522,9 +497,8 @@ int orig_hash_add_if(struct batman_if *batman_if, int max_if_num)
522{ 497{
523 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface); 498 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
524 struct hashtable_t *hash = bat_priv->orig_hash; 499 struct hashtable_t *hash = bat_priv->orig_hash;
525 struct hlist_node *walk; 500 struct hlist_node *node;
526 struct hlist_head *head; 501 struct hlist_head *head;
527 struct element_t *bucket;
528 struct orig_node *orig_node; 502 struct orig_node *orig_node;
529 int i, ret; 503 int i, ret;
530 504
@@ -536,9 +510,7 @@ int orig_hash_add_if(struct batman_if *batman_if, int max_if_num)
536 head = &hash->table[i]; 510 head = &hash->table[i];
537 511
538 rcu_read_lock(); 512 rcu_read_lock();
539 hlist_for_each_entry_rcu(bucket, walk, head, hlist) { 513 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
540 orig_node = bucket->data;
541
542 spin_lock_bh(&orig_node->ogm_cnt_lock); 514 spin_lock_bh(&orig_node->ogm_cnt_lock);
543 ret = orig_node_add_if(orig_node, max_if_num); 515 ret = orig_node_add_if(orig_node, max_if_num);
544 spin_unlock_bh(&orig_node->ogm_cnt_lock); 516 spin_unlock_bh(&orig_node->ogm_cnt_lock);
@@ -614,9 +586,8 @@ int orig_hash_del_if(struct batman_if *batman_if, int max_if_num)
614{ 586{
615 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface); 587 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
616 struct hashtable_t *hash = bat_priv->orig_hash; 588 struct hashtable_t *hash = bat_priv->orig_hash;
617 struct hlist_node *walk; 589 struct hlist_node *node;
618 struct hlist_head *head; 590 struct hlist_head *head;
619 struct element_t *bucket;
620 struct batman_if *batman_if_tmp; 591 struct batman_if *batman_if_tmp;
621 struct orig_node *orig_node; 592 struct orig_node *orig_node;
622 int i, ret; 593 int i, ret;
@@ -629,9 +600,7 @@ int orig_hash_del_if(struct batman_if *batman_if, int max_if_num)
629 head = &hash->table[i]; 600 head = &hash->table[i];
630 601
631 rcu_read_lock(); 602 rcu_read_lock();
632 hlist_for_each_entry_rcu(bucket, walk, head, hlist) { 603 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
633 orig_node = bucket->data;
634
635 spin_lock_bh(&orig_node->ogm_cnt_lock); 604 spin_lock_bh(&orig_node->ogm_cnt_lock);
636 ret = orig_node_del_if(orig_node, max_if_num, 605 ret = orig_node_del_if(orig_node, max_if_num,
637 batman_if->if_num); 606 batman_if->if_num);