Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753890AbYJVPYP (ORCPT ); Wed, 22 Oct 2008 11:24:15 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755500AbYJVPXe (ORCPT ); Wed, 22 Oct 2008 11:23:34 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:37021 "EHLO ecfrec.frec.bull.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755447AbYJVPXc (ORCPT ); Wed, 22 Oct 2008 11:23:32 -0400 Message-Id: <20081022152144.753988954@theryb.frec.bull.fr> References: <20081022152144.351965414@theryb.frec.bull.fr> User-Agent: quilt/0.46-1 Date: Wed, 22 Oct 2008 17:22:04 +0200 From: Benjamin Thery To: netdev , Dave Miller Cc: Eric Biederman , Greg Kroah-Hartman , Al Viro , Serge Hallyn , Daniel Lezcano , linux-kernel@vger.kernel.org, Tejun Heo , Denis Lunev , Linux Containers , Benjamin Thery Subject: [PATCH 2/4] netns: Export nets id to /proc/net/netns Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2305 Lines: 90 This patches exports the new 'struct net' net->id value to /proc/net/nsid file. Signed-off-by: Benjamin Thery --- 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 #include #include +#include #include #include @@ -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); -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/