From ae5ca8177d6b0ab85923787f91d2aa717e1f6fd2 Mon Sep 17 00:00:00 2001 From: Georgi Sabev Date: Tue, 9 Apr 2019 16:20:05 +0300 Subject: [PATCH] Refactor mount path check and add comments Co-authored-by: Danail Branekov Signed-off-by: Georgi Sabev --- mount/mount_linux.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mount/mount_linux.go b/mount/mount_linux.go index 1c61c73d5..6bbc50bbf 100644 --- a/mount/mount_linux.go +++ b/mount/mount_linux.go @@ -111,10 +111,18 @@ func unmount(target string, flags int) error { // UnmountAll repeatedly unmounts the given mount point until there // are no mounts remaining (EINVAL is returned by mount), which is // useful for undoing a stack of mounts on the same mount point. +// UnmountAll all is noop when the first argument is an empty string. +// This is done when the containerd client did not specify any rootfs +// mounts (e.g. because the rootfs is managed outside containerd) +// UnmountAll is noop when the mount path does not exist. func UnmountAll(mount string, flags int) error { - if _, err := os.Stat(mount); err != nil { + if mount == "" { return nil } + if _, err := os.Stat(mount); os.IsNotExist(err) { + return nil + } + for { if err := unmount(mount, flags); err != nil { // EINVAL is returned if the target is not a