Files
laptops-kernel/kernel/nscommon.c
T

77 lines
1.5 KiB
C
Raw Normal View History

2025-09-17 12:28:02 +02:00
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/ns_common.h>
2025-09-17 12:28:07 +02:00
#include <linux/proc_ns.h>
2025-09-22 14:42:37 +02:00
#include <linux/vfsdebug.h>
#ifdef CONFIG_DEBUG_VFS
static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops)
{
2025-09-24 13:33:59 +02:00
switch (ns->ns_type) {
2025-09-22 14:42:37 +02:00
#ifdef CONFIG_CGROUPS
case CLONE_NEWCGROUP:
VFS_WARN_ON_ONCE(ops != &cgroupns_operations);
break;
#endif
#ifdef CONFIG_IPC_NS
case CLONE_NEWIPC:
VFS_WARN_ON_ONCE(ops != &ipcns_operations);
break;
#endif
case CLONE_NEWNS:
VFS_WARN_ON_ONCE(ops != &mntns_operations);
break;
#ifdef CONFIG_NET_NS
case CLONE_NEWNET:
VFS_WARN_ON_ONCE(ops != &netns_operations);
break;
#endif
#ifdef CONFIG_PID_NS
case CLONE_NEWPID:
VFS_WARN_ON_ONCE(ops != &pidns_operations);
break;
#endif
#ifdef CONFIG_TIME_NS
case CLONE_NEWTIME:
VFS_WARN_ON_ONCE(ops != &timens_operations);
break;
#endif
#ifdef CONFIG_USER_NS
case CLONE_NEWUSER:
VFS_WARN_ON_ONCE(ops != &userns_operations);
break;
#endif
#ifdef CONFIG_UTS_NS
case CLONE_NEWUTS:
VFS_WARN_ON_ONCE(ops != &utsns_operations);
break;
#endif
}
}
#endif
2025-09-17 12:28:02 +02:00
2025-09-24 13:33:59 +02:00
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum)
2025-09-17 12:28:02 +02:00
{
2025-09-18 12:11:59 +02:00
refcount_set(&ns->__ns_ref, 1);
2025-09-17 12:28:02 +02:00
ns->stashed = NULL;
ns->ops = ops;
ns->ns_id = 0;
2025-09-24 13:33:59 +02:00
ns->ns_type = ns_type;
2025-09-17 12:28:02 +02:00
RB_CLEAR_NODE(&ns->ns_tree_node);
INIT_LIST_HEAD(&ns->ns_list_node);
2025-09-17 12:28:07 +02:00
2025-09-22 14:42:37 +02:00
#ifdef CONFIG_DEBUG_VFS
ns_debug(ns, ops);
#endif
2025-09-17 12:28:07 +02:00
if (inum) {
ns->inum = inum;
return 0;
}
return proc_alloc_inum(&ns->inum);
2025-09-17 12:28:02 +02:00
}
2025-09-17 12:28:08 +02:00
void __ns_common_free(struct ns_common *ns)
{
proc_free_inum(ns->inum);
}