netns: revert "netns: avoid disabling irq for netns id"
[cascardo/linux.git] / net / core / net_namespace.c
index 5e00426..f61c0e0 100644 (file)
@@ -37,6 +37,8 @@ struct net init_net = {
 };
 EXPORT_SYMBOL(init_net);
 
+static bool init_net_initialized;
+
 #define INITIAL_NET_GEN_PTRS   13 /* +1 for len +2 for rcu_head */
 
 static unsigned int max_gen_ptrs = INITIAL_NET_GEN_PTRS;
@@ -225,7 +227,6 @@ int peernet2id_alloc(struct net *net, struct net *peer)
                rtnl_net_notifyid(net, RTM_NEWNSID, id);
        return id;
 }
-EXPORT_SYMBOL(peernet2id_alloc);
 
 /* This function returns, if assigned, the id of a peer netns. */
 int peernet2id(struct net *net, struct net *peer)
@@ -238,6 +239,7 @@ int peernet2id(struct net *net, struct net *peer)
        spin_unlock_irqrestore(&net->nsid_lock, flags);
        return id;
 }
+EXPORT_SYMBOL(peernet2id);
 
 /* This function returns true is the peer netns has an id assigned into the
  * current netns.
@@ -551,7 +553,7 @@ static struct pernet_operations __net_initdata net_ns_ops = {
        .exit = net_ns_net_exit,
 };
 
-static struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
+static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
        [NETNSA_NONE]           = { .type = NLA_UNSPEC },
        [NETNSA_NSID]           = { .type = NLA_S32 },
        [NETNSA_PID]            = { .type = NLA_U32 },
@@ -770,6 +772,8 @@ static int __init net_ns_init(void)
        if (setup_net(&init_net, &init_user_ns))
                panic("Could not setup the initial network namespace");
 
+       init_net_initialized = true;
+
        rtnl_lock();
        list_add_tail_rcu(&init_net.list, &net_namespace_list);
        rtnl_unlock();
@@ -831,15 +835,24 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
 static int __register_pernet_operations(struct list_head *list,
                                        struct pernet_operations *ops)
 {
+       if (!init_net_initialized) {
+               list_add_tail(&ops->list, list);
+               return 0;
+       }
+
        return ops_init(ops, &init_net);
 }
 
 static void __unregister_pernet_operations(struct pernet_operations *ops)
 {
-       LIST_HEAD(net_exit_list);
-       list_add(&init_net.exit_list, &net_exit_list);
-       ops_exit_list(ops, &net_exit_list);
-       ops_free_list(ops, &net_exit_list);
+       if (!init_net_initialized) {
+               list_del(&ops->list);
+       } else {
+               LIST_HEAD(net_exit_list);
+               list_add(&init_net.exit_list, &net_exit_list);
+               ops_exit_list(ops, &net_exit_list);
+               ops_free_list(ops, &net_exit_list);
+       }
 }
 
 #endif /* CONFIG_NET_NS */