From: Vivien Chappelier <vivien.chappelier-L+G57L1VLRbR7s880joybQ@public.gmane.org>
To: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 1/6] netns: add in ida ID to identify the network namespace
Date: Thu, 30 Oct 2008 14:06:29 +0100 [thread overview]
Message-ID: <20081030130629.GA17665@thomson.net> (raw)
Patch initially submitted by Benjamin Thery.
This patch adds in 'id' member to struct net. This member contains an
IDA ID. The id is allocated at netns creation.
This 'id' will be used to reference network namespaces without the need for a pid.
---
include/net/net_namespace.h | 2 ++
net/core/net_namespace.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 708009b..8bde629 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -75,6 +75,8 @@ struct net {
#endif
#endif
struct net_generic *gen;
+
+ int id;
};
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index f1d07b5..894b35e 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -26,6 +26,16 @@ EXPORT_SYMBOL(init_net);
#define INITIAL_NET_GEN_PTRS 13 /* +1 for len +2 for rcu_head */
/*
+ * IDs allocated from this ida are used as a suffix in sysfs to tag
+ * devices belonging to each netns (other than init_net).
+ * Only 4 characters are left to store a separator plus this tag in sysfs
+ * (BUS_ID_SIZE-IFNAMSIZ)
+ * Thus, this limits us to 4095 ("FFF") simultaneous network namespaces.
+ */
+static DEFINE_IDA(net_id_ida);
+#define NET_ID_MAX 0xFFF
+
+/*
* setup_net runs the initializers for the network namespace object.
*/
static __net_init int setup_net(struct net *net)
@@ -40,7 +50,20 @@ static __net_init int setup_net(struct net *net)
atomic_set(&net->use_count, 0);
#endif
+ /* Get an ID */
+again:
+ error = ida_get_new(&net_id_ida, &net->id);
+ if (error) {
+ if (error == -EAGAIN) {
+ ida_pre_get(&net_id_ida, GFP_KERNEL);
+ goto again;
+ }
+ goto out;
+ }
error = -ENOMEM;
+ if (net->id > NET_ID_MAX)
+ goto out;
+
ng = kzalloc(sizeof(struct net_generic) +
INITIAL_NET_GEN_PTRS * sizeof(void *), GFP_KERNEL);
if (ng == NULL)
@@ -97,6 +120,7 @@ static void net_free(struct net *net)
}
#endif
kfree(net->gen);
+ ida_remove(&net_id_ida, net->id);
kmem_cache_free(net_cachep, net);
}
--
1.5.4.4
reply other threads:[~2008-10-30 13:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20081030130629.GA17665@thomson.net \
--to=vivien.chappelier-l+g57l1vlrbr7s880joybq@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
/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