aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/translation-table.c
diff options
context:
space:
mode:
authorAntonio Quartulli <ordex@autistici.org>2011-11-07 10:47:01 -0500
committerSven Eckelmann <sven@narfation.org>2011-11-20 07:08:36 -0500
commit697f25314a923f75deef0d3b10991dd103f59d93 (patch)
tree429c812893fea76a9644ce2a04513205a3f8e6e6 /net/batman-adv/translation-table.c
parent48100bac89a6161ca53dd65697fe635f77986686 (diff)
batman-adv: generalise tt_local_reset_flags()
The tt_local_reset_flags() is actually used for one use case only. It is not generalised enough to be used indifferent situations. This patch make it general enough in order to let other code use it whenever a flag set is requested over the whole hash table (passed as parameter). The function is now called tt_set_flags() Signed-off-by: Antonio Quartulli <ordex@autistici.org> Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/translation-table.c')
-rw-r--r--net/batman-adv/translation-table.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 76134bc5e513..f6bbd6423def 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1695,19 +1695,19 @@ void tt_free(struct bat_priv *bat_priv)
1695 kfree(bat_priv->tt_buff); 1695 kfree(bat_priv->tt_buff);
1696} 1696}
1697 1697
1698/* This function will reset the specified flags from all the entries in 1698/* This function will enable or disable the specified flags for all the entries
1699 * the given hash table and will increment num_local_tt for each involved 1699 * in the given hash table and returns the number of modified entries */
1700 * entry */ 1700static uint16_t tt_set_flags(struct hashtable_t *hash, uint16_t flags,
1701static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) 1701 bool enable)
1702{ 1702{
1703 uint32_t i; 1703 uint32_t i;
1704 struct hashtable_t *hash = bat_priv->tt_local_hash; 1704 uint16_t changed_num = 0;
1705 struct hlist_head *head; 1705 struct hlist_head *head;
1706 struct hlist_node *node; 1706 struct hlist_node *node;
1707 struct tt_common_entry *tt_common_entry; 1707 struct tt_common_entry *tt_common_entry;
1708 1708
1709 if (!hash) 1709 if (!hash)
1710 return; 1710 goto out;
1711 1711
1712 for (i = 0; i < hash->size; i++) { 1712 for (i = 0; i < hash->size; i++) {
1713 head = &hash->table[i]; 1713 head = &hash->table[i];
@@ -1715,14 +1715,21 @@ static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags)
1715 rcu_read_lock(); 1715 rcu_read_lock();
1716 hlist_for_each_entry_rcu(tt_common_entry, node, 1716 hlist_for_each_entry_rcu(tt_common_entry, node,
1717 head, hash_entry) { 1717 head, hash_entry) {
1718 if (!(tt_common_entry->flags & flags)) 1718 if (enable) {
1719 continue; 1719 if ((tt_common_entry->flags & flags) == flags)
1720 tt_common_entry->flags &= ~flags; 1720 continue;
1721 atomic_inc(&bat_priv->num_local_tt); 1721 tt_common_entry->flags |= flags;
1722 } else {
1723 if (!(tt_common_entry->flags & flags))
1724 continue;
1725 tt_common_entry->flags &= ~flags;
1726 }
1727 changed_num++;
1722 } 1728 }
1723 rcu_read_unlock(); 1729 rcu_read_unlock();
1724 } 1730 }
1725 1731out:
1732 return changed_num;
1726} 1733}
1727 1734
1728/* Purge out all the tt local entries marked with TT_CLIENT_PENDING */ 1735/* Purge out all the tt local entries marked with TT_CLIENT_PENDING */
@@ -1766,7 +1773,11 @@ static void tt_local_purge_pending_clients(struct bat_priv *bat_priv)
1766 1773
1767void tt_commit_changes(struct bat_priv *bat_priv) 1774void tt_commit_changes(struct bat_priv *bat_priv)
1768{ 1775{
1769 tt_local_reset_flags(bat_priv, TT_CLIENT_NEW); 1776 uint16_t changed_num = tt_set_flags(bat_priv->tt_local_hash,
1777 TT_CLIENT_NEW, false);
1778 /* all the reset entries have now to be effectively counted as local
1779 * entries */
1780 atomic_add(changed_num, &bat_priv->num_local_tt);
1770 tt_local_purge_pending_clients(bat_priv); 1781 tt_local_purge_pending_clients(bat_priv);
1771 1782
1772 /* Increment the TTVN only once per OGM interval */ 1783 /* Increment the TTVN only once per OGM interval */