69 Commits

Author SHA1 Message Date
Lei Xue
a7b58b8eb3 fix: handle discovery sessions in UnBindISCSISession
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>
2026-03-17 15:01:22 +08:00
Lei Xue
be3cad5aba fix: extract clearHostIP helper and restore IP cleanup on close
Restore CurrentHostIP cleanup on connection close (needed for
blockMultipleHostLogin feature). Extract to clearHostIP helper
to reduce duplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 14:54:08 +08:00
Lei Xue
8ffe5ec5ce fix: prevent nil deref on session reinstatement during cleanup race
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>
2026-03-17 14:37:16 +08:00
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
25f0038456 Add tgtNSG to fullfeaturephase and tgtTrans to true
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-20 17:03:58 +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
64deda8106 convert initialR2T to always true for datadigest
tttttt-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 18:10:53 +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
f339c5e70c downgrade ceph 2019-06-12 20:14:12 +03:00
chessman
8d17243b3a update dependencies 2019-06-12 19:10:59 +03:00
xgwang
29b6c29902 Fix typo of fmt format 2018-05-10 10:30:12 +08: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
payes
ddf59bf1cb Making sure the required number of bytes are read 2017-02-17 18:55:27 +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
18e1419b06 fix verify and add verify test cases 2016-11-28 16:26:05 +08:00