Skip to content

Commit

Permalink
util: use IsMountPoint to detect mounts
Browse files Browse the repository at this point in the history
using IsMountPoint to detect the mounts
as suggested in the document as IsLikelyNotMountPoint
cannot detect the linux bind mounts in some
cases.

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 committed Nov 20, 2024
1 parent d91ee43 commit 4c20bf9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/cephfs/fuserecovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/cephfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -616,7 +616,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)

Expand Down Expand Up @@ -688,7 +688,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)

Expand Down
3 changes: 1 addition & 2 deletions internal/csi-common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,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 {
Expand Down

0 comments on commit 4c20bf9

Please sign in to comment.