include/linux/ns_common.h
Source file repositories/reference/linux-study-clean/include/linux/ns_common.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/ns_common.h- Extension
.h- Size
- 4651 bytes
- Lines
- 153
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ns/ns_common_types.hlinux/refcount.hlinux/vfsdebug.huapi/linux/sched.huapi/linux/nsfs.h
Detected Declarations
function is_ns_init_inumfunction is_ns_init_idfunction __ns_ref_active_readfunction __ns_ref_readfunction __ns_ref_putfunction __ns_ref_getfunction __ns_ref_incfunction __ns_ref_dec_and_lockfunction ns_get_unless_inactive
Annotated Snippet
#ifndef _LINUX_NS_COMMON_H
#define _LINUX_NS_COMMON_H
#include <linux/ns/ns_common_types.h>
#include <linux/refcount.h>
#include <linux/vfsdebug.h>
#include <uapi/linux/sched.h>
#include <uapi/linux/nsfs.h>
bool is_current_namespace(struct ns_common *ns);
int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_operations *ops, int inum);
void __ns_common_free(struct ns_common *ns);
struct ns_common *__must_check ns_owner(struct ns_common *ns);
static __always_inline bool is_ns_init_inum(const struct ns_common *ns)
{
VFS_WARN_ON_ONCE(ns->inum == 0);
return unlikely(in_range(ns->inum, MNT_NS_INIT_INO,
IPC_NS_INIT_INO - MNT_NS_INIT_INO + 1));
}
static __always_inline bool is_ns_init_id(const struct ns_common *ns)
{
VFS_WARN_ON_ONCE(ns->ns_id == 0);
return ns->ns_id <= NS_LAST_INIT_ID;
}
#define NS_COMMON_INIT(nsname) \
{ \
.ns_type = ns_common_type(&nsname), \
.ns_id = ns_init_id(&nsname), \
.inum = ns_init_inum(&nsname), \
.ops = to_ns_operations(&nsname), \
.stashed = NULL, \
.__ns_ref = REFCOUNT_INIT(1), \
.__ns_ref_active = ATOMIC_INIT(1), \
.ns_unified_node.ns_list_entry = LIST_HEAD_INIT(nsname.ns.ns_unified_node.ns_list_entry), \
.ns_tree_node.ns_list_entry = LIST_HEAD_INIT(nsname.ns.ns_tree_node.ns_list_entry), \
.ns_owner_node.ns_list_entry = LIST_HEAD_INIT(nsname.ns.ns_owner_node.ns_list_entry), \
.ns_owner_root.ns_list_head = LIST_HEAD_INIT(nsname.ns.ns_owner_root.ns_list_head), \
}
#define ns_common_init(__ns) \
__ns_common_init(to_ns_common(__ns), \
ns_common_type(__ns), \
to_ns_operations(__ns), \
(((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
#define ns_common_init_inum(__ns, __inum) \
__ns_common_init(to_ns_common(__ns), \
ns_common_type(__ns), \
to_ns_operations(__ns), \
__inum)
#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
bool may_see_all_namespaces(void);
static __always_inline __must_check int __ns_ref_active_read(const struct ns_common *ns)
{
return atomic_read(&ns->__ns_ref_active);
}
static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns)
{
return refcount_read(&ns->__ns_ref);
}
static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
{
if (is_ns_init_id(ns)) {
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
return false;
}
if (refcount_dec_and_test(&ns->__ns_ref)) {
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns));
return true;
}
return false;
}
static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns)
{
if (is_ns_init_id(ns)) {
VFS_WARN_ON_ONCE(__ns_ref_read(ns) != 1);
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns) != 1);
return true;
}
if (refcount_inc_not_zero(&ns->__ns_ref))
Annotation
- Immediate include surface: `linux/ns/ns_common_types.h`, `linux/refcount.h`, `linux/vfsdebug.h`, `uapi/linux/sched.h`, `uapi/linux/nsfs.h`.
- Detected declarations: `function is_ns_init_inum`, `function is_ns_init_id`, `function __ns_ref_active_read`, `function __ns_ref_read`, `function __ns_ref_put`, `function __ns_ref_get`, `function __ns_ref_inc`, `function __ns_ref_dec_and_lock`, `function ns_get_unless_inactive`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.