From a25ae2b1d5d8a533fa065fb6739f2938d66e61cb Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 21 Nov 2022 14:49:42 +0100 Subject: [PATCH] mounts/ostree.deployment: create private tree mount Create a private mount point for the tree, so that later we can move the `root` mount point. This is needed since "moving a mount residing under a shared mount is invalid and unsupported.", see `mount(8)`. Currently the `tree` is mounted via a private mount- point since reading the tree is done via bind-mounts, but this will change in subsequent commits; this prepares for it. --- mounts/org.osbuild.ostree.deployment | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mounts/org.osbuild.ostree.deployment b/mounts/org.osbuild.ostree.deployment index 70fcc6eb..5571cc1f 100755 --- a/mounts/org.osbuild.ostree.deployment +++ b/mounts/org.osbuild.ostree.deployment @@ -63,6 +63,7 @@ class OSTreeDeploymentMount(mounts.MountService): def __init__(self, args): super().__init__(args) + self.tree = None self.mountpoint = None self.check = False @@ -71,6 +72,7 @@ class OSTreeDeploymentMount(mounts.MountService): subprocess.run([ "mount", "--bind", "--make-private", source, target, ], check=True) + return target def mount(self, args: Dict): @@ -82,6 +84,13 @@ class OSTreeDeploymentMount(mounts.MountService): ref = deployment["ref"] serial = deployment.get("serial", 0) + # create a private mountpoint for the tree, which is needed + # in order to be able to move the `root` mountpoint, which + # is contained inside tree, since "moving a mount residing + # under a shared mount is invalid and unsupported." + # - `mount(8)` + self.tree = self.bind_mount(tree, tree) + root = ostree.deployment_path(tree, osname, ref, serial) print(f"Deployment root at '{os.path.relpath(root, tree)}'") @@ -104,16 +113,18 @@ class OSTreeDeploymentMount(mounts.MountService): self.check = True def umount(self): + if self.mountpoint: + subprocess.run(["sync", "-f", self.mountpoint], + check=self.check) - if not self.mountpoint: - return + subprocess.run(["umount", "-R", self.mountpoint], + check=self.check) + self.mountpoint = None - subprocess.run(["sync", "-f", self.mountpoint], - check=self.check) - - subprocess.run(["umount", "-R", self.mountpoint], - check=self.check) - self.mountpoint = None + if self.tree: + subprocess.run(["umount", "-R", self.tree], + check=self.check) + self.tree = None def main():