diff --git a/pkg/util/mount/mount_helper.go b/pkg/util/mount/mount_helper.go index fcbc37a639..a06871e478 100644 --- a/pkg/util/mount/mount_helper.go +++ b/pkg/util/mount/mount_helper.go @@ -24,18 +24,12 @@ import ( "k8s.io/klog" ) -// UnmountPath is a common unmount routine that unmounts the given path and -// deletes the remaining directory if successful. -func UnmountPath(mountPath string, mounter Interface) error { - return UnmountMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) -} - -// UnmountMountPoint is a common unmount routine that unmounts the given path and +// CleanupMountPoint unmounts the given path and // deletes the remaining directory if successful. // if extensiveMountPointCheck is true // IsNotMountPoint will be called instead of IsLikelyNotMountPoint. -// IsNotMountPoint is more expensive but properly handles bind mounts. -func UnmountMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool) error { +// IsNotMountPoint is more expensive but properly handles bind mounts within the same fs. +func CleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool) error { // mounter.ExistsPath cannot be used because for containerized kubelet, we need to check // the path in the kubelet container, not on the host. pathExists, pathErr := PathExists(mountPath) @@ -47,16 +41,17 @@ func UnmountMountPoint(mountPath string, mounter Interface, extensiveMountPointC if pathErr != nil && !corruptedMnt { return fmt.Errorf("Error checking path: %v", pathErr) } - return doUnmountMountPoint(mountPath, mounter, extensiveMountPointCheck, corruptedMnt) + return doCleanupMountPoint(mountPath, mounter, extensiveMountPointCheck, corruptedMnt) } -// doUnmountMountPoint is a common unmount routine that unmounts the given path and +// doCleanupMountPoint unmounts the given path and // deletes the remaining directory if successful. // if extensiveMountPointCheck is true // IsNotMountPoint will be called instead of IsLikelyNotMountPoint. -// IsNotMountPoint is more expensive but properly handles bind mounts. -// if corruptedMnt is true, it means that the mountPath is a corrupted mountpoint, Take it as an argument for convenience of testing -func doUnmountMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool, corruptedMnt bool) error { +// IsNotMountPoint is more expensive but properly handles bind mounts within the same fs. +// if corruptedMnt is true, it means that the mountPath is a corrupted mountpoint, and the mount point check +// will be skipped +func doCleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool, corruptedMnt bool) error { if !corruptedMnt { var notMnt bool var err error diff --git a/pkg/util/mount/mount_helper_test.go b/pkg/util/mount/mount_helper_test.go index e8da449f9e..3afcca3798 100644 --- a/pkg/util/mount/mount_helper_test.go +++ b/pkg/util/mount/mount_helper_test.go @@ -25,7 +25,7 @@ import ( "testing" ) -func TestDoUnmountMountPoint(t *testing.T) { +func TestDoCleanupMountPoint(t *testing.T) { const testMount = "test-mount" const defaultPerm = 0750 @@ -92,7 +92,7 @@ func TestDoUnmountMountPoint(t *testing.T) { MountCheckErrors: map[string]error{mountPoint.Path: mountError}, } - err = doUnmountMountPoint(mountPoint.Path, fake, true, tt.corruptedMnt) + err = doCleanupMountPoint(mountPoint.Path, fake, true, tt.corruptedMnt) if tt.expectErr { if err == nil { t.Errorf("test %s failed, expected error, got none", name) diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 12a6590f15..85a9016968 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -934,11 +934,11 @@ func doCleanSubPath(mounter Interface, fullContainerDirPath, subPathIndex string klog.V(4).Infof("Cleaning up subpath mounts for subpath %v", subPathIndex) fullSubPath := filepath.Join(fullContainerDirPath, subPathIndex) - if err := UnmountMountPoint(fullSubPath, mounter, true); err != nil { - return fmt.Errorf("error unmounting %s: %s", fullSubPath, err) + if err := CleanupMountPoint(fullSubPath, mounter, true); err != nil { + return fmt.Errorf("error cleaning subpath mount %s: %s", fullSubPath, err) } - klog.V(5).Infof("Removed %s", fullSubPath) + klog.V(4).Infof("Successfully cleaned subpath directory %s", fullSubPath) return nil } diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index e3a6e8ed05..18e24d69f0 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -127,9 +127,9 @@ func SetReady(dir string) { // UnmountPath is a common unmount routine that unmounts the given path and // deletes the remaining directory if successful. -// TODO: Change callers to call mount pkg directly +// TODO: Remove this function and change callers to call mount pkg directly func UnmountPath(mountPath string, mounter mount.Interface) error { - return mount.UnmountMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) + return mount.CleanupMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) } // UnmountMountPoint is a common unmount routine that unmounts the given path and @@ -139,7 +139,7 @@ func UnmountPath(mountPath string, mounter mount.Interface) error { // IsNotMountPoint is more expensive but properly handles bind mounts. // TODO: Change callers to call mount pkg directly func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error { - return mount.UnmountMountPoint(mountPath, mounter, extensiveMountPointCheck) + return mount.CleanupMountPoint(mountPath, mounter, extensiveMountPointCheck) } // PathExists returns true if the specified path exists.