]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - net/core/net_namespace.c
Merge tag 'afs-next-20190915' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowel...
[mirror_ubuntu-hirsute-kernel.git] / net / core / net_namespace.c
index f7b6dda798e00b0b6e695f3c3949799a59449d28..a0e0d298c9918f55afe34264c63d0f791160c898 100644 (file)
@@ -152,6 +152,17 @@ static void ops_free(const struct pernet_operations *ops, struct net *net)
        }
 }
 
+static void ops_pre_exit_list(const struct pernet_operations *ops,
+                             struct list_head *net_exit_list)
+{
+       struct net *net;
+
+       if (ops->pre_exit) {
+               list_for_each_entry(net, net_exit_list, exit_list)
+                       ops->pre_exit(net);
+       }
+}
+
 static void ops_exit_list(const struct pernet_operations *ops,
                          struct list_head *net_exit_list)
 {
@@ -336,6 +347,12 @@ out_undo:
         */
        list_add(&net->exit_list, &net_exit_list);
        saved_ops = ops;
+       list_for_each_entry_continue_reverse(ops, &pernet_list, list)
+               ops_pre_exit_list(ops, &net_exit_list);
+
+       synchronize_rcu();
+
+       ops = saved_ops;
        list_for_each_entry_continue_reverse(ops, &pernet_list, list)
                ops_exit_list(ops, &net_exit_list);
 
@@ -560,10 +577,15 @@ static void cleanup_net(struct work_struct *work)
                list_add_tail(&net->exit_list, &net_exit_list);
        }
 
+       /* Run all of the network namespace pre_exit methods */
+       list_for_each_entry_reverse(ops, &pernet_list, list)
+               ops_pre_exit_list(ops, &net_exit_list);
+
        /*
         * Another CPU might be rcu-iterating the list, wait for it.
         * This needs to be before calling the exit() notifiers, so
         * the rcu_barrier() below isn't sufficient alone.
+        * Also the pre_exit() and exit() methods need this barrier.
         */
        synchronize_rcu();
 
@@ -1121,6 +1143,8 @@ static int __register_pernet_operations(struct list_head *list,
 out_undo:
        /* If I have an error cleanup all namespaces I initialized */
        list_del(&ops->list);
+       ops_pre_exit_list(ops, &net_exit_list);
+       synchronize_rcu();
        ops_exit_list(ops, &net_exit_list);
        ops_free_list(ops, &net_exit_list);
        return error;
@@ -1135,6 +1159,8 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
        /* See comment in __register_pernet_operations() */
        for_each_net(net)
                list_add_tail(&net->exit_list, &net_exit_list);
+       ops_pre_exit_list(ops, &net_exit_list);
+       synchronize_rcu();
        ops_exit_list(ops, &net_exit_list);
        ops_free_list(ops, &net_exit_list);
 }
@@ -1159,6 +1185,8 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
        } else {
                LIST_HEAD(net_exit_list);
                list_add(&init_net.exit_list, &net_exit_list);
+               ops_pre_exit_list(ops, &net_exit_list);
+               synchronize_rcu();
                ops_exit_list(ops, &net_exit_list);
                ops_free_list(ops, &net_exit_list);
        }