Commit Graph

2202 Commits

Author SHA1 Message Date
lishiao144
de86745f14 Update login.c 2025-05-29 14:00:53 +08:00
lishiao144
a57f51708c Incorrect handling of CHAP_C encoding during CHAP_R computation 2025-05-29 11:51:50 +08:00
lishiao144
676afd07a0 Signed vs. unsigned byte mismatch in CHAP_R comparison 2025-05-29 11:50:20 +08:00
Ronnie Sahlberg
35cb001a39 Merge pull request #446 from lishiao144/master
Fix CHAP response buffer zero-init and increase MAX_CHAP_R_SIZE to support SHA-256
2025-05-28 19:16:18 +10:00
lishiao144
7254f954ff zero-initialize target_chap_c to avoid relying on stack memory 2025-05-28 15:59:27 +08:00
lishiao144
b4d1cd7907 MAX_CHAP_R_SIZE updata 2025-05-28 15:57:40 +08:00
Ronnie Sahlberg
fa37a2136c Apple: use mutexes instead of spinlocks on apple
Apple do not support spinlocks so we must remap to the much slower
mutexes instead if we think we are compiling for apple.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-03 20:49:46 +10:00
Ronnie Sahlberg
8cd2381476 New version 1.20.1
Add sha1/sha256/sha3 authentication
Add multithreading support

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-03 10:02:42 +10:00
Ronnie Sahlberg
eb19863f77 Fix race between queueing the pdu and update the task data
After we have called iscsi_queue_pdu from iscsi_scsi_command_async
the pdu might have already completed if we are using multithreading
so we should not dereference pdu at that point.

Move the assignment of task->cmdsn and task->itt we need for
task management into iscsi_pdu_set_cmdsn instead.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 11:55:47 +10:00
Ronnie Sahlberg
d5e3bf6175 Merge branch 'tst' 2025-04-26 11:30:58 +10:00
Ronnie Sahlberg
7e86ed7962 Add multithreaded example using the async API
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 11:28:57 +10:00
Ronnie Sahlberg
31fd95dc8f README: add blurb about multithreading
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:59:28 +10:00
Ronnie Sahlberg
edd7d9b843 Remove the small allocations
This is not compatible with multithreading and would require a complete
re-design.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
8047421868 Protect some variables in iscsi_context by the spinlock
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
91cc1e4197 Protect outqueue and waitpdu with a spinlock
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
4593746363 Add spinlock primitives
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
3fc5d2996b iscsi_queue_pdu() can never fail, make it void
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
37bc6fcd81 TCP: immediately trigger the service thread to write PDU
IF qe queue a new PDU to an empty outqueue then the mt service thread
will still be stuck in poll() until it timesout or the socket becomes
readable.

Fix this by sending SIGUSR1 to the service thread when we queue a PDU
to an empty queue. This will break out of poll() and we can immediately
go and write to the socket.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
f63ed0b76e Remove two global variables used to set the initial seed
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
ca0df22ede Add iscsi-pthreads-readloop
This is a tool to create multiple contexts and threads and run read operations on all
of them in a loop.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
5b391ad188 Pass iscsi to iscsi_init_sync_state
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
09ec037e34 Make the mutex symbols always available
so we do not need to wrap them inside an ifdef.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
1f91358c8a Flag variables in iscsi_context for multithreading audit
These variables may need to be protected by a mutex.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
3c48aea225 Add initial multithreading support and example
This is the basic support for doing i/o in a separate worker thread.
It is still not threads safe but a start.
Now we need to protect all variables such as outqueue, waitpdu
and friends.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
ecc8a10212 Merge pull request #440 from plieven/small_fixes
Small fixes
2025-03-27 09:38:01 +10:00
Peter Lieven
eb0853e36e fix: use correct maximum length for TargetName and InitiatorName
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-26 13:28:23 +00:00
Peter Lieven
90036a167d refactor(TODO): cleanup todos that have been implemented for ages
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-26 13:19:47 +00:00
Ronnie Sahlberg
e968a37c4d Merge pull request #439 from plieven/feat/improve_logging
Add some logging improvements
2025-03-26 08:23:30 +10:00
Peter Lieven
696c946a9b feat(socket): log resolved ip addresses if portal is a hostname
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:21 +00:00
Peter Lieven
98f0f2f7f1 fix(socket): restore logging of local ip and port
commit a92b413 removed the logging of local ip and port.
For debugging puposes these information can be important.
Restore functionality by using the new thread safe replacement
for inet_ntoa called inet_ntop.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:19 +00:00
Peter Lieven
7f0a8597d6 feat(logging): include LUN into log messages
a process might have a connection to different LUNs on the same target.
To be able to distinguish the different connections add the LUN id to the target
to log messages.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:15 +00:00
Ronnie Sahlberg
cb44ad4e26 Add multithreading helpers
Add an abstraction for mutexts and threads
that handles both pthread api and native win32 api

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-03-07 08:46:47 +10:00
Ronnie Sahlberg
f8542ab5cc Add checks if pthreads are available and enable HAVE_MULTITHREADING
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-03-07 07:04:17 +10:00
Ronnie Sahlberg
b8d9fbf5e3 Add CHAP SHA3-256 support
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 14:20:28 +10:00
Ronnie Sahlberg
34e83f7dbd Add support for CHAP with SHA-256
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 09:09:02 +10:00
Ronnie Sahlberg
95a0d98cfd Add support for CHAP using SHA1
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 00:59:02 +10:00
Ronnie Sahlberg
a92b41318c Don't use inet_ntoa, it is deprecated
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-03 15:48:51 +10:00
Ronnie Sahlberg
9637e1371e Merge pull request #434 from raywang-dev/fix-stack-corruption
fix: scan PDUs before exiting event_loop due to connect timedout
2024-12-07 01:30:47 -05:00
Ronnie Sahlberg
6f2f7855c2 Merge pull request #433 from tianrenz2/invalid-fd
lib: finish event_loop on invalid fd
2024-12-07 01:29:43 -05:00
hongleiwang
5cb77051ce fix: scan PDUs before exiting event_loop due to connect timedout
In iSCSI synchronous operations, a struct iscsi_sync_state variable
(state) is allocated on the stack, and its address is assigned to
pdu->scsi_cbdata.private_data. This address is eventually used in
the PDU callback function.

However, if a reconnection occurs during a synchronous operation
(e.g., read or write), but the connect function fails (iscsi->fd
will be set to -1), the event_loop times out and exits. At this point,
unprocessed PDUs remain. If the PDU callback function is triggered
after the timeout (e.g., during iscsi_destroy_context), it may
access the pdu->scsi_cbdata.private_data address, which no longer
points to the original stack allocation. Writing to this invalid
address in the callback corrupts the current stack structure,
leading to process crash.

This patch addresses the issue by scanning PDUs before exiting the
event_loop due connect timedout, ensuring the unprocessed PDUs are
properly handled to prevent stack corruption and crash.

Signed-off-by: raywang <honglei.wang@smartx.com>
2024-12-04 17:55:49 +08:00
Tianren Zhang
458030219d lib: finish event_loop on invalid fd
When iscsi->fd gets invalid, there is not point to
keep stuck in the event loop, instead could give an
accurate error about the invalid fd.

Signed-off-by: Tianren Zhang <tianren@smartx.com>
2024-11-27 04:53:02 +00:00
Ronnie Sahlberg
041f12d27f Merge pull request #432 from tianrenz2/fd-reuse
lib: reserve the fd on reconnect
2024-11-24 22:30:25 -05:00
Tianren Zhang
97ba4c34e2 lib: reserve the fd on reconnect
On reconnect case, the iscsi_tcp_connect tries to reuse
the fd number of old_iscsi. However, this fd could have been
already closed in previous iscsi_tcp_disconnect if
iscsi->fd == iscsi->old_iscsi->fd and the fd number
might have been allocated to some other caller, in this
case the fd reuse in iscsi_tcp_connect is not safe anymore.

Solve this by not closing the fd if iscsi and old_iscsi
share the same fd on reconnect to "really" reserve this
fd number.

Signed-off-by: Tianren Zhang <tianren@smartx.com>
2024-11-22 06:16:59 +00:00
Ronnie Sahlberg
7d1c926bd6 Merge pull request #431 from Ir1Ka/fix-mismatch-alloc-free
Fix mismatch alloc free
2024-11-11 00:16:59 -05:00
IriKa Qiu
057fa61f00 Fix free pdu mismatch with alloc
The pdu alloced by iscsi->drv->new_pdu, by free with iscsi_free direct
when fail in iscsi_allocate_pdu.

Signed-off-by: IriKa Qiu <qiujie.jq@gmail.com>
2024-11-10 03:19:37 +00:00
IriKa Qiu
2934d643ca Fix pdu indata of iser alloc and free mismatch
The pdu indata alloc by iscsi_malloc with a undetermined size, but free
by iscsi_sfree. The iscsi_sfree can only be used to free memory which
size is equal to iscsi->smalloc_size.

Signed-off-by: IriKa Qiu <qiujie.jq@gmail.com>
2024-11-10 03:10:51 +00:00
Ronnie Sahlberg
551d90724d Merge pull request #427 from folkertvanheusden/detail
For failing writes, show what is in the block instead
2024-11-01 15:49:40 -04:00
Ronnie Sahlberg
758e09ebeb Merge pull request #429 from raywang-dev/reset-next-reconnect
feat: add iscsi_reset_next_reconnect interface
2024-11-01 15:48:52 -04:00
hongleiwang
29e626c0f4 feat: add iscsi_reset_next_reconnect interface
When an iSCSI connection enters the reconnection phase, the backoff
time (next_reconnect) increases with reconnection retry_cnt. However,
if the client detects that the target has recovered before reaching
next_reconnect, calling iscsi_reconnect/iscsi_force_reconnect has no
any effect, making fast reconnection impossible.

This patch introduces an interface to reset next_reconnect, so that
the client can reset the backoff time upon detecting target recovery
and achieve faster reconnection.

Resolves: https://github.com/sahlberg/libiscsi/issues/428

Signed-off-by: raywang <honglei.wang@smartx.com>
2024-10-30 18:29:33 +08:00
Folkert van Heusden
aed7faf4db For failing writes, show what is in the sector instead 2024-10-18 08:05:53 +02:00