diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2026-02-16 12:59:14 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2026-02-16 12:59:14 +0200 |
| commit | 5f46fde558c467414fa151ad962caaf7f07628fa (patch) | |
| tree | 247d6fd45ddbc811fb71d2009fbbd2042e158791 /jprov/mounts.py | |
Initial commit
Diffstat (limited to 'jprov/mounts.py')
| -rw-r--r-- | jprov/mounts.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/jprov/mounts.py b/jprov/mounts.py new file mode 100644 index 0000000..2f87f8e --- /dev/null +++ b/jprov/mounts.py @@ -0,0 +1,22 @@ +"""Nullfs mount handling.""" + +from __future__ import annotations + +import os + +from .config import Mount +from .runner import run + + +def mount_all(root: str, mounts: list[Mount], *, log_file: str | None = None) -> None: + for mnt in mounts: + target = os.path.join(root, mnt.jail.lstrip("/")) + os.makedirs(target, exist_ok=True) + opts = "ro" if mnt.readonly else "rw" + run(["mount", "-t", "nullfs", "-o", opts, mnt.host, target], log_file=log_file) + + +def unmount_all(root: str, mounts: list[Mount], *, log_file: str | None = None) -> None: + for mnt in reversed(mounts): + target = os.path.join(root, mnt.jail.lstrip("/")) + run(["umount", target], allow_fail=True, log_file=log_file) |
