LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Benjamin Thery <benjamin.thery@bull.net>
To: netdev <netdev@vger.kernel.org>, Dave Miller <davem@davemloft.net>
Cc: Eric Biederman <ebiederm@xmission.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Al Viro <viro@ftp.linux.org.uk>, Serge Hallyn <serue@us.ibm.com>,
	Daniel Lezcano <dlezcano@fr.ibm.com>,
	linux-kernel@vger.kernel.org, Tejun Heo <htejun@gmail.com>,
	Denis Lunev <den@openvz.org>,
	Linux Containers <containers@lists.linux-foundation.org>,
	Benjamin Thery <benjamin.thery@bull.net>
Subject: [PATCH 1/4] netns: add in ida ID to identify the network namespace
Date: Wed, 22 Oct 2008 17:21:54 +0200	[thread overview]
Message-ID: <20081022152144.562569159@theryb.frec.bull.fr> (raw)
In-Reply-To: <20081022152144.351965414@theryb.frec.bull.fr>

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 'tag' net devices belonging to network namespace
in sysfs (in order to allow registration of net devices with the same name 
in different network namespace: see last patch for the details).

The advantage of IDA IDs over using the netns pointer is the id values
are small starting at 0, thus they requires less bytes to be displayed
(we are limited to 3 characters: again see last patch for the details). 
And they stay small as they are recycled when IDs are freed (unless you
have thousands of netns running on your host).

Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
Acked-by: Serge Hallyn <serue@us.ibm.com>
---
 include/net/net_namespace.h |    2 ++
 net/core/net_namespace.c    |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

Index: net-next-2.6/include/net/net_namespace.h
===================================================================
--- net-next-2.6.orig/include/net/net_namespace.h
+++ net-next-2.6/include/net/net_namespace.h
@@ -75,6 +75,8 @@ struct net {
 #endif
 #endif
 	struct net_generic	*gen;
+
+	int			id;
 };
 
 
Index: net-next-2.6/net/core/net_namespace.c
===================================================================
--- net-next-2.6.orig/net/core/net_namespace.c
+++ net-next-2.6/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 n
 	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
 
+	ida_remove(&net_id_ida, net->id);
 	kmem_cache_free(net_cachep, net);
 }
 

-- 

  reply	other threads:[~2008-10-22 15:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-22 15:21 [PATCH 0/4][RFC] netns: sysfs: add a netns suffix to net device sysfs entries Benjamin Thery
2008-10-22 15:21 ` Benjamin Thery [this message]
2008-10-22 15:22 ` [PATCH 2/4] netns: Export nets id to /proc/net/netns Benjamin Thery
2008-10-22 15:22 ` [PATCH 3/4] net: cleanup some vars names to be more consistant with the network code Benjamin Thery
2008-10-22 15:22 ` [PATCH 4/4] netns: sysfs: add netns suffix to net devices sysfs entries Benjamin Thery
2008-10-22 19:59 ` [PATCH 0/4][RFC] netns: sysfs: add a netns suffix to net device " Eric W. Biederman
2008-10-22 20:30   ` Serge E. Hallyn
2008-10-22 21:01     ` Eric W. Biederman
2008-10-22 21:55       ` Stephen Hemminger
2008-10-22 22:54         ` Eric W. Biederman
2008-10-23  4:14           ` Kyle Moffett
2008-10-23 11:56   ` Benjamin Thery
2008-10-23 15:46     ` Eric W. Biederman
2008-10-22 20:16 ` Greg KH
2008-10-22 21:08   ` Eric W. Biederman
2008-10-22 21:24     ` Greg KH
2008-10-22 20:32 ` [PATCH] netns: Coexist with the sysfs limitations Eric W. Biederman
2008-10-22 20:40   ` Daniel Lezcano
2008-10-22 21:21   ` Serge E. Hallyn
2008-10-23  8:04     ` Benjamin Thery
2008-10-23 15:40       ` Eric W. Biederman
2008-10-23 15:56       ` [PATCH] netns: Coexist with the sysfs limitations v2 Eric W. Biederman
2008-10-27 19:41         ` David Miller
2008-10-27 20:19           ` Eric W. Biederman
2008-10-28  0:50             ` David Miller

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=20081022152144.562569159@theryb.frec.bull.fr \
    --to=benjamin.thery@bull.net \
    --cc=containers@lists.linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=den@openvz.org \
    --cc=dlezcano@fr.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=serue@us.ibm.com \
    --cc=viro@ftp.linux.org.uk \
    --subject='Re: [PATCH 1/4] netns: add in ida ID to identify the network namespace' \
    /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

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