Merge pull request #114246 from mxpv/mount

Make Mounter interface exportable
This commit is contained in:
Kubernetes Prow Robot 2022-12-10 07:55:05 -08:00 committed by GitHub
commit c2e55fb066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 14 deletions

View File

@ -218,7 +218,7 @@ func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil return true, nil
} }
func (f *FakeMounter) canSafelySkipMountPointCheck() bool { func (f *FakeMounter) CanSafelySkipMountPointCheck() bool {
return f.skipMountPointCheck return f.skipMountPointCheck
} }

View File

@ -65,10 +65,10 @@ type Interface interface {
// care about such situations, this is a faster alternative to calling List() // care about such situations, this is a faster alternative to calling List()
// and scanning that output. // and scanning that output.
IsLikelyNotMountPoint(file string) (bool, error) IsLikelyNotMountPoint(file string) (bool, error)
// canSafelySkipMountPointCheck indicates whether this mounter returns errors on // CanSafelySkipMountPointCheck indicates whether this mounter returns errors on
// operations for targets that are not mount points. If this returns true, no such // operations for targets that are not mount points. If this returns true, no such
// errors will be returned. // errors will be returned.
canSafelySkipMountPointCheck() bool CanSafelySkipMountPointCheck() bool
// IsMountPoint determines if a directory is a mountpoint. // IsMountPoint determines if a directory is a mountpoint.
// It should return ErrNotExist when the directory does not exist. // It should return ErrNotExist when the directory does not exist.
// IsMountPoint is more expensive than IsLikelyNotMountPoint. // IsMountPoint is more expensive than IsLikelyNotMountPoint.

View File

@ -52,9 +52,9 @@ func CleanupMountWithForce(mountPath string, mounter MounterForceUnmounter, exte
return fmt.Errorf("Error checking path: %v", pathErr) return fmt.Errorf("Error checking path: %v", pathErr)
} }
if corruptedMnt || mounter.canSafelySkipMountPointCheck() { if corruptedMnt || mounter.CanSafelySkipMountPointCheck() {
klog.V(4).Infof("unmounting %q (corruptedMount: %t, mounterCanSkipMountPointChecks: %t)", klog.V(4).Infof("unmounting %q (corruptedMount: %t, mounterCanSkipMountPointChecks: %t)",
mountPath, corruptedMnt, mounter.canSafelySkipMountPointCheck()) mountPath, corruptedMnt, mounter.CanSafelySkipMountPointCheck())
if err := mounter.UnmountWithForce(mountPath, umountTimeout); err != nil { if err := mounter.UnmountWithForce(mountPath, umountTimeout); err != nil {
return err return err
} }
@ -89,9 +89,9 @@ func CleanupMountWithForce(mountPath string, mounter MounterForceUnmounter, exte
// if corruptedMnt is true, it means that the mountPath is a corrupted mountpoint, and the mount point check // if corruptedMnt is true, it means that the mountPath is a corrupted mountpoint, and the mount point check
// will be skipped. The mount point check will also be skipped if the mounter supports it. // will be skipped. The mount point check will also be skipped if the mounter supports it.
func doCleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool, corruptedMnt bool) error { func doCleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool, corruptedMnt bool) error {
if corruptedMnt || mounter.canSafelySkipMountPointCheck() { if corruptedMnt || mounter.CanSafelySkipMountPointCheck() {
klog.V(4).Infof("unmounting %q (corruptedMount: %t, mounterCanSkipMountPointChecks: %t)", klog.V(4).Infof("unmounting %q (corruptedMount: %t, mounterCanSkipMountPointChecks: %t)",
mountPath, corruptedMnt, mounter.canSafelySkipMountPointCheck()) mountPath, corruptedMnt, mounter.CanSafelySkipMountPointCheck())
if err := mounter.Unmount(mountPath); err != nil { if err := mounter.Unmount(mountPath); err != nil {
return err return err
} }

View File

@ -23,7 +23,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/moby/sys/mountinfo"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
"os" "os"
@ -34,6 +33,8 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/moby/sys/mountinfo"
"k8s.io/klog/v2" "k8s.io/klog/v2"
utilexec "k8s.io/utils/exec" utilexec "k8s.io/utils/exec"
utilio "k8s.io/utils/io" utilio "k8s.io/utils/io"
@ -422,8 +423,8 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil return true, nil
} }
// canSafelySkipMountPointCheck relies on the detected behavior of umount when given a target that is not a mount point. // CanSafelySkipMountPointCheck relies on the detected behavior of umount when given a target that is not a mount point.
func (mounter *Mounter) canSafelySkipMountPointCheck() bool { func (mounter *Mounter) CanSafelySkipMountPointCheck() bool {
return mounter.withSafeNotMountedBehavior return mounter.withSafeNotMountedBehavior
} }

View File

@ -74,8 +74,8 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, errUnsupported return true, errUnsupported
} }
// canSafelySkipMountPointCheck always returns false on unsupported platforms // CanSafelySkipMountPointCheck always returns false on unsupported platforms
func (mounter *Mounter) canSafelySkipMountPointCheck() bool { func (mounter *Mounter) CanSafelySkipMountPointCheck() bool {
return false return false
} }

View File

@ -244,8 +244,8 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil return true, nil
} }
// canSafelySkipMountPointCheck always returns false on Windows // CanSafelySkipMountPointCheck always returns false on Windows
func (mounter *Mounter) canSafelySkipMountPointCheck() bool { func (mounter *Mounter) CanSafelySkipMountPointCheck() bool {
return false return false
} }