Thread (18 messages) 18 messages, 5 authors, 2014-07-15

Re: [RFC PATCH net-next 1/5] netns: allocate netns ids

From: Sergei Shtylyov <hidden>
Date: 2014-07-02 13:33:08

Hello.

On 07/02/2014 03:59 PM, Nicolas Dichtel wrote:
With this patch, netns allocates ids for all netns. Each netns has its own list
of ids, it means that the id is valid only in the current netns.
For homogeneity, an id is also allocated for the netns owner itself.
Signed-off-by: Nicolas Dichtel <redacted>
[...]
quoted hunk ↗ jump to hunk
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 85b62691f4f2..2976864cef13 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -144,6 +144,30 @@ static void ops_free_list(const struct pernet_operations *ops,
  	}
  }

+static int net_eq_idr(int id, void *net, void *peer)
+{
+	return net_eq(net, peer) ? id : 0;
+}
+
+int net2id(struct net *net, struct net *peer)
+{
+	ASSERT_RTNL();
+	return idr_for_each(&(net)->netns_ids, net_eq_idr, (peer)) ? : -ENOENT;
    I don't think the inner parens are needed, this is not a macro body...
+}
+
+struct net *get_net_from_netnsid(struct net *net, int id)
+{
+	struct net *peer;
+
+	rcu_read_lock();
+	peer = idr_find(&(net)->netns_ids, id);
    Same here.
+	if (peer)
+		get_net(peer);
+	rcu_read_unlock();
+
+	return peer;
+}
+
  /*
   * setup_net runs the initializers for the network namespace object.
   */
[...]

WBR, Sergei
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help