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 2/4] netns: Export nets id to /proc/net/netns
Date: Wed, 22 Oct 2008 17:22:04 +0200	[thread overview]
Message-ID: <20081022152144.753988954@theryb.frec.bull.fr> (raw)
In-Reply-To: <20081022152144.351965414@theryb.frec.bull.fr>

This patches exports the new 'struct net' net->id value to /proc/net/nsid
file.

Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
---
 net/core/net_namespace.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

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
@@ -6,6 +6,7 @@
 #include <linux/delay.h>
 #include <linux/sched.h>
 #include <linux/idr.h>
+#include <linux/proc_fs.h>
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 
@@ -211,6 +212,53 @@ struct net *copy_net_ns(unsigned long fl
 }
 #endif
 
+#ifdef CONFIG_PROC_FS
+static int netns_seq_show(struct seq_file *seq, void *v)
+{
+	struct net *net = seq->private;
+
+	seq_printf(seq, "%x\n", net->id);
+	return 0;
+}
+
+static int netns_seq_open(struct inode *inode, struct file *file)
+{
+        return single_open_net(inode, file, netns_seq_show);
+}
+
+static const struct file_operations netns_seq_fops = {
+	.owner   = THIS_MODULE,
+	.open    = netns_seq_open,
+	.read	 = seq_read,
+	.llseek	 = seq_lseek,
+	.release = single_release_net,
+};
+
+static int __net_init netns_net_init(struct net *net)
+{
+	if (!proc_net_fops_create(net, "nsid", S_IRUGO, &netns_seq_fops))
+		return -ENOMEM;
+	return 0;
+}
+
+static void __net_exit netns_net_exit(struct net *net)
+{
+	proc_net_remove(net, "nsid");
+}
+
+static struct pernet_operations netns_proc_ops = {
+	.init = netns_net_init,
+	.exit = netns_net_exit,
+};
+
+static int __init netns_proc_init()
+{
+	return register_pernet_subsys(&netns_proc_ops);
+}
+#else
+#define netns_proc_init() 0
+#endif /* CONFIG_PROC_FS */
+
 static int __init net_ns_init(void)
 {
 	int err;
@@ -226,6 +274,8 @@ static int __init net_ns_init(void)
 	if (!netns_wq)
 		panic("Could not create netns workq");
 #endif
+	if (netns_proc_init())
+		panic("Could not register netns subsys");
 
 	mutex_lock(&net_mutex);
 	err = setup_net(&init_net);

-- 

  parent reply	other threads:[~2008-10-22 15:24 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 ` [PATCH 1/4] netns: add in ida ID to identify the network namespace Benjamin Thery
2008-10-22 15:22 ` Benjamin Thery [this message]
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.753988954@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 2/4] netns: Export nets id to /proc/net/netns' \
    /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).