include/linux/ns/ns_common_types.h

Source file repositories/reference/linux-study-clean/include/linux/ns/ns_common_types.h

File Facts

System
Linux kernel
Corpus path
include/linux/ns/ns_common_types.h
Extension
.h
Size
9482 bytes
Lines
223
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ns_common {
	struct {
		refcount_t __ns_ref; /* do not use directly */
	} ____cacheline_aligned_in_smp;
	u32 ns_type;
	struct dentry *stashed;
	const struct proc_ns_operations *ops;
	unsigned int inum;
	union {
		struct ns_tree;
		struct rcu_head ns_rcu;
	};
};

#define to_ns_common(__ns)                                    \
	_Generic((__ns),                                      \
		struct cgroup_namespace *:       &(__ns)->ns, \
		const struct cgroup_namespace *: &(__ns)->ns, \
		struct ipc_namespace *:          &(__ns)->ns, \
		const struct ipc_namespace *:    &(__ns)->ns, \
		struct mnt_namespace *:          &(__ns)->ns, \
		const struct mnt_namespace *:    &(__ns)->ns, \
		struct net *:                    &(__ns)->ns, \
		const struct net *:              &(__ns)->ns, \
		struct pid_namespace *:          &(__ns)->ns, \
		const struct pid_namespace *:    &(__ns)->ns, \
		struct time_namespace *:         &(__ns)->ns, \
		const struct time_namespace *:   &(__ns)->ns, \
		struct user_namespace *:         &(__ns)->ns, \
		const struct user_namespace *:   &(__ns)->ns, \
		struct uts_namespace *:          &(__ns)->ns, \
		const struct uts_namespace *:    &(__ns)->ns)

#define ns_init_inum(__ns)                                     \
	_Generic((__ns),                                       \
		struct cgroup_namespace *: CGROUP_NS_INIT_INO, \
		struct ipc_namespace *:    IPC_NS_INIT_INO,    \
		struct mnt_namespace *:    MNT_NS_INIT_INO,    \
		struct net *:              NET_NS_INIT_INO,    \
		struct pid_namespace *:    PID_NS_INIT_INO,    \
		struct time_namespace *:   TIME_NS_INIT_INO,   \
		struct user_namespace *:   USER_NS_INIT_INO,   \
		struct uts_namespace *:    UTS_NS_INIT_INO)

#define ns_init_ns(__ns)                                    \
	_Generic((__ns),                                    \
		struct cgroup_namespace *: &init_cgroup_ns, \
		struct ipc_namespace *:    &init_ipc_ns,    \
		struct mnt_namespace *:    &init_mnt_ns,     \
		struct net *:              &init_net,       \
		struct pid_namespace *:    &init_pid_ns,    \
		struct time_namespace *:   &init_time_ns,   \
		struct user_namespace *:   &init_user_ns,   \
		struct uts_namespace *:    &init_uts_ns)

#define ns_init_id(__ns)						\
	_Generic((__ns),						\
		struct cgroup_namespace *:	CGROUP_NS_INIT_ID,	\
		struct ipc_namespace *:		IPC_NS_INIT_ID,		\
		struct mnt_namespace *:		MNT_NS_INIT_ID,		\
		struct net *:			NET_NS_INIT_ID,		\
		struct pid_namespace *:		PID_NS_INIT_ID,		\
		struct time_namespace *:	TIME_NS_INIT_ID,	\
		struct user_namespace *:	USER_NS_INIT_ID,	\
		struct uts_namespace *:		UTS_NS_INIT_ID)

#define to_ns_operations(__ns)                                                                         \
	_Generic((__ns),                                                                               \
		struct cgroup_namespace *: (IS_ENABLED(CONFIG_CGROUPS) ? &cgroupns_operations : NULL), \
		struct ipc_namespace *:    (IS_ENABLED(CONFIG_IPC_NS)  ? &ipcns_operations    : NULL), \
		struct mnt_namespace *:    &mntns_operations,                                          \
		struct net *:              (IS_ENABLED(CONFIG_NET_NS)  ? &netns_operations    : NULL), \
		struct pid_namespace *:    (IS_ENABLED(CONFIG_PID_NS)  ? &pidns_operations    : NULL), \
		struct time_namespace *:   (IS_ENABLED(CONFIG_TIME_NS) ? &timens_operations   : NULL), \
		struct user_namespace *:   (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations   : NULL), \
		struct uts_namespace *:    (IS_ENABLED(CONFIG_UTS_NS)  ? &utsns_operations    : NULL))

/*
 * FOR_EACH_NS_TYPE - Canonical list of namespace types
 *
 * Enumerates all (struct type, CLONE_NEW* flag) pairs.  This is the
 * single source of truth used to derive ns_common_type() and
 * CLONE_NS_ALL.  When adding a new namespace type, add a single entry
 * here; all consumers update automatically.
 *
 * @X: Callback macro taking (struct_name, clone_flag) as arguments.
 */
#define FOR_EACH_NS_TYPE(X)                  \
	X(cgroup_namespace, CLONE_NEWCGROUP) \
	X(ipc_namespace, CLONE_NEWIPC)       \

Annotation

Implementation Notes