Skip to content

Commit 7faad04

Browse files
Kirill TkhaiNagarathnam Muthusamy
authored andcommitted
net: Assign net to net_namespace_list in setup_net()
This patch merges two repeating pieces of code in one, and they will live in setup_net() now. The only change is that assignment: init_net_initialized = true; becomes reordered with: list_add_tail_rcu(&net->list, &net_namespace_list); The order does not have visible effect, and it is a simple cleanup because of: init_net_initialized is used in !CONFIG_NET_NS case to order proc_net_ns_ops registration occuring at boot time: start_kernel()->proc_root_init()->proc_net_init(), with net_ns_init()->setup_net(&init_net, &init_user_ns) also occuring in boot time from the same init_task. When there are no another tasks to race with them, for the single task it does not matter, which order two sequential independent loads should be made. So we make them reordered. Signed-off-by: Kirill Tkhai <[email protected]> Acked-by: Andrei Vagin <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 98f6c53) Orabug: 28900385 Signed-off-by: Nagarathnam Muthusamy <[email protected]> Reviewed-by: Darren Kenny <[email protected]>
1 parent 40a65f1 commit 7faad04

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

net/core/net_namespace.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
295295
if (error < 0)
296296
goto out_undo;
297297
}
298+
rtnl_lock();
299+
list_add_tail_rcu(&net->list, &net_namespace_list);
300+
rtnl_unlock();
298301
out:
299302
return error;
300303

@@ -412,11 +415,6 @@ struct net *copy_net_ns(unsigned long flags,
412415
goto put_userns;
413416

414417
rv = setup_net(net, user_ns);
415-
if (rv == 0) {
416-
rtnl_lock();
417-
list_add_tail_rcu(&net->list, &net_namespace_list);
418-
rtnl_unlock();
419-
}
420418
mutex_unlock(&net_mutex);
421419
if (rv < 0) {
422420
put_userns:
@@ -844,11 +842,6 @@ static int __init net_ns_init(void)
844842
panic("Could not setup the initial network namespace");
845843

846844
init_net_initialized = true;
847-
848-
rtnl_lock();
849-
list_add_tail_rcu(&init_net.list, &net_namespace_list);
850-
rtnl_unlock();
851-
852845
mutex_unlock(&net_mutex);
853846

854847
register_pernet_subsys(&net_ns_ops);

0 commit comments

Comments
 (0)