Skip to content

Commit 7691a85

Browse files
authored
Merge pull request #139 from okartau/tolerate-repeated-unpublish
NodeVolumeUnpublish: tolerate repeated requests
2 parents 9fdddc2 + 2d18f8a commit 7691a85

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pkg/hostpath/nodeserver.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,24 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
204204
return nil, status.Error(codes.NotFound, err.Error())
205205
}
206206

207-
switch vol.VolAccessType {
208-
case blockAccess:
209-
// Unmount and delete the block file.
210-
err = mount.New("").Unmount(targetPath)
211-
if err != nil {
212-
return nil, status.Error(codes.Internal, err.Error())
213-
}
214-
if err = os.RemoveAll(targetPath); err != nil {
207+
// Unmount only if the target path is really a mount point.
208+
if notMnt, err := mount.IsNotMountPoint(mount.New(""), targetPath); err != nil {
209+
if !os.IsNotExist(err) {
215210
return nil, status.Error(codes.Internal, err.Error())
216211
}
217-
glog.V(4).Infof("hostpath: volume %s has been unpublished.", targetPath)
218-
case mountAccess:
219-
// Unmounting the image
220-
err = mount.New("").Unmount(req.GetTargetPath())
212+
} else if !notMnt {
213+
// Unmounting the image or filesystem.
214+
err = mount.New("").Unmount(targetPath)
221215
if err != nil {
222216
return nil, status.Error(codes.Internal, err.Error())
223217
}
224-
glog.V(4).Infof("hostpath: volume %s/%s has been unmounted.", targetPath, volumeID)
225218
}
219+
// Delete the mount point.
220+
// Does not return error for non-existent path, repeated calls OK for idempotency.
221+
if err = os.RemoveAll(targetPath); err != nil {
222+
return nil, status.Error(codes.Internal, err.Error())
223+
}
224+
glog.V(4).Infof("hostpath: volume %s has been unpublished.", targetPath)
226225

227226
if vol.Ephemeral {
228227
glog.V(4).Infof("deleting volume %s", volumeID)

0 commit comments

Comments
 (0)