Merge pull request #78941 from jsafrane/fix-iscsi-logout

Fix iscsi logout issues
This commit is contained in:
Kubernetes Prow Robot 2019-07-31 08:54:23 -07:00 committed by GitHub
commit fde94e931f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,6 +60,11 @@ const (
// 'iscsiadm' error code stating that a session is logged in // 'iscsiadm' error code stating that a session is logged in
// See https://github.com/open-iscsi/open-iscsi/blob/7d121d12ad6ba7783308c25ffd338a9fa0cc402b/include/iscsi_err.h#L37-L38 // See https://github.com/open-iscsi/open-iscsi/blob/7d121d12ad6ba7783308c25ffd338a9fa0cc402b/include/iscsi_err.h#L37-L38
iscsiadmErrorSessExists = 15 iscsiadmErrorSessExists = 15
// iscsiadm exit code for "session could not be found"
exit_ISCSI_ERR_SESS_NOT_FOUND = 2
// iscsiadm exit code for "no records/targets/sessions/portals found to execute operation on."
exit_ISCSI_ERR_NO_OBJS_FOUND = 21
) )
var ( var (
@ -723,14 +728,18 @@ func (util *ISCSIUtil) detachISCSIDisk(exec mount.Exec, portals []string, iqn, i
} }
klog.Infof("iscsi: log out target %s iqn %s iface %s", portal, iqn, iface) klog.Infof("iscsi: log out target %s iqn %s iface %s", portal, iqn, iface)
out, err := exec.Run("iscsiadm", logoutArgs...) out, err := exec.Run("iscsiadm", logoutArgs...)
err = ignoreExitCodes(err, exit_ISCSI_ERR_NO_OBJS_FOUND, exit_ISCSI_ERR_SESS_NOT_FOUND)
if err != nil { if err != nil {
klog.Errorf("iscsi: failed to detach disk Error: %s", string(out)) klog.Errorf("iscsi: failed to detach disk Error: %s", string(out))
return err
} }
// Delete the node record // Delete the node record
klog.Infof("iscsi: delete node record target %s iqn %s", portal, iqn) klog.Infof("iscsi: delete node record target %s iqn %s", portal, iqn)
out, err = exec.Run("iscsiadm", deleteArgs...) out, err = exec.Run("iscsiadm", deleteArgs...)
err = ignoreExitCodes(err, exit_ISCSI_ERR_NO_OBJS_FOUND, exit_ISCSI_ERR_SESS_NOT_FOUND)
if err != nil { if err != nil {
klog.Errorf("iscsi: failed to delete node record Error: %s", string(out)) klog.Errorf("iscsi: failed to delete node record Error: %s", string(out))
return err
} }
} }
// Delete the iface after all sessions have logged out // Delete the iface after all sessions have logged out
@ -738,8 +747,10 @@ func (util *ISCSIUtil) detachISCSIDisk(exec mount.Exec, portals []string, iqn, i
if initiatorName != "" && found && iface == (portals[0]+":"+volName) { if initiatorName != "" && found && iface == (portals[0]+":"+volName) {
deleteArgs := []string{"-m", "iface", "-I", iface, "-o", "delete"} deleteArgs := []string{"-m", "iface", "-I", iface, "-o", "delete"}
out, err := exec.Run("iscsiadm", deleteArgs...) out, err := exec.Run("iscsiadm", deleteArgs...)
err = ignoreExitCodes(err, exit_ISCSI_ERR_NO_OBJS_FOUND, exit_ISCSI_ERR_SESS_NOT_FOUND)
if err != nil { if err != nil {
klog.Errorf("iscsi: failed to delete iface Error: %s", string(out)) klog.Errorf("iscsi: failed to delete iface Error: %s", string(out))
return err
} }
} }
@ -933,3 +944,17 @@ func getVolCount(dir, portal, iqn string) (int, error) {
return counter, nil return counter, nil
} }
func ignoreExitCodes(err error, ignoredExitCodes ...int) error {
exitError, ok := err.(utilexec.ExitError)
if !ok {
return err
}
for _, code := range ignoredExitCodes {
if exitError.ExitStatus() == code {
klog.V(4).Infof("ignored iscsiadm exit code %d", code)
return nil
}
}
return err
}