aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorViktor Kuzmin <kvaster@gmail.com>2023-08-06 20:55:56 +0300
committerViktor Kuzmin <kvaster@gmail.com>2023-08-06 20:55:56 +0300
commiteca9cde95a899ab5645b00d8c0d547abd4bc7e8e (patch)
treee3c646e031c35b0299d58407994b10b5ed38a89a /pkg
parentcb920765f5d0b3b7a6a54b9bacf5e9be28b46102 (diff)
downloadseaweedfs-csi-driver-eca9cde95a899ab5645b00d8c0d547abd4bc7e8e.tar.xz
seaweedfs-csi-driver-eca9cde95a899ab5645b00d8c0d547abd4bc7e8e.zip
Use single instance of mount utility - mount.New is expensive
Diffstat (limited to 'pkg')
-rw-r--r--pkg/driver/mount_util.go4
-rw-r--r--pkg/driver/mounter.go8
-rw-r--r--pkg/driver/nodeserver.go6
-rw-r--r--pkg/driver/utils.go7
-rw-r--r--pkg/driver/volume.go8
5 files changed, 14 insertions, 19 deletions
diff --git a/pkg/driver/mount_util.go b/pkg/driver/mount_util.go
index d288e8c..40716d0 100644
--- a/pkg/driver/mount_util.go
+++ b/pkg/driver/mount_util.go
@@ -7,11 +7,13 @@ import (
"k8s.io/mount-utils"
)
+var mountutil = mount.New("")
+
func waitForMount(path string, timeout time.Duration) error {
var elapsed time.Duration
var interval = 10 * time.Millisecond
for {
- notMount, err := mount.New("").IsLikelyNotMountPoint(path)
+ notMount, err := mountutil.IsLikelyNotMountPoint(path)
if err != nil {
return err
}
diff --git a/pkg/driver/mounter.go b/pkg/driver/mounter.go
index 34e0461..64eae33 100644
--- a/pkg/driver/mounter.go
+++ b/pkg/driver/mounter.go
@@ -79,7 +79,7 @@ func fuseMount(path string, command string, args []string) (Unmounter, error) {
// make sure we'll have no stale mounts
time.Sleep(time.Millisecond * 100)
- _ = mount.New("").Unmount(path)
+ _ = mountutil.Unmount(path)
close(fu.finished)
}()
@@ -122,10 +122,8 @@ func (fu *fuseUnmounter) waitFinished(timeout time.Duration) error {
}
func (fu *fuseUnmounter) Unmount() error {
- m := mount.New("")
-
- if ok, err := m.IsLikelyNotMountPoint(fu.path); !ok || mount.IsCorruptedMnt(err) {
- if err := m.Unmount(fu.path); err != nil {
+ if ok, err := mountutil.IsLikelyNotMountPoint(fu.path); !ok || mount.IsCorruptedMnt(err) {
+ if err := mountutil.Unmount(fu.path); err != nil {
return err
}
}
diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go
index d89919e..56d02c6 100644
--- a/pkg/driver/nodeserver.go
+++ b/pkg/driver/nodeserver.go
@@ -149,8 +149,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
glog.Warningf("volume %s hasn't been published", volumeID)
// make sure there is no any garbage
- mounter := mount.New("")
- _ = mount.CleanupMountPoint(targetPath, mounter, true)
+ _ = mount.CleanupMountPoint(targetPath, mountutil, true)
return &csi.NodeUnpublishVolumeResponse{}, nil
}
@@ -221,8 +220,7 @@ func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
glog.Warningf("volume %s hasn't been staged", volumeID)
// make sure there is no any garbage
- mounter := mount.New("")
- _ = mount.CleanupMountPoint(stagingTargetPath, mounter, true)
+ _ = mount.CleanupMountPoint(stagingTargetPath, mountutil, true)
} else {
if err := volume.(*Volume).Unstage(stagingTargetPath); err != nil {
return nil, status.Error(codes.Internal, err.Error())
diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go
index ea83209..eee1825 100644
--- a/pkg/driver/utils.go
+++ b/pkg/driver/utils.go
@@ -70,8 +70,7 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
}
func checkMount(targetPath string) (bool, error) {
- mounter := mount.New("")
- isMnt, err := mounter.IsMountPoint(targetPath)
+ isMnt, err := mountutil.IsMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
if err = os.MkdirAll(targetPath, 0750); err != nil {
@@ -79,10 +78,10 @@ func checkMount(targetPath string) (bool, error) {
}
isMnt = false
} else if mount.IsCorruptedMnt(err) {
- if err := mounter.Unmount(targetPath); err != nil {
+ if err := mountutil.Unmount(targetPath); err != nil {
return false, err
}
- isMnt, err = mounter.IsMountPoint(targetPath)
+ isMnt, err = mountutil.IsMountPoint(targetPath)
} else {
return false, err
}
diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go
index a6a8cfc..5358700 100644
--- a/pkg/driver/volume.go
+++ b/pkg/driver/volume.go
@@ -36,7 +36,7 @@ func (vol *Volume) Stage(stagingTargetPath string) error {
return err
} else if isMnt {
// try to unmount before mounting again
- _ = mount.New("").Unmount(stagingTargetPath)
+ _ = mountutil.Unmount(stagingTargetPath)
}
if u, err := vol.mounter.Mount(stagingTargetPath); err == nil {
@@ -62,8 +62,7 @@ func (vol *Volume) Publish(stagingTargetPath string, targetPath string, readOnly
mountOptions = append(mountOptions, "ro")
}
- mounter := mount.New("")
- if err := mounter.Mount(stagingTargetPath, targetPath, "", mountOptions); err != nil {
+ if err := mountutil.Mount(stagingTargetPath, targetPath, "", mountOptions); err != nil {
return err
}
@@ -89,8 +88,7 @@ func (vol *Volume) Expand(sizeByte int64) error {
func (vol *Volume) Unpublish(targetPath string) error {
// Try unmounting target path and deleting it.
- mounter := mount.New("")
- if err := mount.CleanupMountPoint(targetPath, mounter, true); err != nil {
+ if err := mount.CleanupMountPoint(targetPath, mountutil, true); err != nil {
return err
}