Patchwork [net-next,2/2] netpoll: use the net namespace of current process instead of init_net

login
register
mail settings
Submitter Amerigo Wang
Date Jan. 23, 2013, 9:02 a.m.
Message ID <1358931731-17438-2-git-send-email-amwang@redhat.com>
Download mbox | patch
Permalink /patch/214851/
State Superseded
Delegated to: David Miller
Headers show

Comments

Amerigo Wang - Jan. 23, 2013, 9:02 a.m.
From: Cong Wang <amwang@redhat.com>

This will allow us to setup netconsole in a different namespace
rather than where init_net is.

Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
---
 net/core/netpoll.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Amerigo Wang - Jan. 26, 2013, 10 a.m.
On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
> From: Cong Wang <amwang@redhat.com>
> 
> This will allow us to setup netconsole in a different namespace
> rather than where init_net is.
> 

Hmm, I missed to put the netns in netpoll_cleanup()...

Will send v2.


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric W. Biederman - Jan. 27, 2013, 5:16 a.m.
Cong Wang <amwang@redhat.com> writes:

> On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
>> From: Cong Wang <amwang@redhat.com>
>> 
>> This will allow us to setup netconsole in a different namespace
>> rather than where init_net is.
>> 
>
> Hmm, I missed to put the netns in netpoll_cleanup()...
>
> Will send v2.

Since you are working on it.  I forgot to mention that it doesn't
look you were working with nsproxy properly.  The code just felt
very different from every other nsproxy reference I have seen.

Looking more closely since you are looking at current you don't need
to test to see if nsproxy is NULL. You can just say.

-	if (np->dev_name)
-		ndev = __dev_get_by_name(&init_net, np->dev_name);
+	if (np->dev_name) {
+		net = current->nsproxy->net_ns;
+		ndev = __dev_get_by_name(net, np->dev_name);
+	}

task_nsproxy and get_net are needed when you are accessing another
tasks nsproxy.  Since you are just accessing current the code
can be much simpler.

Which also means that you shouldn't need to get a reference to
the network namespace or put the reference to the network namespace.
Although you do need to handle things like network device hotplug
in case the network device (or equivalently for most purposes) the
network namespace goes away.

Eric

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Amerigo Wang - Jan. 28, 2013, 1:36 a.m.
On Sat, 2013-01-26 at 21:16 -0800, Eric W. Biederman wrote:
> Cong Wang <amwang@redhat.com> writes:
> 
> > On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
> >> From: Cong Wang <amwang@redhat.com>
> >> 
> >> This will allow us to setup netconsole in a different namespace
> >> rather than where init_net is.
> >> 
> >
> > Hmm, I missed to put the netns in netpoll_cleanup()...
> >
> > Will send v2.
> 
> Since you are working on it.  I forgot to mention that it doesn't
> look you were working with nsproxy properly.  The code just felt
> very different from every other nsproxy reference I have seen.
> 
> Looking more closely since you are looking at current you don't need
> to test to see if nsproxy is NULL. You can just say.
> 
> -	if (np->dev_name)
> -		ndev = __dev_get_by_name(&init_net, np->dev_name);
> +	if (np->dev_name) {
> +		net = current->nsproxy->net_ns;
> +		ndev = __dev_get_by_name(net, np->dev_name);
> +	}
> 
> task_nsproxy and get_net are needed when you are accessing another
> tasks nsproxy.  Since you are just accessing current the code
> can be much simpler.

Ok.

> 
> Which also means that you shouldn't need to get a reference to
> the network namespace or put the reference to the network namespace.
> Although you do need to handle things like network device hotplug
> in case the network device (or equivalently for most purposes) the
> network namespace goes away.

I believe we already handle NETDEV_UNREGISTER.

Thanks!

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index a6f39b6..c3b2589 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -1046,11 +1046,16 @@  int netpoll_setup(struct netpoll *np)
 {
 	struct net_device *ndev = NULL;
 	struct in_device *in_dev;
+	struct net *net = &init_net;
+	struct nsproxy *ns = task_nsproxy(current);
 	int err;
 
 	rtnl_lock();
-	if (np->dev_name)
-		ndev = __dev_get_by_name(&init_net, np->dev_name);
+	if (np->dev_name) {
+		if (ns != NULL)
+			net = get_net(ns->net_ns);
+		ndev = __dev_get_by_name(net, np->dev_name);
+	}
 	if (!ndev) {
 		np_err(np, "%s doesn't exist, aborting\n", np->dev_name);
 		err = -ENODEV;
@@ -1159,6 +1164,8 @@  int netpoll_setup(struct netpoll *np)
 put:
 	dev_put(ndev);
 unlock:
+	if (net != &init_net)
+		put_net(net);
 	rtnl_unlock();
 	return err;
 }