netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: wenxu@ucloud.cn, davem@davemloft.net
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net-next v3] ip_tunnel: Add dst_cache support in lwtunnel_state of ip tunnel
Date: Fri, 22 Feb 2019 21:45:09 -0500	[thread overview]
Message-ID: <c19f1092-112a-f2f0-63bc-a592605d32fd@gmail.com> (raw)
In-Reply-To: <1550881979-12589-1-git-send-email-wenxu@ucloud.cn>

On 2/22/19 7:32 PM, wenxu@ucloud.cn wrote:
> diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c
> index 0b17175..f6301af 100644
> --- a/net/core/lwtunnel.c
> +++ b/net/core/lwtunnel.c
> @@ -123,17 +123,18 @@ int lwtunnel_build_state(u16 encap_type,
>  	rcu_read_lock();
>  	ops = rcu_dereference(lwtun_encaps[encap_type]);
>  	if (likely(ops && ops->build_state && try_module_get(ops->owner))) {
> +		rcu_read_unlock();
>  		found = true;
>  		ret = ops->build_state(encap, family, cfg, lws, extack);
>  		if (ret)
>  			module_put(ops->owner);
>  	}
> -	rcu_read_unlock();
>  
>  	/* don't rely on -EOPNOTSUPP to detect match as build_state
>  	 * handlers could return it
>  	 */
>  	if (!found) {
> +		rcu_read_unlock();

I was thinking something much simpler ... like:

rcu_read_lock();

ops = rcu_dereference(lwtun_encaps[encap_type]);
if (likely(ops && ops->build_state && try_module_get(ops->owner))) {
	found = true;

rcu_read_unlock();

if (found) {
	ret = ops->build_state(encap, family, cfg, lws, extack);
	if (ret)
		module_put(ops->owner);
} else {
	NL_SET_ERR_MSG_ATTR(...);
}

>
>  		NL_SET_ERR_MSG_ATTR(extack, encap,
>  				    "LWT encapsulation type not supported");
>  	}
> diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> index 9a0e67b..334e77a 100644
> --- a/net/ipv4/ip_tunnel_core.c
> +++ b/net/ipv4/ip_tunnel_core.c
> @@ -252,6 +252,14 @@ static int ip_tun_build_state(struct nlattr *attr,
>  
>  	tun_info = lwt_tun_info(new_state);
>  
> +#ifdef CONFIG_DST_CACHE
> +	err = dst_cache_init(&tun_info->dst_cache, GFP_KERNEL);
> +	if (err) {
> +		lwtstate_free(new_state);
> +		return err;
> +	}
> +#endif
> +
>  	if (tb[LWTUNNEL_IP_ID])
>  		tun_info->key.tun_id = nla_get_be64(tb[LWTUNNEL_IP_ID]);
>  
> @@ -278,6 +286,15 @@ static int ip_tun_build_state(struct nlattr *attr,
>  	return 0;
>  }
>  
> +#ifdef CONFIG_DST_CACHE
> +static void ip_tun_destroy_state(struct lwtunnel_state *lwtstate)
> +{
> +	struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate);
> +
> +	dst_cache_destroy(&tun_info->dst_cache);
> +}> +#endif
> +
>  static int ip_tun_fill_encap_info(struct sk_buff *skb,
>  				  struct lwtunnel_state *lwtstate)
>  {
> @@ -313,6 +330,9 @@ static int ip_tun_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b)
>  
>  static const struct lwtunnel_encap_ops ip_tun_lwt_ops = {
>  	.build_state = ip_tun_build_state,
> +#ifdef CONFIG_DST_CACHE
> +	.destroy_state = ip_tun_destroy_state,
> +#endif

Define ip_tun_destroy_state when DST_CACHE is not enabled so you don't
need this ifdef as well. e.g., move the ifdef around dst_cache_destroy
and its local arg to mirror the init.

      reply	other threads:[~2019-02-23  2:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23  0:32 [PATCH net-next v3] ip_tunnel: Add dst_cache support in lwtunnel_state of ip tunnel wenxu
2019-02-23  2:45 ` David Ahern [this message]

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=c19f1092-112a-f2f0-63bc-a592605d32fd@gmail.com \
    --to=dsahern@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=wenxu@ucloud.cn \
    /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;
as well as URLs for NNTP newsgroup(s).