From 1fb33aa2dafaba7cdbd4e7f00f59c51acea392a6 Mon Sep 17 00:00:00 2001 From: chengyli Date: Sun, 24 Apr 2016 03:00:59 +0800 Subject: [PATCH] fix cinder volume dir umount issue #24717 fix https://github.com/kubernetes/kubernetes/issues/24717 If kubelet root-dir is a symlink, the pod's cinder volume dir can't be umounted even after pod is deleted. This patch reads target path of symlink before comparing with entries in proc mounts. --- pkg/util/mount/mount.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index 8f0489a3c3e..9c1d8d4f265 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -21,6 +21,7 @@ package mount import ( "github.com/golang/glog" "k8s.io/kubernetes/pkg/util/exec" + "path/filepath" ) type Interface interface { @@ -86,8 +87,13 @@ func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { // Find the device name. deviceName := "" + // If mountPath is symlink, need get its target path. + slTarget, err := filepath.EvalSymlinks(mountPath) + if err != nil { + slTarget = mountPath + } for i := range mps { - if mps[i].Path == mountPath { + if mps[i].Path == slTarget { deviceName = mps[i].Device break } @@ -99,7 +105,7 @@ func GetMountRefs(mounter Interface, mountPath string) ([]string, error) { glog.Warningf("could not determine device for path: %q", mountPath) } else { for i := range mps { - if mps[i].Device == deviceName && mps[i].Path != mountPath { + if mps[i].Device == deviceName && mps[i].Path != slTarget { refs = append(refs, mps[i].Path) } } @@ -118,8 +124,13 @@ func GetDeviceNameFromMount(mounter Interface, mountPath string) (string, int, e // Find the device name. // FIXME if multiple devices mounted on the same mount path, only the first one is returned device := "" + // If mountPath is symlink, need get its target path. + slTarget, err := filepath.EvalSymlinks(mountPath) + if err != nil { + slTarget = mountPath + } for i := range mps { - if mps[i].Path == mountPath { + if mps[i].Path == slTarget { device = mps[i].Device break }