Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvar...
[pandora-kernel.git] / net / core / net-sysfs.c
index 143052a..99e7052 100644 (file)
@@ -14,7 +14,9 @@
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
 #include <linux/slab.h>
+#include <linux/nsproxy.h>
 #include <net/sock.h>
+#include <net/net_namespace.h>
 #include <linux/rtnetlink.h>
 #include <linux/wireless.h>
 #include <linux/vmalloc.h>
@@ -467,6 +469,7 @@ static struct attribute_group wireless_group = {
        .attrs = wireless_attrs,
 };
 #endif
+#endif /* CONFIG_SYSFS */
 
 #ifdef CONFIG_RPS
 /*
@@ -550,7 +553,7 @@ static void rps_map_release(struct rcu_head *rcu)
        kfree(map);
 }
 
-ssize_t store_rps_map(struct netdev_rx_queue *queue,
+static ssize_t store_rps_map(struct netdev_rx_queue *queue,
                      struct rx_queue_attribute *attribute,
                      const char *buf, size_t len)
 {
@@ -635,7 +638,7 @@ static void rps_dev_flow_table_release(struct rcu_head *rcu)
        schedule_work(&table->free_work);
 }
 
-ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
+static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
                                     struct rx_queue_attribute *attr,
                                     const char *buf, size_t len)
 {
@@ -766,7 +769,38 @@ static void rx_queue_remove_kobjects(struct net_device *net)
        kset_unregister(net->queues_kset);
 }
 #endif /* CONFIG_RPS */
-#endif /* CONFIG_SYSFS */
+
+static const void *net_current_ns(void)
+{
+       return current->nsproxy->net_ns;
+}
+
+static const void *net_initial_ns(void)
+{
+       return &init_net;
+}
+
+static const void *net_netlink_ns(struct sock *sk)
+{
+       return sock_net(sk);
+}
+
+static struct kobj_ns_type_operations net_ns_type_operations = {
+       .type = KOBJ_NS_TYPE_NET,
+       .current_ns = net_current_ns,
+       .netlink_ns = net_netlink_ns,
+       .initial_ns = net_initial_ns,
+};
+
+static void net_kobj_ns_exit(struct net *net)
+{
+       kobj_ns_exit(KOBJ_NS_TYPE_NET, net);
+}
+
+static struct pernet_operations kobj_net_ops = {
+       .exit = net_kobj_ns_exit,
+};
+
 
 #ifdef CONFIG_HOTPLUG
 static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
@@ -774,9 +808,6 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
        struct net_device *dev = to_net_dev(d);
        int retval;
 
-       if (!net_eq(dev_net(dev), &init_net))
-               return 0;
-
        /* pass interface to uevent. */
        retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
        if (retval)
@@ -806,6 +837,13 @@ static void netdev_release(struct device *d)
        kfree((char *)dev - dev->padded);
 }
 
+static const void *net_namespace(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,
@@ -815,6 +853,8 @@ static struct class net_class = {
 #ifdef CONFIG_HOTPLUG
        .dev_uevent = netdev_uevent,
 #endif
+       .ns_type = &net_ns_type_operations,
+       .namespace = net_namespace,
 };
 
 /* Delete sysfs entries but hold kobject reference until after all
@@ -826,9 +866,6 @@ void netdev_unregister_kobject(struct net_device * net)
 
        kobject_get(&dev->kobj);
 
-       if (!net_eq(dev_net(net), &init_net))
-               return;
-
 #ifdef CONFIG_RPS
        rx_queue_remove_kobjects(net);
 #endif
@@ -843,6 +880,7 @@ int netdev_register_kobject(struct net_device *net)
        const struct attribute_group **groups = net->sysfs_groups;
        int error = 0;
 
+       device_initialize(dev);
        dev->class = &net_class;
        dev->platform_data = net;
        dev->groups = groups;
@@ -865,9 +903,6 @@ int netdev_register_kobject(struct net_device *net)
 #endif
 #endif /* CONFIG_SYSFS */
 
-       if (!net_eq(dev_net(net), &init_net))
-               return 0;
-
        error = device_add(dev);
        if (error)
                return error;
@@ -896,13 +931,9 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
 EXPORT_SYMBOL(netdev_class_create_file);
 EXPORT_SYMBOL(netdev_class_remove_file);
 
-void netdev_initialize_kobject(struct net_device *net)
-{
-       struct device *device = &(net->dev);
-       device_initialize(device);
-}
-
 int netdev_kobject_init(void)
 {
+       kobj_ns_type_register(&net_ns_type_operations);
+       register_pernet_subsys(&kobj_net_ops);
        return class_register(&net_class);
 }