Commit Graph

2230 Commits

Author SHA1 Message Date
Peter Lieven
ea141f8475 fix: only try to read unit serial if lun != -1
iscsi-ls --show-luns connects to lun -1 for which iscsi inquiry fails on some storage.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-09-22 14:38:38 +00:00
Ronnie Sahlberg
37b8579c9b Merge pull request #461 from plieven/feat/targetname_redirect
feat: allow targetname redirect
2025-09-12 17:33:42 +10:00
Ronnie Sahlberg
ed01816ce9 Merge pull request #460 from plieven/feat/verify_sn
feat: read and validate unit serial number after login
2025-09-12 17:32:34 +10:00
Peter Lieven
247133c9e2 feat: allow targetname redirect
this patch adds an non-RFC extenstion to the redirect login response which allows
a target to temporarily redirect not only to a different target address but also to
a different targetname.

This is needed to allow scenarious in active/active storage clusters where each
node had its own targetname, but maps the same volumes behind equal LUN ids.

For this non-RFC behaviour the environment variable LIBISCSI_ALLLOW_TARGETNAME_REDIRECT
has to be set.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-09-11 19:51:00 +00:00
Peter Lieven
2b2529d196 fix: check scsi_datain_unmarshall for NULL
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-09-11 19:50:45 +00:00
Peter Lieven
5f14051864 fix: check scsi_datain_unmarshall for NULL
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-09-11 19:39:43 +00:00
Peter Lieven
8c4e2ad46b feat: read and validate unit serial number after login
this patch adds a read of VPD page 0x80 (unit serial number) after successful login.

The serial is then validated on secutive reconnects to avoid the accidental mismatch
of LUN ids if some kind of remapping appears between loss of connection and a later
reconnect.

An additional url parameter force_usn is added to enforce the usn right from the beginning.
If not set via url or the new iscsi_set_unit_serial_number function the usn is learned
at the first successful login.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-09-11 15:15:42 +00:00
Ronnie Sahlberg
9b1a625adc Merge pull request #454 from sevan/add-clock_gettime-guard
examples/iscsi-dd.c: add HAVE_CLOCK_GETTIME guards
2025-07-17 08:36:35 +10:00
Sevan Janiyan
1100aa4aa4 examples/iscsi-dd.c: add HAVE_CLOCK_GETTIME guards
Only show time stats if clock_gettime(3) is available.
It's actually possible to have clock_gettime(3) and not yet support
CLOCK_MONOTONIC on legacy systems, however on macOS, they all arrived
together in macOS 10.12. Rather than add new configure checks for
CLOCK_MONOTONIC, I opted to use the existing HAVE_CLOCK_GETTIME.
2025-07-16 18:49:25 +01:00
sahlberg
46631b9083 New version 1.20.3
When queueing the first PDU to an idle socket, immediately try to write
it to the socket instead of waiting for the event-loop to
timeout/notice there is work to do.

Various other small bugfixes.

Signed-off-by: sahlberg <sahlberg@r10-0-1.rocky10.sahlberg>
2025-07-15 19:27:12 +10:00
sahlberg
a8c3920ab8 Write the PDU directly to the socket if the socket is idle.
Signed-off-by: sahlberg <sahlberg@r10-0-1.rocky10.sahlberg>
2025-07-15 19:26:46 +10:00
Ronnie Sahlberg
c92e84c9bc Merge pull request #452 from glagolig/master
fall-through in maintenancein unmarshal switch
2025-07-09 08:52:21 +10:00
Anatoliy Glagolev
89713775dd fall-through in maintenancein unmarshal switch
Fixing a potential fall-through in switch in data unmarshal function
for maintenance-in commands. The fall-through never happens for valid
commands, but the build tools may complain about it.
2025-07-08 16:11:26 -06:00
Ronnie Sahlberg
1255a68acf Merge pull request #451 from glagolig/master
RTPG support
2025-07-05 05:40:59 +10:00
Anatoliy Glagolev
4c39ccc9fc fixup! RTPG support 2025-07-03 17:44:05 -06:00
Anatoliy Glagolev
19d05ab7a7 RTPG support
Implementing support of the Report Target Port Groups command.

Tested on Ubuntu against Pure Storage Flash Array
using designated unit tests and new iscsi-rtpg utility

./iscsi-rtpg  -i iqn.2005-03.org.open-iscsi:6feb2db21ea iscsi://192.168.1.12/iqn.2010-06.com.purestorage:flasharray.4e8d52d82e4b2c0f/1
RTPG retrieved 2 groups
Group 0x0000: preferred 0, format 0x00, ALUA state ACTIVE-OPTIMIZED,flags 0x8f, status code 0x02, port count 65
Ports: [ 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c
0x4d 0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67
0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71]
Group 0x0001: preferred 0, format 0x00, ALUA state ACTIVE-OPTIMIZED,flags 0x8f, status code 0x02, port count 65
Ports: [ 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f 0x20 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a
0x7b 0x7c 0x7d 0x7e 0x7f 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90 0x91 0x92 0x93 0x94 0x95
0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0 0xa1 0xa2]
2025-07-03 17:20:52 -06:00
Ronnie Sahlberg
a2c041ee32 Merge pull request #450 from glagolig/master
iscsi-inq: binary values in hex
2025-06-28 10:00:02 +10:00
Anatoliy Glagolev
e7c44b802f iscsi-inq: binary values in hex
While printing device identification information format
binary values as hex instead of ASCII characters.
2025-06-27 17:21:44 -06:00
Ronnie Sahlberg
914eb5d578 Fix compiler warning/error from the previous commit
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-06-18 10:06:54 +10:00
Ronnie Sahlberg
3a6cfc1273 Merge pull request #449 from lishiao144/master
fix ExpStatSN handling for Data-Out PDUs
2025-06-18 09:55:59 +10:00
lishiao
8ebfb20c55 Optimize the judgment conditions 2025-06-17 12:24:40 +08:00
lishiao
a81eacc0b1 iscsi: compute Data Digest for out_data segments 2025-06-17 11:57:38 +08:00
lishiao144
cbba36e150 fix ExpStatSN handling for Data-Out PDUs 2025-06-12 18:26:19 +08:00
Ronnie Sahlberg
54ef3353a2 Merge pull request #448 from lishiao144/master
Fix length check to exclude padding when comparing against initiator
2025-06-12 18:55:23 +10:00
lishiao144
484adf5017 Fix length check to exclude padding when comparing against initiator_max_recv_data_segment_length 2025-06-12 16:41:53 +08:00
Ronnie Sahlberg
2803276f60 Merge remote-tracking branch 'refs/remotes/origin/master' 2025-05-30 10:53:25 +10:00
Ronnie Sahlberg
37e324c370 Merge pull request #447 from lishiao144/master
Fix CHAP_C Encoding and CHAP_R Comparison in CHAP Authentication
2025-05-30 10:47:06 +10:00
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
bd439878c0 New version 1.20.2
- Fix for Apple as their pthreads do not provide spinlock support.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-05 16:20:09 +10: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