aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Kuzmin <kvaster@gmail.com>2022-08-20 23:54:24 +0300
committerViktor Kuzmin <kvaster@gmail.com>2022-08-20 23:54:24 +0300
commit32031fee148673e5afdd97f47afb80721b56caf9 (patch)
treea11ead292979216428228668e9308e22c02964a7
parentb4d5be34718fd4d49cc25ac8f49755b691c6a870 (diff)
downloadseaweedfs-csi-driver-32031fee148673e5afdd97f47afb80721b56caf9.tar.xz
seaweedfs-csi-driver-32031fee148673e5afdd97f47afb80721b56caf9.zip
Make sure mount point is cleaned up even if we think we're not managing it
-rw-r--r--pkg/driver/nodeserver.go10
-rw-r--r--pkg/driver/volume.go18
2 files changed, 12 insertions, 16 deletions
diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go
index 7d9bfc1..38ba34f 100644
--- a/pkg/driver/nodeserver.go
+++ b/pkg/driver/nodeserver.go
@@ -139,6 +139,11 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
volume, ok := ns.volumes.Load(volumeID)
if !ok {
glog.Warningf("volume %s hasn't been published", volumeID)
+
+ // make sure there is no any garbage
+ mounter := mount.New("")
+ _ = mount.CleanupMountPoint(targetPath, mounter, true)
+
return &csi.NodeUnpublishVolumeResponse{}, nil
}
@@ -206,6 +211,11 @@ func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
volume, ok := ns.volumes.Load(volumeID)
if !ok {
glog.Warningf("volume %s hasn't been staged", volumeID)
+
+ // make sure there is no any garbage
+ mounter := mount.New("")
+ _ = mount.CleanupMountPoint(stagingTargetPath, mounter, true)
+
return &csi.NodeUnstageVolumeResponse{}, nil
}
diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go
index 6ed52a8..c7d8f64 100644
--- a/pkg/driver/volume.go
+++ b/pkg/driver/volume.go
@@ -18,11 +18,6 @@ type Volume struct {
// volume's real mount point
stagingTargetPath string
- // Target paths to which the volume has been published.
- // These paths are symbolic links to the real mount point.
- // So multiple pods using the same volume can share a mount.
- targetPaths map[string]bool
-
mounter Mounter
// unix socket used to manage volume
@@ -31,9 +26,8 @@ type Volume struct {
func NewVolume(volumeID string, mounter Mounter) *Volume {
return &Volume{
- VolumeId: volumeID,
- mounter: mounter,
- targetPaths: make(map[string]bool),
+ VolumeId: volumeID,
+ mounter: mounter,
}
}
@@ -78,7 +72,6 @@ func (vol *Volume) Publish(targetPath string, readOnly bool) error {
return err
}
- vol.targetPaths[targetPath] = true
return nil
}
@@ -104,19 +97,12 @@ func (vol *Volume) Expand(sizeByte int64) error {
}
func (vol *Volume) Unpublish(targetPath string) error {
- // Check whether the volume is published to the target path.
- if _, ok := vol.targetPaths[targetPath]; !ok {
- glog.Warningf("volume %s hasn't been published to %s", vol.VolumeId, targetPath)
- return nil
- }
-
// Try unmounting target path and deleting it.
mounter := mount.New("")
if err := mount.CleanupMountPoint(targetPath, mounter, true); err != nil {
return err
}
- delete(vol.targetPaths, targetPath)
return nil
}