DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace
@ 2014-11-21  3:10 Takayuki Usui
  2014-11-26 21:26 ` Thomas Monjalon
  2014-11-27  9:06 ` Nicolas Dichtel
  0 siblings, 2 replies; 10+ messages in thread
From: Takayuki Usui @ 2014-11-21  3:10 UTC (permalink / raw)
  To: dev

With this patch, KNI interface (e.g. vEth0) is created in the
network namespace where the DPDK application is running.
Otherwise, all interfaces are created in the default namespace
in the host.

Signed-off-by: Takayuki Usui <takayuki@midokura.com>
---
 lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index ba77776..f4a9965 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 		return -EBUSY;
 	}
 
+	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
+
 	kni = netdev_priv(net_dev);
 
 	kni->net_dev = net_dev;
-- 
2.1.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace
  2014-11-21  3:10 [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace Takayuki Usui
@ 2014-11-26 21:26 ` Thomas Monjalon
  2014-12-01  5:45   ` Hemant
  2014-11-27  9:06 ` Nicolas Dichtel
  1 sibling, 1 reply; 10+ messages in thread
From: Thomas Monjalon @ 2014-11-26 21:26 UTC (permalink / raw)
  To: dev

Anyone to review this KNI patch?

2014-11-21 12:10, Takayuki Usui:
> With this patch, KNI interface (e.g. vEth0) is created in the
> network namespace where the DPDK application is running.
> Otherwise, all interfaces are created in the default namespace
> in the host.
> 
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>  lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..f4a9965 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>  		return -EBUSY;
>  	}
>  
> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
> +
>  	kni = netdev_priv(net_dev);
>  
>  	kni->net_dev = net_dev;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace
  2014-11-21  3:10 [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace Takayuki Usui
  2014-11-26 21:26 ` Thomas Monjalon
@ 2014-11-27  9:06 ` Nicolas Dichtel
  2014-12-02  2:19   ` [dpdk-dev] [PATCH v2] " Takayuki Usui
  1 sibling, 1 reply; 10+ messages in thread
From: Nicolas Dichtel @ 2014-11-27  9:06 UTC (permalink / raw)
  To: Takayuki Usui, dev

Le 21/11/2014 04:10, Takayuki Usui a écrit :
> With this patch, KNI interface (e.g. vEth0) is created in the
> network namespace where the DPDK application is running.
> Otherwise, all interfaces are created in the default namespace
> in the host.
>
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>   lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..f4a9965 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   		return -EBUSY;
>   	}
>
> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
You should test the returned value and release the refcnt.
net = get_net_ns_by_pid(current->pid)
if (IS_ERR(net))
...
put_net(net);

> +
>   	kni = netdev_priv(net_dev);
>
>   	kni->net_dev = net_dev;
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace
  2014-11-26 21:26 ` Thomas Monjalon
@ 2014-12-01  5:45   ` Hemant
  2014-12-01 10:42     ` Nicolas Dichtel
  0 siblings, 1 reply; 10+ messages in thread
From: Hemant @ 2014-12-01  5:45 UTC (permalink / raw)
  To: dev

> 2014-11-21 12:10, Takayuki Usui:
> > With this patch, KNI interface (e.g. vEth0) is created in the network
> > namespace where the DPDK application is running.
> > Otherwise, all interfaces are created in the default namespace in the
> > host.
> >
> > Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> > ---
> >  lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c
> > b/lib/librte_eal/linuxapp/kni/kni_misc.c
> > index ba77776..f4a9965 100644
> > --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> > +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> > @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned
> long ioctl_param)
> >  		return -EBUSY;
> >  	}
> >
> > +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
> > +

Another way to get it done is by the following. It will be init_net for the root container.

#ifdef CONFIG_NET_NS
	net_dev->nd_net = current->nsproxy->net_ns; 
#endif
> >  	kni = netdev_priv(net_dev);
> >
> >  	kni->net_dev = net_dev;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace
  2014-12-01  5:45   ` Hemant
@ 2014-12-01 10:42     ` Nicolas Dichtel
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Dichtel @ 2014-12-01 10:42 UTC (permalink / raw)
  To: Hemant, dev

Le 01/12/2014 06:45, Hemant@freescale.com a écrit :
>> 2014-11-21 12:10, Takayuki Usui:
>>> With this patch, KNI interface (e.g. vEth0) is created in the network
>>> namespace where the DPDK application is running.
>>> Otherwise, all interfaces are created in the default namespace in the
>>> host.
>>>
>>> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
>>> ---
>>>   lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>>>   1 file changed, 2 insertions(+)
>>>
>>> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> b/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> index ba77776..f4a9965 100644
>>> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned
>> long ioctl_param)
>>>   		return -EBUSY;
>>>   	}
>>>
>>> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
>>> +
>
> Another way to get it done is by the following. It will be init_net for the root container.
>
> #ifdef CONFIG_NET_NS
> 	net_dev->nd_net = current->nsproxy->net_ns;
> #endif
No. It's always better to use existing helpers, it hides this kind of ifdef and
more importantly, it do the right things (call release_net()/hold_net())!
Reimplemented helpers is error prone.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v2] kni: create KNI interface in current network namespace
  2014-11-27  9:06 ` Nicolas Dichtel
@ 2014-12-02  2:19   ` Takayuki Usui
  2014-12-02  9:04     ` Nicolas Dichtel
  0 siblings, 1 reply; 10+ messages in thread
From: Takayuki Usui @ 2014-12-02  2:19 UTC (permalink / raw)
  To: dev

With this patch, KNI interface (e.g. vEth0) is created in the
network namespace where the DPDK application is running.
Otherwise, all interfaces are created in the default namespace
in the host.

put_net() is required, since get_net_ns_by_pid() increments
the reference counter of the network namespace with get_net().

Signed-off-by: Takayuki Usui <takayuki@midokura.com>
---
 lib/librte_eal/linuxapp/kni/kni_misc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index ba77776..33c7a48 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -311,6 +311,7 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 	struct net_device *net_dev = NULL;
 	struct net_device *lad_dev = NULL;
 	struct kni_dev *kni, *dev, *n;
+	struct net *net;
 
 	printk(KERN_INFO "KNI: Creating kni...\n");
 	/* Check the buffer size, to avoid warning */
@@ -354,6 +355,12 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 		return -EBUSY;
 	}
 
+	net = get_net_ns_by_pid(current->pid);
+	if (IS_ERR(net))
+		return PTR_ERR(net);
+	dev_net_set(net_dev, net);
+	put_net(net);
+
 	kni = netdev_priv(net_dev);
 
 	kni->net_dev = net_dev;
-- 
2.1.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH v2] kni: create KNI interface in current network namespace
  2014-12-02  2:19   ` [dpdk-dev] [PATCH v2] " Takayuki Usui
@ 2014-12-02  9:04     ` Nicolas Dichtel
  2014-12-03  1:37       ` [dpdk-dev] [PATCH v3] " Takayuki Usui
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Dichtel @ 2014-12-02  9:04 UTC (permalink / raw)
  To: Takayuki Usui, dev

Le 02/12/2014 03:19, Takayuki Usui a écrit :
> With this patch, KNI interface (e.g. vEth0) is created in the
> network namespace where the DPDK application is running.
> Otherwise, all interfaces are created in the default namespace
> in the host.
>
> put_net() is required, since get_net_ns_by_pid() increments
> the reference counter of the network namespace with get_net().
>
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>   lib/librte_eal/linuxapp/kni/kni_misc.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..33c7a48 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -311,6 +311,7 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   	struct net_device *net_dev = NULL;
>   	struct net_device *lad_dev = NULL;
>   	struct kni_dev *kni, *dev, *n;
> +	struct net *net;
>
>   	printk(KERN_INFO "KNI: Creating kni...\n");
>   	/* Check the buffer size, to avoid warning */
> @@ -354,6 +355,12 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   		return -EBUSY;
>   	}
>
> +	net = get_net_ns_by_pid(current->pid);
> +	if (IS_ERR(net))
In case of error, you should call free_netdev(net_dev) to avoid a memory leak.

> +		return PTR_ERR(net);
> +	dev_net_set(net_dev, net);
> +	put_net(net);
> +
>   	kni = netdev_priv(net_dev);
>
>   	kni->net_dev = net_dev;
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v3] kni: create KNI interface in current network namespace
  2014-12-02  9:04     ` Nicolas Dichtel
@ 2014-12-03  1:37       ` Takayuki Usui
  2014-12-03 10:51         ` Nicolas Dichtel
  0 siblings, 1 reply; 10+ messages in thread
From: Takayuki Usui @ 2014-12-03  1:37 UTC (permalink / raw)
  To: dev

With this patch, KNI interface (e.g. vEth0) is created in the
network namespace where the DPDK application is running.
Otherwise, all interfaces are created in the default namespace
in the host.

put_net() is required, since get_net_ns_by_pid() increments
the reference counter of the network namespace with get_net().

Signed-off-by: Takayuki Usui <takayuki@midokura.com>
---
 lib/librte_eal/linuxapp/kni/kni_misc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index ba77776..868b325 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -311,6 +311,7 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 	struct net_device *net_dev = NULL;
 	struct net_device *lad_dev = NULL;
 	struct kni_dev *kni, *dev, *n;
+	struct net *net;
 
 	printk(KERN_INFO "KNI: Creating kni...\n");
 	/* Check the buffer size, to avoid warning */
@@ -354,6 +355,14 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 		return -EBUSY;
 	}
 
+	net = get_net_ns_by_pid(current->pid);
+	if (IS_ERR(net)) {
+		free_netdev(net_dev);
+		return PTR_ERR(net);
+	}
+	dev_net_set(net_dev, net);
+	put_net(net);
+
 	kni = netdev_priv(net_dev);
 
 	kni->net_dev = net_dev;
-- 
2.1.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH v3] kni: create KNI interface in current network namespace
  2014-12-03  1:37       ` [dpdk-dev] [PATCH v3] " Takayuki Usui
@ 2014-12-03 10:51         ` Nicolas Dichtel
  2014-12-03 14:01           ` Thomas Monjalon
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Dichtel @ 2014-12-03 10:51 UTC (permalink / raw)
  To: Takayuki Usui, dev

Le 03/12/2014 02:37, Takayuki Usui a écrit :
> With this patch, KNI interface (e.g. vEth0) is created in the
> network namespace where the DPDK application is running.
> Otherwise, all interfaces are created in the default namespace
> in the host.
>
> put_net() is required, since get_net_ns_by_pid() increments
> the reference counter of the network namespace with get_net().
>
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH v3] kni: create KNI interface in current network namespace
  2014-12-03 10:51         ` Nicolas Dichtel
@ 2014-12-03 14:01           ` Thomas Monjalon
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2014-12-03 14:01 UTC (permalink / raw)
  To: Takayuki Usui; +Cc: dev

> > With this patch, KNI interface (e.g. vEth0) is created in the
> > network namespace where the DPDK application is running.
> > Otherwise, all interfaces are created in the default namespace
> > in the host.
> >
> > put_net() is required, since get_net_ns_by_pid() increments
> > the reference counter of the network namespace with get_net().
> >
> > Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Applied

Thanks
-- 
Thomas

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-12-03 14:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-21  3:10 [dpdk-dev] [PATCH] kni: create KNI interface in current network namespace Takayuki Usui
2014-11-26 21:26 ` Thomas Monjalon
2014-12-01  5:45   ` Hemant
2014-12-01 10:42     ` Nicolas Dichtel
2014-11-27  9:06 ` Nicolas Dichtel
2014-12-02  2:19   ` [dpdk-dev] [PATCH v2] " Takayuki Usui
2014-12-02  9:04     ` Nicolas Dichtel
2014-12-03  1:37       ` [dpdk-dev] [PATCH v3] " Takayuki Usui
2014-12-03 10:51         ` Nicolas Dichtel
2014-12-03 14:01           ` Thomas Monjalon

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).