Skip to content

Commit 5890f50

Browse files
committed
ns: add ns_debug()
Add ns_debug() that asserts that the correct operations are used for the namespace type. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d7610cb commit 5890f50

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

kernel/nscommon.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22

33
#include <linux/ns_common.h>
44
#include <linux/proc_ns.h>
5+
#include <linux/vfsdebug.h>
6+
7+
#ifdef CONFIG_DEBUG_VFS
8+
static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops)
9+
{
10+
switch (ns->ops->type) {
11+
#ifdef CONFIG_CGROUPS
12+
case CLONE_NEWCGROUP:
13+
VFS_WARN_ON_ONCE(ops != &cgroupns_operations);
14+
break;
15+
#endif
16+
#ifdef CONFIG_IPC_NS
17+
case CLONE_NEWIPC:
18+
VFS_WARN_ON_ONCE(ops != &ipcns_operations);
19+
break;
20+
#endif
21+
case CLONE_NEWNS:
22+
VFS_WARN_ON_ONCE(ops != &mntns_operations);
23+
break;
24+
#ifdef CONFIG_NET_NS
25+
case CLONE_NEWNET:
26+
VFS_WARN_ON_ONCE(ops != &netns_operations);
27+
break;
28+
#endif
29+
#ifdef CONFIG_PID_NS
30+
case CLONE_NEWPID:
31+
VFS_WARN_ON_ONCE(ops != &pidns_operations);
32+
break;
33+
#endif
34+
#ifdef CONFIG_TIME_NS
35+
case CLONE_NEWTIME:
36+
VFS_WARN_ON_ONCE(ops != &timens_operations);
37+
break;
38+
#endif
39+
#ifdef CONFIG_USER_NS
40+
case CLONE_NEWUSER:
41+
VFS_WARN_ON_ONCE(ops != &userns_operations);
42+
break;
43+
#endif
44+
#ifdef CONFIG_UTS_NS
45+
case CLONE_NEWUTS:
46+
VFS_WARN_ON_ONCE(ops != &utsns_operations);
47+
break;
48+
#endif
49+
default:
50+
VFS_WARN_ON_ONCE(true);
51+
}
52+
}
53+
#endif
554

655
int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum)
756
{
@@ -12,6 +61,10 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
1261
RB_CLEAR_NODE(&ns->ns_tree_node);
1362
INIT_LIST_HEAD(&ns->ns_list_node);
1463

64+
#ifdef CONFIG_DEBUG_VFS
65+
ns_debug(ns, ops);
66+
#endif
67+
1568
if (inum) {
1669
ns->inum = inum;
1770
return 0;

0 commit comments

Comments
 (0)