util/mnt: add a remount paramater
This is just a temporary workaround to get the containers-storage input working in `bootc-image-builder`
This commit is contained in:
parent
36d1187c35
commit
9258bda89d
1 changed files with 15 additions and 3 deletions
|
|
@ -50,11 +50,22 @@ def umount(target, lazy=False):
|
||||||
class MountGuard(contextlib.AbstractContextManager):
|
class MountGuard(contextlib.AbstractContextManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mounts = []
|
self.mounts = []
|
||||||
|
self.remount = False
|
||||||
|
|
||||||
def mount(self, source, target, bind=True, permissions: Optional[MountPermissions] = None, mode="0755"):
|
def mount(
|
||||||
|
self,
|
||||||
|
source,
|
||||||
|
target,
|
||||||
|
bind=True,
|
||||||
|
remount=False,
|
||||||
|
permissions: Optional[MountPermissions] = None,
|
||||||
|
mode="0755"):
|
||||||
|
self.remount = remount
|
||||||
options = []
|
options = []
|
||||||
if bind:
|
if bind:
|
||||||
options += ["bind"]
|
options += ["bind"]
|
||||||
|
if remount:
|
||||||
|
options += ["remount"]
|
||||||
if permissions:
|
if permissions:
|
||||||
if permissions not in list(MountPermissions):
|
if permissions not in list(MountPermissions):
|
||||||
raise ValueError(f"unknown filesystem permissions: {permissions}")
|
raise ValueError(f"unknown filesystem permissions: {permissions}")
|
||||||
|
|
@ -86,8 +97,9 @@ class MountGuard(contextlib.AbstractContextManager):
|
||||||
# The sync should in theory not be needed but in rare
|
# The sync should in theory not be needed but in rare
|
||||||
# cases `target is busy` error has been spotted.
|
# cases `target is busy` error has been spotted.
|
||||||
# Calling `sync` does not hurt so we keep it for now.
|
# Calling `sync` does not hurt so we keep it for now.
|
||||||
subprocess.run(["sync", "-f", target], check=True)
|
if not self.remount:
|
||||||
subprocess.run(["umount", target], check=True)
|
subprocess.run(["sync", "-f", target], check=True)
|
||||||
|
subprocess.run(["umount", target], check=True)
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
self.umount()
|
self.umount()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue