Commit bd3524c14bd02f94a4fa33e700883e01182f5ed5

Authored by Simon Wunderlich
Committed by Antonio Quartulli
1 parent 741aa06bfb

batman-adv: remove obsolete deleted attribute for gateway node

With rcu, the gateway node deleted attribute is not needed anymore. In
fact, it may delay the free of the gateway node and its referenced
structures. Therefore remove it altogether and simplify purging as well.

Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>

Showing 5 changed files with 14 additions and 41 deletions Side-by-side Diff

net/batman-adv/gateway_client.c
... ... @@ -161,9 +161,6 @@
161 161  
162 162 rcu_read_lock();
163 163 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
164   - if (gw_node->deleted)
165   - continue;
166   -
167 164 orig_node = gw_node->orig_node;
168 165 router = batadv_orig_router_get(orig_node, BATADV_IF_DEFAULT);
169 166 if (!router)
... ... @@ -473,9 +470,6 @@
473 470 if (gw_node_tmp->orig_node != orig_node)
474 471 continue;
475 472  
476   - if (gw_node_tmp->deleted)
477   - continue;
478   -
479 473 if (!atomic_inc_not_zero(&gw_node_tmp->refcount))
480 474 continue;
481 475  
482 476  
... ... @@ -525,9 +519,7 @@
525 519 gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
526 520 gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
527 521  
528   - gw_node->deleted = 0;
529 522 if (ntohl(gateway->bandwidth_down) == 0) {
530   - gw_node->deleted = jiffies;
531 523 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
532 524 "Gateway %pM removed from gateway list\n",
533 525 orig_node->orig);
534 526  
535 527  
... ... @@ -535,14 +527,21 @@
535 527 /* Note: We don't need a NULL check here, since curr_gw never
536 528 * gets dereferenced.
537 529 */
  530 + spin_lock_bh(&bat_priv->gw.list_lock);
  531 + hlist_del_init_rcu(&gw_node->list);
  532 + spin_unlock_bh(&bat_priv->gw.list_lock);
  533 +
  534 + batadv_gw_node_free_ref(gw_node);
  535 +
538 536 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
539 537 if (gw_node == curr_gw)
540 538 batadv_gw_reselect(bat_priv);
  539 +
  540 + if (curr_gw)
  541 + batadv_gw_node_free_ref(curr_gw);
541 542 }
542 543  
543 544 out:
544   - if (curr_gw)
545   - batadv_gw_node_free_ref(curr_gw);
546 545 if (gw_node)
547 546 batadv_gw_node_free_ref(gw_node);
548 547 }
549 548  
550 549  
551 550  
552 551  
553 552  
554 553  
555 554  
556 555  
... ... @@ -558,39 +557,19 @@
558 557 batadv_gw_node_update(bat_priv, orig_node, &gateway);
559 558 }
560 559  
561   -void batadv_gw_node_purge(struct batadv_priv *bat_priv)
  560 +void batadv_gw_node_free(struct batadv_priv *bat_priv)
562 561 {
563   - struct batadv_gw_node *gw_node, *curr_gw;
  562 + struct batadv_gw_node *gw_node;
564 563 struct hlist_node *node_tmp;
565   - unsigned long timeout = msecs_to_jiffies(2 * BATADV_PURGE_TIMEOUT);
566   - int do_reselect = 0;
567 564  
568   - curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
569   -
570 565 spin_lock_bh(&bat_priv->gw.list_lock);
571   -
572 566 hlist_for_each_entry_safe(gw_node, node_tmp,
573 567 &bat_priv->gw.list, list) {
574   - if (((!gw_node->deleted) ||
575   - (time_before(jiffies, gw_node->deleted + timeout))) &&
576   - atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE)
577   - continue;
578 568  
579   - if (curr_gw == gw_node)
580   - do_reselect = 1;
581   -
582   - hlist_del_rcu(&gw_node->list);
  569 + hlist_del_init_rcu(&gw_node->list);
583 570 batadv_gw_node_free_ref(gw_node);
584 571 }
585   -
586 572 spin_unlock_bh(&bat_priv->gw.list_lock);
587   -
588   - /* gw_reselect() needs to acquire the gw_list_lock */
589   - if (do_reselect)
590   - batadv_gw_reselect(bat_priv);
591   -
592   - if (curr_gw)
593   - batadv_gw_node_free_ref(curr_gw);
594 573 }
595 574  
596 575 /* fails if orig_node has no router */
... ... @@ -654,9 +633,6 @@
654 633  
655 634 rcu_read_lock();
656 635 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
657   - if (gw_node->deleted)
658   - continue;
659   -
660 636 /* fails if orig_node has no router */
661 637 if (batadv_write_buffer_text(bat_priv, seq, gw_node) < 0)
662 638 continue;
net/batman-adv/gateway_client.h
... ... @@ -38,7 +38,7 @@
38 38 struct batadv_tvlv_gateway_data *gateway);
39 39 void batadv_gw_node_delete(struct batadv_priv *bat_priv,
40 40 struct batadv_orig_node *orig_node);
41   -void batadv_gw_node_purge(struct batadv_priv *bat_priv);
  41 +void batadv_gw_node_free(struct batadv_priv *bat_priv);
42 42 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset);
43 43 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);
44 44 enum batadv_dhcp_recipient
net/batman-adv/main.c
... ... @@ -199,7 +199,7 @@
199 199  
200 200 batadv_purge_outstanding_packets(bat_priv, NULL);
201 201  
202   - batadv_gw_node_purge(bat_priv);
  202 + batadv_gw_node_free(bat_priv);
203 203 batadv_nc_mesh_free(bat_priv);
204 204 batadv_dat_free(bat_priv);
205 205 batadv_bla_free(bat_priv);
net/batman-adv/originator.c
... ... @@ -1028,7 +1028,6 @@
1028 1028 spin_unlock_bh(list_lock);
1029 1029 }
1030 1030  
1031   - batadv_gw_node_purge(bat_priv);
1032 1031 batadv_gw_election(bat_priv);
1033 1032 }
1034 1033  
net/batman-adv/types.h
... ... @@ -328,7 +328,6 @@
328 328 * @orig_node: pointer to corresponding orig node
329 329 * @bandwidth_down: advertised uplink download bandwidth
330 330 * @bandwidth_up: advertised uplink upload bandwidth
331   - * @deleted: this struct is scheduled for deletion
332 331 * @refcount: number of contexts the object is used
333 332 * @rcu: struct used for freeing in an RCU-safe manner
334 333 */
... ... @@ -337,7 +336,6 @@
337 336 struct batadv_orig_node *orig_node;
338 337 u32 bandwidth_down;
339 338 u32 bandwidth_up;
340   - unsigned long deleted;
341 339 atomic_t refcount;
342 340 struct rcu_head rcu;
343 341 };