From 59fc287500c9412bb826f8a2120c74ae3f41c9c4 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Wed, 21 Apr 2021 20:38:47 +0530 Subject: [PATCH] iscsi: capture/log iscsi disconnect error and call safe removal At present while iscsi target disconnect is attempted, if there is an error its ignored. This patch fetches the error if any and also log it for further actions. Also to avoid accidental deletion of user data we go with safe path of os.remove() Signed-off-by: Humble Chirammal --- pkg/iscsi/iscsi.go | 2 +- pkg/iscsi/iscsi_util.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/iscsi/iscsi.go b/pkg/iscsi/iscsi.go index 4e9cca74..727c005b 100644 --- a/pkg/iscsi/iscsi.go +++ b/pkg/iscsi/iscsi.go @@ -60,7 +60,7 @@ func getISCSIInfo(req *csi.NodePublishVolumeRequest) (*iscsiDisk, error) { } for _, portal := range portals { - bkportal = append(bkportal, portalMounter(string(portal))) + bkportal = append(bkportal, portalMounter(portal)) } iface := req.GetVolumeContext()["iscsiInterface"] diff --git a/pkg/iscsi/iscsi_util.go b/pkg/iscsi/iscsi_util.go index e482f5de..2590e5bf 100644 --- a/pkg/iscsi/iscsi_util.go +++ b/pkg/iscsi/iscsi_util.go @@ -109,9 +109,10 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, targetPath string) error return err } - iscsi_lib.Disconnect(connector.TargetIqn, connector.TargetPortals) - - if err := os.RemoveAll(targetPath); err != nil { + if disConnectErr := iscsi_lib.Disconnect(connector.TargetIqn, connector.TargetPortals); disConnectErr != nil { + klog.Warningf("Warning: Disconnect failed for IQN: %v", connector.TargetIqn) + } + if err := os.Remove(targetPath); err != nil { klog.Errorf("iscsi: failed to remove mount path Error: %v", err) return err }