mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 10:33:41 +02:00
net: use ns_common_init()
Don't cargo-cult the same thing over and over. Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
96ece8eb67
commit
08027f6b79
|
|
@ -397,10 +397,22 @@ static __net_init void preinit_net_sysctl(struct net *net)
|
|||
}
|
||||
|
||||
/* init code that must occur even if setup_net() is not called. */
|
||||
static __net_init void preinit_net(struct net *net, struct user_namespace *user_ns)
|
||||
static __net_init int preinit_net(struct net *net, struct user_namespace *user_ns)
|
||||
{
|
||||
const struct proc_ns_operations *ns_ops;
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_NET_NS
|
||||
ns_ops = &netns_operations;
|
||||
#else
|
||||
ns_ops = NULL;
|
||||
#endif
|
||||
|
||||
ret = ns_common_init(&net->ns, ns_ops, false);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
refcount_set(&net->passive, 1);
|
||||
refcount_set(&net->ns.count, 1);
|
||||
ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt");
|
||||
ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt");
|
||||
|
||||
|
|
@ -420,6 +432,7 @@ static __net_init void preinit_net(struct net *net, struct user_namespace *user_
|
|||
INIT_LIST_HEAD(&net->ptype_all);
|
||||
INIT_LIST_HEAD(&net->ptype_specific);
|
||||
preinit_net_sysctl(net);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -559,7 +572,9 @@ struct net *copy_net_ns(unsigned long flags,
|
|||
goto dec_ucounts;
|
||||
}
|
||||
|
||||
preinit_net(net, user_ns);
|
||||
rv = preinit_net(net, user_ns);
|
||||
if (rv < 0)
|
||||
goto dec_ucounts;
|
||||
net->ucounts = ucounts;
|
||||
get_user_ns(user_ns);
|
||||
|
||||
|
|
@ -812,15 +827,15 @@ static void net_ns_net_debugfs(struct net *net)
|
|||
|
||||
static __net_init int net_ns_net_init(struct net *net)
|
||||
{
|
||||
#ifdef CONFIG_NET_NS
|
||||
net->ns.ops = &netns_operations;
|
||||
#endif
|
||||
net->ns.inum = PROC_NET_INIT_INO;
|
||||
if (net != &init_net) {
|
||||
int ret = ns_alloc_inum(&net->ns);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
int ret = 0;
|
||||
|
||||
if (net == &init_net)
|
||||
net->ns.inum = PROC_NET_INIT_INO;
|
||||
else
|
||||
ret = proc_alloc_inum(&to_ns_common(net)->inum);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
net_ns_net_debugfs(net);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1282,7 +1297,12 @@ void __init net_ns_init(void)
|
|||
#ifdef CONFIG_KEYS
|
||||
init_net.key_domain = &init_net_key_domain;
|
||||
#endif
|
||||
preinit_net(&init_net, &init_user_ns);
|
||||
/*
|
||||
* This currently cannot fail as the initial network namespace
|
||||
* has a static inode number.
|
||||
*/
|
||||
if (preinit_net(&init_net, &init_user_ns))
|
||||
panic("Could not preinitialize the initial network namespace");
|
||||
|
||||
down_write(&pernet_ops_rwsem);
|
||||
if (setup_net(&init_net))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user