mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +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. */
|
/* 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->passive, 1);
|
||||||
refcount_set(&net->ns.count, 1);
|
|
||||||
ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt");
|
ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt");
|
||||||
ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt");
|
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_all);
|
||||||
INIT_LIST_HEAD(&net->ptype_specific);
|
INIT_LIST_HEAD(&net->ptype_specific);
|
||||||
preinit_net_sysctl(net);
|
preinit_net_sysctl(net);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -559,7 +572,9 @@ struct net *copy_net_ns(unsigned long flags,
|
||||||
goto dec_ucounts;
|
goto dec_ucounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
preinit_net(net, user_ns);
|
rv = preinit_net(net, user_ns);
|
||||||
|
if (rv < 0)
|
||||||
|
goto dec_ucounts;
|
||||||
net->ucounts = ucounts;
|
net->ucounts = ucounts;
|
||||||
get_user_ns(user_ns);
|
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)
|
static __net_init int net_ns_net_init(struct net *net)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_NS
|
int ret = 0;
|
||||||
net->ns.ops = &netns_operations;
|
|
||||||
#endif
|
if (net == &init_net)
|
||||||
net->ns.inum = PROC_NET_INIT_INO;
|
net->ns.inum = PROC_NET_INIT_INO;
|
||||||
if (net != &init_net) {
|
else
|
||||||
int ret = ns_alloc_inum(&net->ns);
|
ret = proc_alloc_inum(&to_ns_common(net)->inum);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
net_ns_net_debugfs(net);
|
net_ns_net_debugfs(net);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1282,7 +1297,12 @@ void __init net_ns_init(void)
|
||||||
#ifdef CONFIG_KEYS
|
#ifdef CONFIG_KEYS
|
||||||
init_net.key_domain = &init_net_key_domain;
|
init_net.key_domain = &init_net_key_domain;
|
||||||
#endif
|
#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);
|
down_write(&pernet_ops_rwsem);
|
||||||
if (setup_net(&init_net))
|
if (setup_net(&init_net))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user