Discovery sessions have nil Target and nil ITNexus. The cleanup
path crashed with nil pointer dereference when trying to remove
ITNexus or access Target.Sessions for discovery sessions.
Guard against nil Target (just release TSIH) and nil ITNexus.
Also add nil safety to clearHostIP helper.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When a new login arrives while the previous connection's async cleanup
is still running, LookupISCSISession finds the stale session but
LookupConnection returns nil (old connection already closed). This
caused a nil pointer dereference when accessing existConn.session
during session reinstatement.
Fix by checking existConn != nil before reinstatement. If the old
connection is already gone, unbind the stale session and create
a fresh one instead.
Also add sync.Once to removeConnectionFromSession to prevent
concurrent goroutine and main-path cleanup from racing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When an iSCSI connection closes or a logout occurs, the associated
session was never removed from the target's Sessions map, and the
TSIH was never released back to the bitmap allocator. This caused
session and TSIH leaks over repeated connect/disconnect cycles.
Changes:
- Add removeConnectionFromSession() to properly clean up session
when its last connection is closed
- Call session cleanup from handler() on CONN_STATE_CLOSE
- Convert iscsiExecLogout to a method and add session cleanup on logout
- Release TSIH in UnBindISCSISession to prevent TSIH bitmap exhaustion
Fixes#42
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix nil pointer dereference in BindISCSISession when existSess is nil
- Fix reversed logic in SPCLuOffline/SPCLuOnline (Online flag was swapped)
- Use negotiated MaxXmitDataSegmentLength for response PDU segmentation (issue #41)
- Fix debug log incorrectly using Warn level in SBCGetLbaStatus
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Convert constant to var so that it can be configured from backend
- Add options to disable persistent reservation and ORWrite16 commands
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
- Respond with failure for unsupported task management commands
- Increase MaxRecvDataSegmentLength to 65536, to match FirstBurstLength
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>