Commit Graph

2221 Commits

Author SHA1 Message Date
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
Ronnie Sahlberg f5b7a6d0ce Merge pull request #424 from folkertvanheusden/docs
libcunit1-dev is required for iscsi-test-cu to be build
2024-09-21 16:38:50 +10:00
Folkert van Heusden dd1d3a9f6d Merge branch 'master' into docs 2024-09-20 06:33:37 +02:00
Folkert van Heusden f9ca9a7ec8 libcunit1-dev is required for iscsi-test-cu to be build 2024-09-20 06:29:40 +02:00
Ronnie Sahlberg 12bfcd778c Merge pull request #422 from qiankehan/fix-makerpms
Fix 2 issues for makerpms.sh
2024-09-15 17:25:01 +10:00
Han Han 7d4becaeb4 install binaries and manpage to rpm
Add these files to libiscsi-utils package:

- /usr/bin/iscsi-discard
- /usr/bin/iscsi-md5sum
- /usr/bin/iscsi-pr
- /usr/share/man/man1/iscsi-md5sum.1.gz

Signed-off-by: Han Han <hhan@redhat.com>
2024-09-14 15:27:54 +08:00
Han Han 393d5e5204 Add utils.h to dist_noinst_HEADERS
Fix the compiling error when runing packaging/RPM/makerpms.sh:

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I./../include -I./include -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wcast-qual -Wvla -Wno-unknown-warning-option -Wno-stringop-truncation -Wno-unused-parameter -Werror -Wwrite-strings -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -c sync.c -o libiscsipriv_la-sync.o >/dev/null 2>&1
scsi-lowlevel.c:59:10: fatal error: utils.h: No such file or directory
   59 | #include "utils.h"
      |          ^~~~~~~~~

Signed-off-by: Han Han <hhan@redhat.com>
2024-09-14 15:07:51 +08:00
Ronnie Sahlberg b25ee4f0c4 fix use after free in recent commit
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2024-05-30 07:49:48 +10:00
Ronnie Sahlberg 2227e7bda2 Merge pull request #400 from anatoliy-glagolev/master
lun_reset cancelling lun tasks only
2024-05-30 07:48:24 +10:00
Ronnie Sahlberg dd94a21f64 Merge pull request #408 from 54shady/fix-task-free
Manually set task to null after free to avoid double free issue
2024-05-30 07:47:24 +10:00
Ronnie Sahlberg 9f7f2c9a8b Merge pull request #419 from bmeagherix/add_data_digest
Add support for Data Digest
2024-05-30 07:46:29 +10:00
Brian Meagher 882bcad53a Add support for Data Digest 2024-05-04 19:34:06 -07:00
Ronnie Sahlberg ec5d33da63 Merge pull request #416 from folkertvanheusden/timestamp-in-logging
A possible 'fix' for issue #415
2024-04-10 03:38:07 +10:00
Ronnie Sahlberg 90e1916ee0 Merge pull request #418 from bonzini/without-libgcrypt
allow choosing between libgcrypt, gnutls or embedded MD5
2024-04-10 03:36:55 +10:00
Paolo Bonzini 35fec3ea0e login: add support for gnutls
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-04-09 16:06:35 +02:00
Paolo Bonzini e07472a337 login: do not try to "emulate" the libgcrypt API
Implement a more generic wrapper API for message digests, so
that it is easier to also include gnutls as an option.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-04-09 16:01:43 +02:00
Paolo Bonzini 380c16a82b configure: add --with-libgcrypt option
libgcrypt is a relatively large dependency that is used only for
the sake of computing MD5 in the CHAP authentication protocol.

Allow distributions to disable it forcibly and rely on the
embedded MD5 implementation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-04-09 16:01:42 +02:00
folkert van heusden 5fc2dcb88f A possible 'fix' for https://github.com/sahlberg/libiscsi/issues/415
This patch adds a timestamp before each logged line. That could help
correlating a logging to a network-trace. Because of offsets in time
between the tracer and the test and the DUT, this does not always help.
2024-02-14 00:44:26 +01:00
Ronnie Sahlberg fef688aa99 Merge pull request #414 from mjt0k/remove-mentions-of-ld_iscsi
COPYING: stop mentioning ld_scsi
2024-02-06 09:51:38 +10:00
Michael Tokarev 6e0206c135 spelling fixes: eventhough, shoudl, asyncronous, maxium, implicity
These changes are carried in debian for a long time, some since 2016.
The last one (implicity) is new in 1.20.0.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-02-05 10:22:23 -08:00
Michael Tokarev 0be2be2c31 COPYING: stop mentioning ld_scsi
Fixes: e6bcdf5fdb "drop the LD_PRELOAD tool"
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-02-05 21:19:00 +03:00
Ronnie Sahlberg d960e6253c New version 1.20.0
Mostly various updates to the test tool

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2024-02-05 16:59:18 +10:00
Ronnie Sahlberg bfce73325d Merge pull request #411 from folkertvanheusden/task-status
print task-status in hex
2024-01-31 12:57:00 +10:00
folkert van heusden a51eafa90d Previously, 'task->status' was printed as decimal. In iscsi.h, the
values that are put into it are defined as hexadecimal. This is a bit
confusing (grepping through the code for 251658241 did not result in
anything while the hex variant f000001 resulted in SCSI_STATUS_ERROR).
2024-01-30 19:47:28 +01:00
folkert van heusden abedc1848c Fix for https://github.com/sahlberg/libiscsi/issues/409
'ms->pages' was not checked for being NULL. This can happen when a
target does not return any pages.
2024-01-30 06:39:08 -08:00
zeroway 9ec12158b0 Manually set task to null after free to avoid double free issue 2024-01-19 17:41:54 +08:00
Ronnie Sahlberg 0fac8df48c Merge pull request #406 from pizhenwei/improve-dump-header
Improve dump header
2023-12-01 19:49:13 +10:00
zhenwei pi 384191f57f Improve iSCSI PDU header dump
Dump iSCSI opcode firstly, then dump SCSI opcode for SCSI request.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-12-01 16:42:12 +08:00
zhenwei pi a6a664e8cb Abstract value_string as common utility
Originally, we use this in scsi-lowlevel.c only, this works as static
function. It also could be used to dump ISCSI opcode, so move it into
common utils.h/utils.c.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-12-01 10:13:20 +08:00
Ronnie Sahlberg fdd00ee801 Merge pull request #404 from pizhenwei/drain-dataout-pdu-on-timeout
Drain DATAOUT PDU on timeout
2023-11-22 14:43:22 +10:00
zhenwei pi addb11d64c Drain DATAOUT PDU on timeout
Describe the reason again:
A WRITE16 command[w] handles R2T, and queues DATAOUT PDU m,x,y,z:

          outqueue->DATAOUT[x]->DATAOUT[y]->DATAOUT[z]...
  outqueue_current->DATAOUT[m]
         waitqueue->WRITE16[w]...

1, Once x, y, z gets released in initiator side, the target still expects the remaining
DATAOUT PDUs.
2, Once command w timeout and callback to uplayer, uplayers usually releases memory of
   iscsi task(include memory referenced by iovec.iov_base). DATAOUT[m] would access
   invalid memory iovce.iov_base.

So invoke WRITEx command callback until draining DATAOUT PDUs.

Co-developed-by: Rui Zhang <zhangrui.1203@bytedance.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-21 16:59:40 +08:00
Ronnie Sahlberg 03e9ddc0a6 Merge pull request #403 from pizhenwei/fix-socket-error-log
Log necessary message on internal reconnect
2023-11-14 02:50:59 -05:00