PatchworkOS  321f6ec
A non-POSIX operating system.
Loading...
Searching...
No Matches
Namespaces

Per-process Namespaces. More...

Collaboration diagram for Namespaces:

Detailed Description

Per-process Namespaces.

The per-process namespace system allows each process to have its own view of the filesystem hierarchy, by having each process store its own set of mountpoints instead of having a global set of mountpoints.

Propagation

When a new mount or bind is created in a namespace, it is only added to that specific namespace. However, its possible to propagate mounts to children and/or parent namespaces using mount flags (mount_flags_t), this allows those namespaces to also see the new mount or bind.

Data Structures

struct  namespace_mount_t
 
struct  namespace_t
 
struct  namespace_mount
 A mount in a namespace. More...
 
struct  namespace_t
 Namespace structure. More...
 

Functions

void namespace_init (namespace_t *ns)
 Initializes a namespace.
 
void namespace_deinit (namespace_t *ns)
 Clear and deinitialize a namespace.
 
uint64_t namespace_set_parent (namespace_t *ns, namespace_t *parent)
 Sets the parent of a namespace and inherits all mounts from the parent.
 
uint64_t namespace_traverse (namespace_t *ns, path_t *path)
 If the given path is a mountpoint in the namespace, traverse to the mounted filesystem, else no-op.
 
mount_tnamespace_mount (namespace_t *ns, path_t *target, const char *deviceName, const char *fsName, mount_flags_t flags, mode_t mode, void *private)
 Mount a filesystem in a namespace.
 
mount_tnamespace_bind (namespace_t *ns, dentry_t *source, path_t *target, mount_flags_t flags, mode_t mode)
 Bind a source dentry to a target path in a namespace.
 
uint64_t namespace_get_root_path (namespace_t *ns, path_t *out)
 Get the root path of a namespace.
 
void namespace_clear (namespace_t *ns)
 Clears all mounts from a namespace.
 

Function Documentation

◆ namespace_init()

void namespace_init ( namespace_t ns)

Initializes a namespace.

Parameters
nsThe namespace to initialize.
parentThe parent namespace to inherit all mounts from, can be NULL to create an empty namespace.

Definition at line 100 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_deinit()

void namespace_deinit ( namespace_t ns)

Clear and deinitialize a namespace.

Parameters
nsThe namespace to deinitialize.

Definition at line 111 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_set_parent()

uint64_t namespace_set_parent ( namespace_t ns,
namespace_t parent 
)

Sets the parent of a namespace and inherits all mounts from the parent.

Parameters
nsThe namespace to set the parent of.
parentThe new parent namespace.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EBUSY: The namespace already has a parent.
  • ENOMEM: Out of memory.

Definition at line 123 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_traverse()

uint64_t namespace_traverse ( namespace_t ns,
path_t path 
)

If the given path is a mountpoint in the namespace, traverse to the mounted filesystem, else no-op.

Parameters
nsThe namespace to traverse in.
pathThe mountpoint path to traverse, will be updated to the new path if traversed.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.

Definition at line 163 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_mount()

mount_t * namespace_mount ( namespace_t ns,
path_t target,
const char *  deviceName,
const char *  fsName,
mount_flags_t  flags,
mode_t  mode,
void *  private 
)

Mount a filesystem in a namespace.

Parameters
nsThe namespace to mount in.
deviceNameThe device name, or VFS_DEVICE_NAME_NONE for no device.
targetThe target path to mount to.
fsNameThe filesystem name.
flagsMount flags.
modeThe maximum allowed permissions for files/directories opened under this mount.
privatePrivate data for the filesystem's mount function.
Returns
On success, the new mount. On failure, returns NULL and errno is set to:
  • EINVAL: Invalid parameters.
  • EXDEV: The target path is not visible in the namespace.
  • ENODEV: The specified filesystem does not exist.
  • EBUSY: Attempt to mount to already existing root.
  • ENOMEM: Out of memory.
  • ENOENT: The root does not exist or the target is negative.
  • Other errors as returned by the filesystem's mount() function or mount_new().

Definition at line 191 of file namespace.c.

Here is the call graph for this function:

◆ namespace_bind()

mount_t * namespace_bind ( namespace_t ns,
dentry_t source,
path_t target,
mount_flags_t  flags,
mode_t  mode 
)

Bind a source dentry to a target path in a namespace.

Parameters
nsThe namespace to mount in.
sourceThe source dentry to bind from, could be either a file or directory and from any filesystem.
targetThe target path to bind to.
flagsMount flags.
modeThe maximum allowed permissions for files/directories opened under this mount.
Returns
On success, the new mount. On failure, returns NULL and errno is set to:
  • EINVAL: Invalid parameters.
  • ENOMEM: Out of memory.
  • Other errors as returned by mount_new().

Definition at line 259 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_get_root_path()

uint64_t namespace_get_root_path ( namespace_t ns,
path_t out 
)

Get the root path of a namespace.

Parameters
nsThe namespace, can be NULL to get the kernel process's namespace root.
outThe output root path.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • ENOENT: The namespace has no root mount.

Definition at line 286 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namespace_clear()

void namespace_clear ( namespace_t ns)

Clears all mounts from a namespace.

Note
The parent of the namespace will inherit all child namespaces of the deinitialized namespace.
Parameters
nsThe namespace to clear.

Definition at line 306 of file namespace.c.

Here is the call graph for this function:
Here is the caller graph for this function: