From de865515202264a6cba33ed26f0a87e092d3c468 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 11 Oct 2018 23:22:11 -0700 Subject: [PATCH] pkg/mount: add MakeMount() This function ensures the argument is the mount point (i.e. if it's not, it bind mounts it to itself). Signed-off-by: Kir Kolyshkin (cherry picked from commit 8abadb36fa8149cd44e76b0e7fdedd6f1f2eccd0) Upstream-commit: 2199ada691dc635cac5cdd065d909a539dd0b793 Component: engine --- .../engine/pkg/mount/sharedsubtree_linux.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/components/engine/pkg/mount/sharedsubtree_linux.go b/components/engine/pkg/mount/sharedsubtree_linux.go index 30a3f5b8f0..8a100f0bc8 100644 --- a/components/engine/pkg/mount/sharedsubtree_linux.go +++ b/components/engine/pkg/mount/sharedsubtree_linux.go @@ -48,16 +48,23 @@ func MakeRUnbindable(mountPoint string) error { return ensureMountedAs(mountPoint, "runbindable") } -func ensureMountedAs(mountPoint, options string) error { - mounted, err := Mounted(mountPoint) +// MakeMount ensures that the file or directory given is a mount point, +// bind mounting it to itself it case it is not. +func MakeMount(mnt string) error { + mounted, err := Mounted(mnt) if err != nil { return err } + if mounted { + return nil + } - if !mounted { - if err := Mount(mountPoint, mountPoint, "none", "bind"); err != nil { - return err - } + return Mount(mnt, mnt, "none", "bind") +} + +func ensureMountedAs(mountPoint, options string) error { + if err := MakeMount(mountPoint); err != nil { + return err } return ForceMount("", mountPoint, "none", options)