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: add symlinks to ref_tracker_dir for netns

After assigning the inode number to the namespace, use it to create a
unique name for each netns refcount tracker with the ns.inum and
net_cookie values in it, and register a symlink to the debugfs file for
it.

init_net is registered before the ref_tracker dir is created, so add a
late_initcall() to register its files and symlinks.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20250618-reftrack-dbgfs-v15-8-24fc37ead144@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jeff Layton and committed by
Jakub Kicinski
8f2079f8 d04992dc

+29 -1
+29 -1
net/core/net_namespace.c
··· 791 791 } 792 792 EXPORT_SYMBOL_GPL(get_net_ns_by_pid); 793 793 794 + #ifdef CONFIG_NET_NS_REFCNT_TRACKER 795 + static void net_ns_net_debugfs(struct net *net) 796 + { 797 + ref_tracker_dir_symlink(&net->refcnt_tracker, "netns-%llx-%u-refcnt", 798 + net->net_cookie, net->ns.inum); 799 + ref_tracker_dir_symlink(&net->notrefcnt_tracker, "netns-%llx-%u-notrefcnt", 800 + net->net_cookie, net->ns.inum); 801 + } 802 + 803 + static int __init init_net_debugfs(void) 804 + { 805 + ref_tracker_dir_debugfs(&init_net.refcnt_tracker); 806 + ref_tracker_dir_debugfs(&init_net.notrefcnt_tracker); 807 + net_ns_net_debugfs(&init_net); 808 + return 0; 809 + } 810 + late_initcall(init_net_debugfs); 811 + #else 812 + static void net_ns_net_debugfs(struct net *net) 813 + { 814 + } 815 + #endif 816 + 794 817 static __net_init int net_ns_net_init(struct net *net) 795 818 { 819 + int ret; 820 + 796 821 #ifdef CONFIG_NET_NS 797 822 net->ns.ops = &netns_operations; 798 823 #endif 799 - return ns_alloc_inum(&net->ns); 824 + ret = ns_alloc_inum(&net->ns); 825 + if (!ret) 826 + net_ns_net_debugfs(net); 827 + return ret; 800 828 } 801 829 802 830 static __net_exit void net_ns_net_exit(struct net *net)