Commit Graph

56 Commits

Author SHA1 Message Date
Lei Xue b7e5c4a7d2 fix: defer session cleanup to connection close, not logout
Move session cleanup out of iscsiExecLogout() and keep it only in
the CONN_STATE_CLOSE handler. The logout response must be fully sent
before the session is removed; cleaning up during logout causes the
daemon to hang because subsequent operations reference a nil session.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 14:11:27 +08:00
Lei Xue 70e1955487 fix: remove dead sessions from target session list
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>
2026-03-16 17:22:01 +08:00
Lei Xue 16108ced95 optimize performance: reduce allocations, buffered I/O, and zero-copy reads
- Read path: eliminate redundant allocation in bsPerformCommand - remove
  the pre-allocation before bs.Read() and the append loop for zero-fill,
  use direct copy and in-place zero-fill instead
- parseHeader: use command pool (getCommand) instead of direct allocation,
  reducing GC pressure on the hot path
- Unmap: use a shared 1MB zero buffer instead of allocating per-descriptor,
  dramatically reducing allocations for large unmap operations
- Network I/O: add 256KB bufio.Writer to iSCSI connections, batching
  small PDU writes into fewer syscalls. Flush after txHandler completes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 19:03:30 +08:00
Lei Xue b2776dc5c2 fix critical bugs and improve iSCSI protocol compliance
- 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>
2026-03-14 12:11:23 +08:00
Lei Xue 00cfac3d24 optimize the perf and support more features 2026-03-14 11:45:35 +08:00
Lei Xue d94641a8d7 add target port as command flag 2022-12-13 09:49:34 +08:00
Lei Xue 8a3e19f0c9 fix daemon 's host flag 2022-12-10 22:05:19 +08:00
prateekpandey14 22c2b95d8f fix(state): reset the CurrentHostIP on closed iscsi connection
Signed-off-by: prateekpandey14 <prateekpandey14@gmail.com>
2021-08-16 20:54:04 +05:30
shubham b278ab3133 Add flag to disable login on multiple hosts
Signed-off-by: shubham <shubham.bajpai@mayadata.io>
2021-06-29 21:15:54 +05:30
Payes Anand e5e3c09feb nit: remove unnecessary if-else block
Signed-off-by: Payes Anand <payes.anand@mayadata.io>
2020-12-06 13:44:13 +05:30
Payes Anand ec418673cb fix: concurrent map iteration and map write
Signed-off-by: Payes Anand <payes.anand@mayadata.io>
2020-12-05 14:51:52 +05:30
Chris Koch 6af024c2e3 iscsit: support AuthMethod=None security negotiation
Signed-off-by: Chris Koch <chrisko@google.com>
2020-01-21 22:45:18 -08:00
Utkarsh Mani Tripathi 901974d8c4 remove conn.close
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-28 13:55:36 +05:30
Utkarsh Mani Tripathi 7f31722587 Listen on configured IP
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-26 17:45:09 +05:30
Utkarsh Mani Tripathi 583e9b3a4a Add option to disable multipath and other fixes
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-21 13:42:32 +05:30
Utkarsh Mani Tripathi d7891b1f68 Implement stats and resize and fix remote backing store apis
- 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>
2019-11-20 14:34:35 +05:30
Utkarsh Mani Tripathi d7caf89610 Implement InitSCSILuMap func for jiva
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-19 10:19:58 +05:30
Utkarsh Mani Tripathi 1b02c7897e fix error handling for unsupported commands
- 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>
2019-11-18 18:20:59 +05:30
Utkarsh Mani Tripathi a8cc3e6db2 improve logs and add client (initiator) status
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 16:25:55 +05:30
Utkarsh Mani Tripathi 1dbc82435f iSCSI target fixes for iSCSIResiduals tests causing libiscsi test suite to hang
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 15:16:41 +05:30
Lei Xue 43deee91c0 Merge pull request #85 from datomia/fix-pool-leak
Fix memory leak
2019-06-30 18:57:44 +08:00
chessman db2ed21438 remove task from PendingTasks queue 2019-06-28 19:56:14 +03:00
chessman 791e74fea5 don't use pool to allocate buffers 2019-06-28 17:55:51 +03:00
chessman 93a6cf0c31 add iscsi target driver closer 2019-06-28 13:00:40 +03:00
chessman f11001ec71 add the ability to add luns dynamically 2019-06-28 13:00:40 +03:00
chessman 8d17243b3a update dependencies 2019-06-12 19:10:59 +03:00
Lei Xue 787d872a30 perf3 2017-08-02 19:44:13 +08:00
Lei Xue fcb96b323d perf2 2017-08-02 19:01:41 +08:00
Lei Xue 4ae643e9f8 perf 2017-07-31 21:47:38 +08:00
Lei Xue eeb30723c8 fix bugs 2017-07-09 09:33:34 +08:00
Lei Xue 8ce8ade3d4 update ModeSense6 function 2017-07-05 21:23:13 +08:00
Lei Xue 1dc950035a fix an issue in ALL.iSCSIcmdsn test case and add it in travis test 2017-06-25 21:05:52 +08:00
Lei Xue 6404f9adc4 fix NO_TASK issue in task management function 2017-06-22 09:12:31 +08:00
Lei Xue 3eb2654e52 Merge pull request #52 from carmark/task
support iscsi task function
2017-06-21 15:30:43 +08:00
Lei Xue 12a648b5f3 fix sense data issue 2017-06-15 08:16:43 +08:00
Lei Xue 7a2b08ff80 support iscsi task function 2017-06-12 21:06:57 +08:00
Payes 6deca56487 Create constants for MaxRecvDataSegmentLength and MaxBurstLength 2017-04-21 18:59:29 +05:30
Payes Anand 0b629a16fe Sending data in dataIn PDUs splitted by maxRecvDataSegment Length 2017-03-12 02:00:30 +05:30
Lei Xue 42949563ac small refactor: combine all package response generation 2016-12-11 18:21:53 +08:00
Le Zhang bb67ec66c7 login negotiation and session/conn reinstatment 2016-12-03 04:23:08 +08:00
Lei Xue d3c3a96920 delete cit to use new gotgt as main cmd, use logrus instead of glog 2016-11-29 11:21:40 +08:00
Lei Xue ed47ac5ea0 move port interface to scsi package 2016-11-27 17:02:17 +08:00
Le Zhang 82e6d230a2 PR implementation 2016-11-24 23:16:53 +08:00
payes 9926fb5931 ExpCmdSN should not be increased for DataOut PDUs 2016-11-23 15:57:23 +05:30
Le Zhang 547faf684d iSCSI/SCSI multi port/ALUA support
fix ALUA flag issue
fix NNA flag issue
fix fixed format sense data builder issue
2016-10-18 16:59:25 +08:00
Lei Xue 4a1dcbfc27 return sense data while error 2016-10-06 12:09:24 +08:00
Lei Xue 13e73124a2 Merge pull request #13 from gostor/lun-mapping
mapping lun and fix portal management
2016-10-04 13:43:48 +08:00
Le Zhang c9b93c7527 mapping lun and fix portal management 2016-10-04 13:39:55 +08:00
Lei Xue f8e74185a2 add r2t response into iscsiExecR2T function 2016-10-04 11:53:06 +08:00
Lei Xue 3512ab66f5 init target and luns from config file 2016-10-01 20:59:30 +08:00