Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758850AbYGDBao (ORCPT ); Thu, 3 Jul 2008 21:30:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757908AbYGDB3m (ORCPT ); Thu, 3 Jul 2008 21:29:42 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:45325 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbYGDB3g (ORCPT ); Thu, 3 Jul 2008 21:29:36 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Greg Kroah-Hartman , Andrew Morton Cc: Tejun Heo , Daniel Lezcano , linux-kernel@vger.kernel.org, Al Viro , Linux Containers , Benjamin Thery , References: <20080618170729.808539948@theryb.frec.bull.fr> <486C4515.1070007@gmail.com> <486CB051.5000507@fr.ibm.com> <486CF71F.5090405@gmail.com> Date: Thu, 03 Jul 2008 18:22:35 -0700 In-Reply-To: (Eric W. Biederman's message of "Thu, 03 Jul 2008 18:21:28 -0700") Message-ID: User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SA-Exim-Connect-IP: 24.130.11.59 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Greg Kroah-Hartman , Andrew Morton X-Spam-Relay-Country: X-Spam-Report: * -1.8 ALL_TRUSTED Passed through trusted hosts only via SMTP * -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% * [score: 0.0002] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 XM_SPF_Neutral SPF-Neutral Subject: [PATCH 14/15] netns: Enable tagging for net_class directories in sysfs X-SA-Exim-Version: 4.2 (built Thu, 03 Mar 2005 10:44:12 +0100) X-SA-Exim-Scanned: Yes (on mgr1.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3617 Lines: 126 The problem. Network devices show up in sysfs and with the network namespace active multiple devices with the same name can show up in the same directory, ouch! To avoid that problem and allow existing applications in network namespaces to see the same interface that is currently presented in sysfs, this patch enables the tagging directory support in sysfs. By using the network namespace pointers as tags to separate out the the sysfs directory entries we ensure that we don't have conflicts in the directories and applications only see a limited set of the network devices. Signed-off-by: Eric W. Biederman --- include/linux/sysfs.h | 1 + net/Kconfig | 2 +- net/core/net-sysfs.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletions(-) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index c3a30ce..1ed31bb 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -80,6 +80,7 @@ struct sysfs_ops { enum sysfs_tag_type { SYSFS_TAG_TYPE_NONE = 0, + SYSFS_TAG_TYPE_NETNS, SYSFS_TAG_TYPES }; diff --git a/net/Kconfig b/net/Kconfig index acbf7c6..9aad03b 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -30,7 +30,7 @@ menu "Networking options" config NET_NS bool "Network namespace support" default n - depends on EXPERIMENTAL && !SYSFS && NAMESPACES + depends on EXPERIMENTAL && NAMESPACES help Allow user space to create what appear to be multiple instances of the network stack. diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 4e7b847..6227a28 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -13,7 +13,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -385,6 +387,24 @@ static struct attribute_group wireless_group = { }; #endif +static const void *net_sysfs_mount_tag(void) +{ + return current->nsproxy->net_ns; +} + +static struct sysfs_tag_type_operations net_tag_type_operations = { + .mount_tag = net_sysfs_mount_tag, +}; + +static void net_sysfs_net_exit(struct net *net) +{ + sysfs_exit_tag(SYSFS_TAG_TYPE_NETNS, net); +} + +static struct pernet_operations sysfs_net_ops = { + .exit = net_sysfs_net_exit, +}; + #endif /* CONFIG_SYSFS */ #ifdef CONFIG_HOTPLUG @@ -421,6 +441,13 @@ static void netdev_release(struct device *d) kfree((char *)dev - dev->padded); } +static const void *net_sysfs_tag(struct device *d) +{ + struct net_device *dev; + dev = container_of(d, struct net_device, dev); + return dev_net(dev); +} + static struct class net_class = { .name = "net", .dev_release = netdev_release, @@ -430,6 +457,8 @@ static struct class net_class = { #ifdef CONFIG_HOTPLUG .dev_uevent = netdev_uevent, #endif + .tag_type = SYSFS_TAG_TYPE_NETNS, + .sysfs_tag = net_sysfs_tag, }; /* Delete sysfs entries but hold kobject reference until after all @@ -472,5 +501,9 @@ int netdev_register_kobject(struct net_device *net) int netdev_kobject_init(void) { +#ifdef CONFIG_SYSFS + sysfs_register_tag_type(SYSFS_TAG_TYPE_NETNS, &net_tag_type_operations); + register_pernet_subsys(&sysfs_net_ops); +#endif return class_register(&net_class); } -- 1.5.3.rc6.17.g1911 -- 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/