mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
util: do not use mount-utils.IsLikelyNotMountPoint
anymore
`IsLikelyNotMountPoint()` is an optimized version for `IsMountPoint()` which can not detect all type of mounts (anymore). The slower `IsMountPoint()` is more safe to use. This can cause a slight performance regression in the case there are many mountpoints on the system, but correctness is more important than speed while mounting. Fixes: #4633 Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
76b4f53897
commit
79cf0321dd
@ -47,7 +47,7 @@ func (ms mountState) String() string {
|
||||
}
|
||||
|
||||
func (ns *NodeServer) getMountState(path string) (mountState, error) {
|
||||
isMnt, err := util.IsMountPoint(ns.Mounter, path)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(path)
|
||||
if err != nil {
|
||||
if util.IsCorruptedMountError(err) {
|
||||
return msCorrupted, nil
|
||||
|
@ -263,7 +263,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
}
|
||||
}
|
||||
|
||||
isMnt, err := util.IsMountPoint(ns.Mounter, stagingTargetPath)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(stagingTargetPath)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
@ -539,7 +539,7 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
|
||||
// Ensure staging target path is a mountpoint.
|
||||
|
||||
isMnt, err := util.IsMountPoint(ns.Mounter, stagingTargetPath)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(stagingTargetPath)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
@ -552,7 +552,7 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
|
||||
// Check if the volume is already mounted
|
||||
|
||||
isMnt, err = util.IsMountPoint(ns.Mounter, targetPath)
|
||||
isMnt, err = ns.Mounter.IsMountPoint(targetPath)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
@ -615,7 +615,7 @@ func (ns *NodeServer) NodeUnpublishVolume(
|
||||
// stop the health-checker that may have been started in NodeGetVolumeStats()
|
||||
ns.healthChecker.StopChecker(volID, targetPath)
|
||||
|
||||
isMnt, err := util.IsMountPoint(ns.Mounter, targetPath)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(targetPath)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
@ -687,7 +687,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
isMnt, err := util.IsMountPoint(ns.Mounter, stagingTargetPath)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(stagingTargetPath)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
@ -351,7 +350,7 @@ func FilesystemNodeGetVolumeStats(
|
||||
targetPath string,
|
||||
includeInodes bool,
|
||||
) (*csi.NodeGetVolumeStatsResponse, error) {
|
||||
isMnt, err := util.IsMountPoint(mounter, targetPath)
|
||||
isMnt, err := mounter.IsMountPoint(targetPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "targetpath %s does not exist", targetPath)
|
||||
|
@ -200,19 +200,19 @@ func (ns *NodeServer) mountNFS(
|
||||
err error
|
||||
)
|
||||
|
||||
notMnt, err := ns.Mounter.IsLikelyNotMountPoint(mountPoint)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(mountPoint)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
err = os.MkdirAll(mountPoint, defaultMountPermission)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
notMnt = true
|
||||
isMnt = false
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !notMnt {
|
||||
if isMnt {
|
||||
log.DebugLog(ctx, "nfs: volume is already mounted to %s", mountPoint)
|
||||
|
||||
return nil
|
||||
|
@ -880,9 +880,9 @@ func (ns *NodeServer) mountVolume(ctx context.Context, stagingPath string, req *
|
||||
|
||||
func (ns *NodeServer) createTargetMountPath(ctx context.Context, mountPath string, isBlock bool) (bool, error) {
|
||||
// Check if that mount path exists properly
|
||||
notMnt, err := ns.Mounter.IsLikelyNotMountPoint(mountPath)
|
||||
isMnt, err := ns.Mounter.IsMountPoint(mountPath)
|
||||
if err == nil {
|
||||
return notMnt, nil
|
||||
return !isMnt, nil
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
return false, status.Error(codes.Internal, err.Error())
|
||||
@ -893,22 +893,22 @@ func (ns *NodeServer) createTargetMountPath(ctx context.Context, mountPath strin
|
||||
if e != nil {
|
||||
log.DebugLog(ctx, "Failed to create mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return notMnt, status.Error(codes.Internal, e.Error())
|
||||
return !isMnt, status.Error(codes.Internal, e.Error())
|
||||
}
|
||||
if err = pathFile.Close(); err != nil {
|
||||
log.DebugLog(ctx, "Failed to close mountPath:%s with error: %v", mountPath, err)
|
||||
|
||||
return notMnt, status.Error(codes.Internal, err.Error())
|
||||
return !isMnt, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
} else {
|
||||
// Create a mountpath directory
|
||||
if err = util.CreateMountPoint(mountPath); err != nil {
|
||||
return notMnt, status.Error(codes.Internal, err.Error())
|
||||
return !isMnt, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
notMnt = true
|
||||
isMnt = false
|
||||
|
||||
return notMnt, err
|
||||
return !isMnt, err
|
||||
}
|
||||
|
||||
// NodeUnpublishVolume unmounts the volume from the target path.
|
||||
|
@ -219,16 +219,6 @@ func checkDirExists(p string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsMountPoint checks if the given path is mountpoint or not.
|
||||
func IsMountPoint(mounter mount.Interface, p string) (bool, error) {
|
||||
notMnt, err := mounter.IsLikelyNotMountPoint(p)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return !notMnt, nil
|
||||
}
|
||||
|
||||
// IsCorruptedMountError checks if the given error is a result of a corrupted
|
||||
// mountpoint.
|
||||
func IsCorruptedMountError(err error) bool {
|
||||
|
Reference in New Issue
Block a user