From patchwork Mon Dec 12 11:31:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1482 Return-Path: Received: from nm9-vm0.bullet.mail.ukl.yahoo.com (nm9-vm0.bullet.mail.ukl.yahoo.com [217.146.183.240]) by open-mesh.org (Postfix) with SMTP id 026F16007F4 for ; Mon, 12 Dec 2011 12:32:26 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.212] by nm9.bullet.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:25 -0000 Received: from [77.238.184.59] by tm5.bullet.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:25 -0000 Received: from [127.0.0.1] by smtp128.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1323689545; bh=0Vpu3Nb3iUrcjt7ycGvu6AqsC2hcdkYcBQxZ4H2P/6A=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=lBzdz+ndlgV4Yzqo+m8uQsQ112Igw1iYe4x3YB9zhXs6/lPvBmh/WM8PCCPoH8pcagM6AQdPpzrTTHtsErth53oBC69ayu4xykSCNSup3fyXH3W6BGzy7yHd7tg5QIAVYsf+loBDzDXLHEJNfJ45+TnwkPKetyu4Unaxp7r/WJk= X-Yahoo-Newman-Id: 888822.35319.bm@smtp128.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: SDfW.BsVM1mrBT.SVoxl6j7cl3DXy25V4bo4k3WJ7p11nbD omIbuewo0RnMXDHUv9Kq5gi3yWjh.WkT3SDog.CbcZ75dibSPaskLEuj1Ris swRvDemwutj.iRPee.Re1JWK7TnSnSuQh9IZd6oJ6owNzrUPhHkvOaTfvym7 NWp_EiJ6X3q1.YFcgFy0ZhTuts13EsuSJShwALDysw1N4N_V5bqR9R5AedEB 3wfGeYRuFftQYX_WkzMkRIYZfydjPumkpE3Q28q6aUdzeTIDgWDmL5sYm_6a 0sqPDKnW2J514srkjvAYZW4jTarzViox6Vf3G1eo9OpbSd8ait58IPS9pZhR b1lj3fud1OglHLNNG.xr_Z2O.bnNpVp_7490ikGf8AwZkz9XthVjKow-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp128.mail.ukl.yahoo.com with SMTP; 12 Dec 2011 11:32:24 +0000 GMT From: Marek Lindner To: davem@davemloft.net Date: Mon, 12 Dec 2011 19:31:47 +0800 Message-Id: <1323689516-24427-4-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323689516-24427-1-git-send-email-lindner_marek@yahoo.de> References: <1323689516-24427-1-git-send-email-lindner_marek@yahoo.de> Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 03/11] batman-adv: generalise tt_local_reset_flags() X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Dec 2011 11:32:27 -0000 From: Antonio Quartulli 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 Signed-off-by: Sven Eckelmann Signed-off-by: Marek Lindner --- net/batman-adv/translation-table.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 76134bc..f6bbd64 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) kfree(bat_priv->tt_buff); } -/* This function will reset the specified flags from all the entries in - * the given hash table and will increment num_local_tt for each involved - * entry */ -static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) +/* This function will enable or disable the specified flags for all the entries + * in the given hash table and returns the number of modified entries */ +static uint16_t tt_set_flags(struct hashtable_t *hash, uint16_t flags, + bool enable) { uint32_t i; - struct hashtable_t *hash = bat_priv->tt_local_hash; + uint16_t changed_num = 0; struct hlist_head *head; struct hlist_node *node; struct tt_common_entry *tt_common_entry; if (!hash) - return; + goto out; for (i = 0; i < hash->size; i++) { head = &hash->table[i]; @@ -1715,14 +1715,21 @@ static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) rcu_read_lock(); hlist_for_each_entry_rcu(tt_common_entry, node, head, hash_entry) { - if (!(tt_common_entry->flags & flags)) - continue; - tt_common_entry->flags &= ~flags; - atomic_inc(&bat_priv->num_local_tt); + if (enable) { + if ((tt_common_entry->flags & flags) == flags) + continue; + tt_common_entry->flags |= flags; + } else { + if (!(tt_common_entry->flags & flags)) + continue; + tt_common_entry->flags &= ~flags; + } + changed_num++; } rcu_read_unlock(); } - +out: + return changed_num; } /* 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) void tt_commit_changes(struct bat_priv *bat_priv) { - tt_local_reset_flags(bat_priv, TT_CLIENT_NEW); + uint16_t changed_num = tt_set_flags(bat_priv->tt_local_hash, + TT_CLIENT_NEW, false); + /* all the reset entries have now to be effectively counted as local + * entries */ + atomic_add(changed_num, &bat_priv->num_local_tt); tt_local_purge_pending_clients(bat_priv); /* Increment the TTVN only once per OGM interval */