Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: use ns_common_init()

Don't cargo-cult the same thing over and over.

Signed-off-by: Christian Brauner <brauner@kernel.org>

+33 -13
+33 -13
net/core/net_namespace.c
··· 397 397 } 398 398 399 399 /* init code that must occur even if setup_net() is not called. */ 400 - static __net_init void preinit_net(struct net *net, struct user_namespace *user_ns) 400 + static __net_init int preinit_net(struct net *net, struct user_namespace *user_ns) 401 401 { 402 + const struct proc_ns_operations *ns_ops; 403 + int ret; 404 + 405 + #ifdef CONFIG_NET_NS 406 + ns_ops = &netns_operations; 407 + #else 408 + ns_ops = NULL; 409 + #endif 410 + 411 + ret = ns_common_init(&net->ns, ns_ops, false); 412 + if (ret) 413 + return ret; 414 + 402 415 refcount_set(&net->passive, 1); 403 - refcount_set(&net->ns.count, 1); 404 416 ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt"); 405 417 ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt"); 406 418 ··· 432 420 INIT_LIST_HEAD(&net->ptype_all); 433 421 INIT_LIST_HEAD(&net->ptype_specific); 434 422 preinit_net_sysctl(net); 423 + return 0; 435 424 } 436 425 437 426 /* ··· 572 559 goto dec_ucounts; 573 560 } 574 561 575 - preinit_net(net, user_ns); 562 + rv = preinit_net(net, user_ns); 563 + if (rv < 0) 564 + goto dec_ucounts; 576 565 net->ucounts = ucounts; 577 566 get_user_ns(user_ns); 578 567 ··· 827 812 828 813 static __net_init int net_ns_net_init(struct net *net) 829 814 { 830 - #ifdef CONFIG_NET_NS 831 - net->ns.ops = &netns_operations; 832 - #endif 833 - net->ns.inum = PROC_NET_INIT_INO; 834 - if (net != &init_net) { 835 - int ret = ns_alloc_inum(&net->ns); 836 - if (ret) 837 - return ret; 838 - } 815 + int ret = 0; 816 + 817 + if (net == &init_net) 818 + net->ns.inum = PROC_NET_INIT_INO; 819 + else 820 + ret = proc_alloc_inum(&to_ns_common(net)->inum); 821 + if (ret) 822 + return ret; 823 + 839 824 net_ns_net_debugfs(net); 840 825 return 0; 841 826 } ··· 1297 1282 #ifdef CONFIG_KEYS 1298 1283 init_net.key_domain = &init_net_key_domain; 1299 1284 #endif 1300 - preinit_net(&init_net, &init_user_ns); 1285 + /* 1286 + * This currently cannot fail as the initial network namespace 1287 + * has a static inode number. 1288 + */ 1289 + if (preinit_net(&init_net, &init_user_ns)) 1290 + panic("Could not preinitialize the initial network namespace"); 1301 1291 1302 1292 down_write(&pernet_ops_rwsem); 1303 1293 if (setup_net(&init_net))