Skip to content

Commit

Permalink
check all iscsi sessions before logout (#1689)
Browse files Browse the repository at this point in the history
* check all iscsi sessions before logout
  • Loading branch information
jharrod committed Aug 8, 2024
1 parent 608ee80 commit c0d43e2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions frontend/csi/node_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,19 +1347,24 @@ func (p *Plugin) nodeUnstageISCSIVolume(
}

// Logout of the iSCSI session if appropriate for each applicable host
logout := false
for hostNumber, sessionNumber := range hostSessionMap {
if !publishInfo.SharedTarget {
// Always log out of a non-shared target.
logout = true
break
} else {
// Log out of a shared target if no mounts to that target remain.
anyMounts, err := utils.ISCSITargetHasMountedDevice(ctx, publishInfo.IscsiTargetIQN)
if logout = (err == nil) && !anyMounts && utils.SafeToLogOut(ctx, hostNumber, sessionNumber); logout {
break
logout := true
if publishInfo.SharedTarget {
// Check for any remaining mounts for this ISCSI target.
anyMounts, err := utils.ISCSITargetHasMountedDevice(ctx, publishInfo.IscsiTargetIQN)
// It's only safe to logout if there are no mounts and no error occurred when checking.
safeToLogout := !anyMounts && err == nil

// Since there are no mounts and no error occurred, we should check the hosts for any remaining devices.
if safeToLogout {
for hostNumber, sessionNumber := range hostSessionMap {
if !utils.SafeToLogOut(ctx, hostNumber, sessionNumber) {
// If even one host session is in use, we can't logout of the iSCSI sessions.
safeToLogout = false
break
}
}
}
logout = safeToLogout
}

if logout {
Expand Down

0 comments on commit c0d43e2

Please sign in to comment.