Commit Graph

84 Commits

Author SHA1 Message Date
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
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
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
75a46d2b2e Add add a timeout to the event_loop in sync.c
This timeout can be used to cancel async connect attempts to
a remote target.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2023-09-19 16:16:44 +10:00
John Levon
30dd7c6429 add iscsi_force_reconnect()
If a connection attempt is hung, then iscsi_reconnect() won't do anything. This
makes sense if we'd just re-try to connect to the same target, but if (for
example) login redirect might point us to a different, healthy, target, it
should be possible to restart the full connection process on request.

Signed-off-by: John Levon <john.levon@nutanix.com>
2022-01-17 13:14:49 -08:00
Bart Van Assche
2a5a0b3291 Enable -Wno-unused-parameter
Instead of adding __attribute__((unused)) to unused arguments, add the
-Wno-unused-parameter compiler flag.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-05-23 13:23:41 -07:00
Bart Van Assche
3804f3c2e0 Remove the discard_const() macro
Declare dynamically allocated strings as 'char *' instead of 'const char *'.
Remove the discard_const() macro. Do not test whether or not a pointer is
NULL before calling free() because it is allowed to pass NULL to free().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-28 21:54:49 -08:00
Tim Crawford
9347cfebf2 Replace file variables with .dir-locals.el
Signed-off-by: Tim Crawford <tcrawford@datto.com>
2019-02-21 11:54:02 -05:00
Paolo Bonzini
f507c94774 sync: remove unnecessary checks
state is always non-NULL in iscsi_sync_cb and iscsi_discovery_cb.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-04 14:06:39 +02:00
Felipe Franciosi
25eb87c7ee sync: cancel pending pdus on error
The set of sync connect calls use a stack variable to track the
connection status. This is ok because such calls block on event_poll()
until the connection is established. However, event_poll may return
early in case of errors (or timeout) while PDUs are still queued on the
context (and pointing to a local stack).

This cancels any pending PDUs before returning from sync connect calls.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2017-11-25 17:12:38 +00:00
Felipe Franciosi
28d0db9c96 lib/pdu.c: clean up empty lines
Remove some extra empty lines between functions.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2017-11-25 16:44:30 +00:00
Tim Crawford
aba0f7da1a Replace WIN32 with _WIN32
Using WIN32 depends on the build environment defining the variable.
_WIN32 is a predefined MSVC macro and is always available.

Signed-off-by: Tim Crawford <crawfxrd@gmail.com>
2017-11-29 10:07:44 -05:00
Ronnie Sahlberg
f750101980 Add initial visual studio project files and fix the win32 build
Win32 has been rotting for a while. This patch adds vs17 build files
as well as fixing up all build errors that have accumulated.
There are still build warnings but those can be addressed in a followup
patch.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-11 21:19:14 -07:00
Peter Lieven
b5210a1e31 sync: fix return value for various sync commands
all sync commands that return an integer value are
supposed to return a negative value on error.
However, state.status is positive non-zero on error.
Fix this by returning -1 if the state.status is
not SCSI_STATUS_GOOD.

Reported-by: Sitsofe Wheeler <sitsofe@yahoo.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-23 15:40:09 +01:00
David Disseldorp
4bc5f962e2 Libiscsi: add support for EXTENDED COPY
Build on existing scsi_cdb_extended_copy() functionality. This operation
can be used to offload inter and intra LU copies to the target.

The API is rather primitive, in that the caller needs to construct the
parameter buffer, including CSCD and segment descriptor lists, etc.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-01-04 19:33:00 +01:00
David Disseldorp
f475436c5a Libiscsi: add support for RECEIVE COPY RESULTS
Build on existing scsi_cdb_receive_copy_results() functionality. This
request is most commonly used to determine target-side EXTENDED COPY
operational parameters.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-01-04 19:33:00 +01:00
Ronnie Sahlberg
d3ef192021 Add synchronous function iscsi_discovery_sync()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-10-09 11:54:10 -07:00
Ronnie Sahlberg
39001203b7 TESTS: simple support for READDEFECTDATA10/12
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-09-22 22:43:16 -07:00
Roy Shterman
c85042bacb Libiscsi: Introducing new functions for zero-copy write operations
iscsi-command:  Adding new functions for all write operations (WRITE10,
                WRITE12, WRITE16, WRITEOR, etc') for cases where the user wants
                to pass his own io vectors (prevent memcpy).

                new functions are called iscsi_write*_iov_task and looks
                very similar to the iscsi_write*_task, only they get
		scsi_iovec pointer and number of scsi_iovec as
		parameters.

Change-Id: I719552b4cbda4f937975b5df7e77b4844e48cd16
Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:51:27 -07:00
Roy Shterman
e00e47d28d Libiscsi: Introducing new functions for zero-copy read operations
iscsi-command:  Adding new functions for all write operations (READ6,
                READ10, READ12, READ16, etc') for cases where the
		user wants to pass his own io vectors (prevent memcpy).

                new functions are called iscsi_read*_iov_task and looks
                very similar to the iscsi_read*_task, only they get
                scsi_iovec pointer and number of scsi_iovec as
                parameters.

Change-Id: Ice6bdb9227d72b20f495927f17d6757c124e4c84
Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:47:55 -07:00
David Disseldorp
c38a8c1d9a task_mgmt: don't cancel local PDUs on ABORT TASK
Currently the iscsi_task_mgmt_abort_task_[a]sync() functions cancel any
queued or dispatched (awaiting response) PDUs prior to transmitting the
ABORT TASK TMF request, which means that a TMF request may be sent which
references a PDU that the target never received.

Bug: https://github.com/sahlberg/libiscsi/issues/192

Signed-off-by: David Disseldorp <ddiss@suse.de>
2016-03-22 21:12:09 +01:00
Ronnie Sahlberg
0f886b7d3a TaskMgmt: Remove null pointer check
We do not need to check the pointer for null here since it is guaranteed
to never be.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-20 14:36:32 -08:00
Ronnie Sahlberg
99a5f99527 Add some emacs defaults. Tabs are 8 spaces.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-18 21:34:43 -08:00
Ronnie Sahlberg
02fd6217cb Add support for WRITE_ATOMIC_16
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-08 10:16:57 -07:00
Ronnie Sahlberg
0630aa5ef0 Timeouts: Fix bugs in scsi task timeout code
Add a test to verify the pdu timeout handling.
Fix numerous bugs in the timeout handling. It was really broken.

Add test for non-SCSI task PDUs too and verify they works.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-24 14:34:06 -07:00
Peter Lieven
e219f1bb97 utils/examples: avoid busy waiting on wait for reconnect
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 10:26:28 +02:00
Peter Lieven
a8b33cefac drop iscsi->is_reconnecting
iscsi->is_reconnecting != 0 is equal to iscsi->old_iscsi != NULL.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 10:13:36 +02:00
Peter Lieven
8398059635 sync: add iscsi_reconnect_sync
This function represents the old sync reconnect behaviour.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-31 16:33:36 +02:00
Ronnie Sahlberg
fd38ff4bfc Add MODESENSE6/10 and MODESELECT6/10 support 2013-07-20 14:05:20 -07:00
Ronnie Sahlberg
7895fb700c Add MODESELECT6 support
Add support for MODESELECT6 and add marshalling functions for the
mode pages we support so far.
2013-07-06 16:11:17 -07:00
Ronnie Sahlberg
92b987de52 Add helpers for the SANITIZE service actions 2013-05-26 10:51:19 -07:00
Ronnie Sahlberg
eebd04e613 Add initial support for SANITIZE and a simple test to generate this opcode. 2013-05-25 16:02:02 -07:00
Ronnie Sahlberg
ce4623b2fb READ SUPPORTED OPCODES. Update the signature to allow setting all of the
parameters to this command.
2013-05-18 12:34:03 -07:00
Ronnie Sahlberg
4a8d967541 Add support for synchronous command timeout.
Default to 0 meaning no timeout.

Implement a test for iSCS to test what happens if we send a command
with CMDSN being higher than the target allows.
In this case we dont strictly know what will happen, just that what should
NOT happen is the target responding with success.
But we have to be prepared for any kind of failure, including a timeout,
scsi sense, or even iscsi reject or session failure.
2013-04-29 20:42:33 -07:00
Ronnie Sahlberg
e640fa3cde missing , broke compile 2013-04-22 18:28:20 -07:00
Ronnie Sahlberg
402653b9f3 portability updates
add check if ipv6/sockaddr_in6 is availavble or not
add check for poll.h and only include when available
add includes for AROS
2013-04-18 19:43:36 -07:00
Ronnie Sahlberg
fbf58ead9f TESTS: When task management functions fail, print the reason why it failed. 2013-03-27 17:25:47 -07:00
Ronnie Sahlberg
aac7ed29b8 SYNC Task mgmt functions. Return !0 status if the command completed successfully
but the target responded with non-zero response code.
2013-03-26 17:38:47 -07:00
Ronnie Sahlberg
0d5c8a4f11 TESTS: Add test for PREVENTALLOWMEDIUMREMOVAL are cleared on lun/target reset 2013-03-03 13:37:52 -08:00
Ronnie Sahlberg
0f73f062d2 SCSI: remove LBDATA/PBDATA from the WriteSame10/16 signatures
Make LBA the third argument to the iscsi writesame functions
2013-01-21 21:15:37 -08:00
Ronnie Sahlberg
2a74fc00bc Initial support for PERSISTENT_RESERVER_OUT and add a simple test to show the api 2012-12-17 21:25:46 -08:00
Ronnie Sahlberg
c60093eafe Add support for PERSISTENT_RESERVE_IN and add a simple test for READ_KEYS 2012-12-17 19:01:50 -08:00
Peter Lieven
30804507f9 SYNC set status to -1 on error in event_loop
If there is an error in iscsi_service or on poll we
exit the event_loop. But in this case scsi_sync_cb is
never reached and the status is 0. This will make
the caller think that the sync task has been completed
successfully.
2012-11-18 14:00:31 -08:00
Peter Lieven
577d37c5ed RECONNECT exit from sync event_loop in case of an error
If there is an error during reconnect we should not loop in event_loop
as this will cause a deadlock in case there is actually an error like
connection drop etc. If this reconnect fails the reconnect routine
will retry itself.
2012-11-18 13:59:53 -08:00
Jon Grimm
b81bdd3932 Merge with upstream 2012-10-25 12:56:26 -05:00
Jon Grimm
1eaca70a52 Add MaintenanceIn: Report Supported Opcodes (all) and testcase. 2012-10-25 12:48:37 -05:00
Peter Lieven
20cf2b279e Fix incorrect whitespaces
At a few places there where spaces where tabulators where appropriate
2012-10-20 19:08:57 +02:00
Jon Grimm
c7d8d2593c Add RESERVE6/RELEASE6 Support. 2012-09-27 12:45:06 -05:00
Jon Grimm
e55ec72f36 Add Read TOC (0x43) Command Support (and basic testcase). 2012-09-24 10:15:00 -05:00