From: Patrick McHardy <kaber@trash.net>
To: Thomas Graf <tgraf@suug.ch>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au,
paulmck@linux.vnet.ibm.com, edumazet@google.com,
john.r.fastabend@intel.com, josh@joshtriplett.org,
netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 1/9] rhashtable: Do hashing inside of rhashtable_lookup_compare()
Date: Fri, 16 Jan 2015 15:37:40 +0000 [thread overview]
Message-ID: <20150116153740.GG30132@acer.localdomain> (raw)
In-Reply-To: <d579f486c3d4a88744dffc23a794601b025b41f4.1420230585.git.tgraf@suug.ch>
On 02.01, Thomas Graf wrote:
> Hash the key inside of rhashtable_lookup_compare() like
> rhashtable_lookup() does. This allows to simplify the hashing
> functions and keep them private.
One more question:
> diff --git a/net/netfilter/nft_hash.c b/net/netfilter/nft_hash.c
> index 1e316ce..614ee09 100644
> --- a/net/netfilter/nft_hash.c
> +++ b/net/netfilter/nft_hash.c
> @@ -94,28 +94,40 @@ static void nft_hash_remove(const struct nft_set *set,
> kfree(he);
> }
>
> +struct nft_compare_arg {
> + const struct nft_set *set;
> + struct nft_set_elem *elem;
> +};
> +
> +static bool nft_hash_compare(void *ptr, void *arg)
> +{
> + struct nft_hash_elem *he = ptr;
> + struct nft_compare_arg *x = arg;
> +
> + if (!nft_data_cmp(&he->key, &x->elem->key, x->set->klen)) {
> + x->elem->cookie = &he->node;
> + x->elem->flags = 0;
> + if (x->set->flags & NFT_SET_MAP)
> + nft_data_copy(&x->elem->data, he->data);
Is there any reason why we need to perform the assignments in the
compare function? The reason why I'm asking is because to add
timeout support, I need another compare function for nft_hash_lookup()
and I'd prefer to use a single one for both cases.
> +
> + return true;
> + }
> +
> + return false;
> +}
> +
> static int nft_hash_get(const struct nft_set *set, struct nft_set_elem *elem)
> {
> const struct rhashtable *priv = nft_set_priv(set);
> - const struct bucket_table *tbl = rht_dereference_rcu(priv->tbl, priv);
> - struct rhash_head __rcu * const *pprev;
> - struct nft_hash_elem *he;
> - u32 h;
> -
> - h = rhashtable_hashfn(priv, &elem->key, set->klen);
> - pprev = &tbl->buckets[h];
> - rht_for_each_entry_rcu(he, tbl->buckets[h], node) {
> - if (nft_data_cmp(&he->key, &elem->key, set->klen)) {
> - pprev = &he->node.next;
> - continue;
> - }
> + struct nft_compare_arg arg = {
> + .set = set,
> + .elem = elem,
> + };
>
> - elem->cookie = (void *)pprev;
> - elem->flags = 0;
> - if (set->flags & NFT_SET_MAP)
> - nft_data_copy(&elem->data, he->data);
> + if (rhashtable_lookup_compare(priv, &elem->key,
> + &nft_hash_compare, &arg))
> return 0;
> - }
> +
> return -ENOENT;
> }
>
next prev parent reply other threads:[~2015-01-16 15:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-02 22:00 [PATCH 0/9 net-next v2] rhashtable: Per bucket locks & deferred table resizing Thomas Graf
2015-01-02 22:00 ` [PATCH 1/9] rhashtable: Do hashing inside of rhashtable_lookup_compare() Thomas Graf
2015-01-16 15:37 ` Patrick McHardy [this message]
2015-01-16 16:00 ` Thomas Graf
2015-01-02 22:00 ` [PATCH 2/9] rhashtable: Use rht_obj() instead of manual offset calculation Thomas Graf
2015-01-02 22:00 ` [PATCH 3/9] rhashtable: Convert bucket iterators to take table and index Thomas Graf
2015-01-02 22:00 ` [PATCH 4/9] rhashtable: Factor out bucket_tail() function Thomas Graf
2015-01-02 22:00 ` [PATCH 5/9] nft_hash: Remove rhashtable_remove_pprev() Thomas Graf
2015-01-02 22:00 ` [PATCH 6/9] spinlock: Add spin_lock_bh_nested() Thomas Graf
2015-01-02 22:00 ` [PATCH 7/9] rhashtable: Per bucket locks & deferred expansion/shrinking Thomas Graf
2015-01-02 22:00 ` [PATCH 8/9] rhashtable: Supports for nulls marker Thomas Graf
2015-01-02 22:00 ` [PATCH 9/9] netlink: Lockless lookup with RCU grace period in socket release Thomas Graf
2015-01-03 19:02 ` [RFC] netlink: get rid of nl_table_lock Stephen Hemminger
2015-01-06 22:19 ` David Miller
2015-01-06 23:00 ` Thomas Graf
2015-01-03 19:44 ` [PATCH 0/9 net-next v2] rhashtable: Per bucket locks & deferred table resizing David Miller
-- strict thread matches above, loose matches on Subject: below --
2014-12-15 12:51 [PATCH 0/9] " Thomas Graf
2014-12-15 12:51 ` [PATCH 1/9] rhashtable: Do hashing inside of rhashtable_lookup_compare() Thomas Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150116153740.GG30132@acer.localdomain \
--to=kaber@trash.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=john.r.fastabend@intel.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox