diff options
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) |
