[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 12 Dec 2012 18:24:37 +0100
From: Nicolas Dichtel <nicolas.dichtel@...nd.com>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, ebiederm@...ssion.com, aatteka@...ira.com,
Nicolas Dichtel <nicolas.dichtel@...nd.com>
Subject: [RFC PATCH net-next 1/5] netns: allocate an unique id to identify a netns
This patch simply adds a field nsindex, which will contain a unique index.
The goal is to prepare the monitoring of netns activities with rtnelink and to
ease netns management by userland apps.
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@...nd.com>
---
include/net/net_namespace.h | 1 +
net/core/net_namespace.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index c5a43f5..5db7a1b 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -55,6 +55,7 @@ struct net {
struct list_head exit_list; /* Use only net_mutex */
struct user_namespace *user_ns; /* Owning user namespace */
+ int nsindex; /* index to identify this ns */
struct proc_dir_entry *proc_net;
struct proc_dir_entry *proc_net_stat;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 6456439..f5267e4 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -27,6 +27,7 @@ static DEFINE_MUTEX(net_mutex);
LIST_HEAD(net_namespace_list);
EXPORT_SYMBOL_GPL(net_namespace_list);
+static DEFINE_IDA(net_namespace_ids);
struct net init_net = {
.dev_base_head = LIST_HEAD_INIT(init_net.dev_base_head),
@@ -157,6 +158,15 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
atomic_set(&net->passive, 1);
net->dev_base_seq = 1;
net->user_ns = user_ns;
+again:
+ error = ida_get_new_above(&net_namespace_ids, 1, &net->nsindex);
+ if (error < 0) {
+ if (error == -EAGAIN) {
+ ida_pre_get(&net_namespace_ids, GFP_KERNEL);
+ goto again;
+ }
+ return error;
+ }
#ifdef NETNS_REFCNT_DEBUG
atomic_set(&net->use_count, 0);
@@ -171,6 +181,7 @@ out:
return error;
out_undo:
+ ida_remove(&net_namespace_ids, net->nsindex);
/* Walk through the list backwards calling the exit functions
* for the pernet modules whose init functions did not fail.
*/
@@ -297,6 +308,11 @@ static void cleanup_net(struct work_struct *work)
*/
synchronize_rcu();
+ list_for_each_entry(net, &net_exit_list, exit_list) {
+ /* Free the index */
+ ida_remove(&net_namespace_ids, net->nsindex);
+ }
+
/* Run all of the network namespace exit methods */
list_for_each_entry_reverse(ops, &pernet_list, list)
ops_exit_list(ops, &net_exit_list);
--
1.8.0.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists