|
PatchworkOS
|
Per-process Namespaces. More...
Data Structures | |
| struct | namespace_t |
| struct | namespace_t |
| Namespace structure. More... | |
Functions | |
| uint64_t | namespace_init (namespace_t *ns, namespace_t *parent, process_t *owner) |
| Initializes a namespace. | |
| void | namespace_deinit (namespace_t *ns) |
| Deinitializes a namespace. | |
| uint64_t | namespace_traverse_mount (namespace_t *ns, const path_t *mountpoint, path_t *outRoot) |
| Traverse a mountpoint path to the root of the mounted filesystem. | |
| mount_t * | namespace_mount (namespace_t *ns, path_t *mountpoint, const char *deviceName, const char *fsName, void *private) |
| Mount a filesystem in a namespace. | |
| mount_t * | namespace_bind (namespace_t *ns, dentry_t *source, path_t *mountpoint) |
| Bind a directory to a mountpoint in a namespace. | |
| uint64_t | namespace_get_root_path (namespace_t *ns, path_t *outPath) |
| Get the root path of a namespace. | |
Per-process Namespaces.
The Per-process namespace system allows each process to have its own view of the filesystem hierarchy, where the children of a parent can see all the mount points that its parents can but can also have additional mount points that are only visible to itself and its children.
For example, say that in the kernel process we define the /usr directory, and then a child process mounts a filesystem at /usr/local. The kernel process and its other children will not see the /usr/local mount point, but the child process that created it and its own children will see it and be able to access it.
This also has the interesting side effect that its possible to hide directories from child processes by mounting a filesystem on to the directory, causing the children to se the mounted filesystem and not the original directory.
| mount_t * namespace_bind | ( | namespace_t * | ns, |
| dentry_t * | source, | ||
| path_t * | mountpoint | ||
| ) |
Bind a directory to a mountpoint in a namespace.
| ns | The namespace to mount in, can be NULL. |
| source | The source directory to bind. |
| mountpoint | The mountpoint path. |
NULL and errno is set. Definition at line 195 of file namespace.c.
References assert, atomic_load, path_t::dentry, DENTRY_NEGATIVE, DEREF, EINVAL, ENOENT, ERR, errno, dentry_t::id, mount_t::id, kernelProcess, namespace_t::lock, map_insert(), mount_t::mapEntry, path_t::mount, mount, mount_cache_key(), mount_new(), namespace_t::mountPoints, NULL, process_get_kernel(), REF, rwlock_write_acquire(), rwlock_write_release(), and dentry_t::superblock.
Referenced by process_dir_init(), and SYSCALL_DEFINE().
| void namespace_deinit | ( | namespace_t * | ns | ) |
Deinitializes a namespace.
| ns | The namespace to deinitialize. |
Definition at line 48 of file namespace.c.
References map_t::capacity, CONTAINER_OF, DEREF, map_t::entries, namespace_t::lock, map_deinit(), MAP_ENTRY_PTR_IS_VALID, mount, namespace_t::mountPoints, NULL, namespace_t::rootMount, rwlock_write_acquire(), and rwlock_write_release().
Referenced by process_init(), and process_kill().
| uint64_t namespace_get_root_path | ( | namespace_t * | ns, |
| path_t * | outPath | ||
| ) |
Get the root path of a namespace.
| ns | The namespace, can be NULL to get the kernel process's namespace root. |
| outPath | The output root path. |
0. On failure, ERR and errno is set. Definition at line 274 of file namespace.c.
References assert, EINVAL, ENOENT, ERR, errno, kernelProcess, namespace_t::lock, NULL, path_set(), process_get_kernel(), mount_t::root, namespace_t::rootMount, rwlock_read_acquire(), rwlock_read_release(), and mount_t::superblock.
Referenced by path_walk(), and vfs_ctx_get_cwd().
| uint64_t namespace_init | ( | namespace_t * | ns, |
| namespace_t * | parent, | ||
| process_t * | owner | ||
| ) |
Initializes a namespace.
| ns | The namespace to initialize. |
| parent | The parent namespace, can be NULL. |
| owner | The process that owns this namespace. |
0. On failure, ERR and errno is set. Definition at line 28 of file namespace.c.
References EINVAL, ERR, errno, namespace_t::lock, map_init(), namespace_t::mountPoints, NULL, namespace_t::owner, namespace_t::parent, REF, namespace_t::rootMount, and rwlock_init().
Referenced by process_init().
| mount_t * namespace_mount | ( | namespace_t * | ns, |
| path_t * | mountpoint, | ||
| const char * | deviceName, | ||
| const char * | fsName, | ||
| void * | private | ||
| ) |
Mount a filesystem in a namespace.
If ns is NULL, the filesystem will be mounted in the kernel process's namespace which will make it visible to all processes.
| ns | The namespace to mount in, can be NULL. |
| deviceName | The device name, or VFS_DEVICE_NAME_NONE for no device. |
| mountpoint | The mountpoint path. |
| fsName | The filesystem name. |
| flags | Superblock flags. |
| private | Private data for the filesystem's mount function. |
NULL and errno is set. Definition at line 107 of file namespace.c.
References assert, atomic_load, path_t::dentry, DENTRY_NEGATIVE, DEREF, DEREF_DEFER, EBUSY, EINVAL, EIO, ENODEV, ENOENT, ERR, errno, dentry_t::id, mount_t::id, kernelProcess, namespace_t::lock, LOG_DEBUG, LOG_INFO, map_insert(), mount_t::mapEntry, path_t::mount, filesystem_t::mount, mount, mount_cache_key(), mount_new(), namespace_t::mountPoints, NULL, process_get_kernel(), REF, namespace_t::rootMount, rwlock_write_acquire(), rwlock_write_release(), RWLOCK_WRITE_SCOPE, dentry_t::superblock, and vfs_get_fs().
Referenced by ramfs_init(), and sysfs_mount_new().
| uint64_t namespace_traverse_mount | ( | namespace_t * | ns, |
| const path_t * | mountpoint, | ||
| path_t * | outRoot | ||
| ) |
Traverse a mountpoint path to the root of the mounted filesystem.
If the mount point is not found in the namespace or its parents, it will simply return the same path as the mountpoint.
| outRoot | The output root path. |
| ns | The namespace to use. |
| mountpoint | The mountpoint path to traverse. |
0. On failure, ERR and errno is set. Definition at line 73 of file namespace.c.
References CONTAINER_OF_SAFE, path_t::dentry, EINVAL, ERR, errno, ESTALE, dentry_t::id, mount_t::id, namespace_t::lock, map_get(), path_t::mount, mount, mount_cache_key(), namespace_t::mountPoints, NULL, namespace_t::parent, path_copy(), path_set(), mount_t::root, RWLOCK_READ_SCOPE, and mount_t::superblock.
Referenced by path_walk(), and path_walk_single_step().