Commit Graph

628 Commits

Author SHA1 Message Date
Roy Shterman
bc64420bad Libiscsi: Changing header iscsi_in_pdu
socket: need to malloc hdr

include/iscsi-private: changing iscsi_in_pdu hdr to char*
		       instead of static array for more convinient iser
		       pdu creation.

To use iscsi_in_pdu in iSER without making a copy of it
we need to change hdr to pointer from static array,
Because of that, iscsi_tcp flow need to do szmalloc (small zero malloc)
hdr when creating new iscsi_in_pdu. iscsi_in_pdu is being malloced
once per each received pdu. This change is reducing iscsi_in_pdu struct
size but adding extra allocation of the same size we reduced
from the struct.

Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:46:18 -07:00
Roy Shterman
2671e10565 Libiscsi: Adding new_pdu function to transport abstraction
Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:45:44 -07:00
Roy Shterman
e3df0bbf96 Libiscsi: Adding queue pdu function to transport abstraction
include/iscsi-private: adding queue_pdu in transport function pointers
                       struct
include/iscsi: declaration of tcp_queue_pdu function

socket: adding queue_pdu function to transport initialization

all_library: changing iscsi_queue_pdu into iscsi->t->queue_pdu

Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:44:51 -07:00
Roy Shterman
0d6362ffe6 Libiscsi: Adding connect function to transport abstraction
socket: adding tcp_connect function and implement it
	in the last common part of iSER and TCP in iscsi_connect_async

Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:43:46 -07:00
Roy Shterman
9378a39ddc Libiscsi: Adding transport layer into all library utilities
lib/init: initializing connection transport

lib/socket: Adding function to initialize tcp transport.
            future commits will include adding iSER transport layer,
            so each transport option will has it's own template of functions.

all_utils: All utils stay the same, in future iSER commits in case of
	   iSER transport we will override tcp_transport in
	   iscsi_context.

connect: adding transport initialization when creating context

include/iscsi-private: Adding iscsi_transport attribute in iscsi_context

Signed-off-by: Roy Shterman <roysh@mellanox.com>

Make iscsi_init_tcp_transport private

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-06-03 18:43:03 -07:00
Ronnie Sahlberg
8da7b8df3e New version 1.17.0
This release contains a bugfix for a rare condition where
if a DATA-OUT PDU has a callback registered, it can cause a crash
on reconnect/timeout.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-05-08 12:37:59 -07:00
Peter Lieven
423b82efa4 pdu: check callback for NULL everywhere
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-02 13:55:13 +02:00
Peter Lieven
cde2043891 pdu: drop ISCSI_PDU_NO_CALLBACK
we use the flag ISCSI_PDU_NO_CALLBACK and pdu->callback simultaneously, but
check only for one of them in various places. So drop ISCSI_PDU_NO_CALLBACK
and check for pdu->callback != NULL instead.

All PDUs that carried this flag have pdu->callback set to NULL.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-02 10:40:15 +02:00
Peter Lieven
03fe4d73f7 iscsi-command: DATA OUT PDUs must have no callback
otherwise we might invoke a cmd_pdu callback multiple times
on timeout or reconnect.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-02 10:08:01 +02:00
Ronnie Sahlberg
a6fc65b4ef Tests: remove the warning if a SSD supports SANITIZE/OVERWRITE
There is technically no reason why a SSD with (assumingly with thin
provisioning) can not support SANITIZE/OVERWRITE instead or or in addition
to the more expected SANITIZE/BLOCK-ERASE so remove the warning for this.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-05-01 12:35:29 -07:00
Ronnie Sahlberg
2bba2fedf9 Merge pull request #197 from bonzini/libiscsi-20160330
Fix iscsi-ls for IPv6 link-local addresses, and bump ABI version again
2016-03-30 19:25:48 -07:00
Jakob van Kruijssen
7d2e9ec708 Fix sending to many headers after completing CHAP auth.
TODO: see if this breaks something else.
2016-03-30 19:21:25 -07:00
Jakob van Kruijssen
81a7610155 Fix CHAP challange not being fully read and hashed. 2016-03-30 19:21:12 -07:00
Paolo Bonzini
edc5a80857 bump ABI version again
Commit 80b81772e2 again broke
the libiscsi ABI.  Bump the soname of the library.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-30 18:07:29 +02:00
David Disseldorp
f117b6c96d socket: add iscsi_out_queue_length() function
This function allows the caller to determine the number of PDUs queued
for transmission for a given iscsi context.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2016-03-22 21:19:51 +01: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
Peter Lieven
a7c94a7af5 connect: invoke all callbacks for dropped PDUs
if we drop a PDU which has a callback we should invoke it otherwise
the caller may wait infinetely for a command completion.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-03-17 12:08:26 +01:00
Peter Lieven
97406c5b36 Revert "Fail pending LOGOUT commands on session reconnect"
This seriously breaks qemu NOP timeouts and probably other things.
The reason is that the

define ISCSI_PDU_ERROR_ON_RECONNECT	0x00000016

is masking bits 0x2 and 0x4 as well.

Correctly it should read:
define ISCSI_PDU_ERROR_ON_RECONNECT	0x00000010

However, the better solution for this approach is invoke all callbacks
of PDUs which carry the ISCSI_PDU_DROP_ON_RECONNECT flag. This will
make sure that callbacks of whatever sync tasks are invoked.

This reverts commit 0407cf6aed.
2016-03-17 12:08:20 +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
b240bf1a2c Don't free() things allicated through scsi_malloc()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-20 14:27:52 -08:00
Ronnie Sahlberg
0629d44e83 Remove C99 style variable declarations
Make it slightly more portable and move the declarations to the start of the
function.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-18 21:50:35 -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
Sitsofe Wheeler
6ea30f9fb2 socket: Simplify SOL_TCP check
Rather than checking for the names of OSes that don't implement it
just check whether the define is available directly.
2016-01-30 08:12:28 +00:00
Sitsofe Wheeler
4714e12e8f socket: Use alternatives if MSG_NOSIGNAL is unavailable
Only Linux has MSG_NOSIGNAL as a socket flag (see
http://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly
) which makes compilation fail on other OSes. The BSDs and OS X have
SO_NOSIGPIPE which implements the same thing but others like
Solaris don't even have that (see
http://stackoverflow.com/questions/2205455/detecting-broken-pipe-in-solaris-send-call
)...

Work around this by checking using MSG_NOSIGNAL or SO_NOSIGPIPE if
available otherwise don't set anything at all so we at least continue
to compile.
2016-01-30 07:50:50 +00:00
Ronnie Sahlberg
7b8363827b libiscsi: Fix RECEIVE COPY RESULTS response unmarshalling
Allocate the correct amount of memory for the scsi_copy_results_copy_status
and scsi_copy_results_op_params structures.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-12-24 10:36:04 -08:00
Ronnie Sahlberg
0407cf6aed Fail pending LOGOUT commands on session reconnect
Certain iSCSI commands such as NOP and LOGOUT commands are discarded instead
of re-queued when we have a session failure and reconnect.
Change the LOGOUT command to instead fail with SCSI_STATUS_ERROR when this
happens.

Otherwise, IF we are in iscsi_logout_sync() and we get a session failure
at the same-ish time we may end up automatically re-connecting the
session, but since we have discarded the logout command we will never
get a reply and will hang indefinitely in the event loop for synchronous
commands.
Arguably, we could also just return SCSI_STATUS_GOOD here since
when we perform a logout, we probably don't care too much about how we
disconnected from the server, only that we did disconnect from the server.
That is academic anyway since this only affects the sync API which is only
meant for trivial applications, which will likely not inspect the result
and just do a:
...
iscsi_logout_sync()
iscsi_destroy_context()
...
anyway.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-15 21:17:50 -08:00
Ronnie Sahlberg
70391b6449 Typo
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-15 19:09:08 -08:00
Ronnie Sahlberg
916fef6c03 Allow sending TUR to consume all UAs during reconnect
During reconnect we normally defer any SCSI commands that are issued
to be queued and sent later, once the re-connect has completed and we have
swapped the contexts.
This is what we want for almost all situations, except when we are
reconnecting very simple applications which request "no ua on reconnect".
For these applications we want to actually send the TURs that are used
during the login phase on the temporary context.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-15 19:05:55 -08:00
Ronnie Sahlberg
3c44092635 Add a feature to request transparent reconnects without any UA
Normal applications want the current behaviour where we have the library
consume any/all of the UnitAttentions that the target may have queued on the
initial connection, but when we reconnect the session after a failure the
library will pass all the UAs back to the application to process.

Some applications, such as the test suite or really trivial applications
might not want to have to deal with handling of UAs and just "make it work".
Those applications can now request that upon any reconnection of the session
that libiscsi will automatically consume any and all UAs and hide them from
the application.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-13 14:29:32 -08:00
Ronnie Sahlberg
74fc637eeb Use MSG_NOSIGNAL with send()
If the server closes the TCP connection before we call send() in
iscsi_write_to_socket() we will get SIGPIPE unless we pass this
argument to send.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-06 12:12:49 -08:00
Bart Van Assche
608dbcba12 scsi-lowlevel.c: Use sizeof() instead of a hardcoded constant
This patch does not change any functionality.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-10-07 07:42:30 -07:00
David Disseldorp
ef8e59a24d lib/scsi: fix PRin REPORT CAPS allow_cmds unmarshalling
The Persistent Reserve In REPORT CAPABILITIES response carries the
ALLOW COMMANDS field in bits 4-6 at byte offset 3.
Bit 7 (TMV) should be masked out during ALLOW COMMANDS unmarshalling.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2015-09-30 11:00:13 +02:00
Ronnie Sahlberg
80b81772e2 Add unmarshalling of VPD BLock Limits settings for atomic writes
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-09 06:49:41 -07:00
Ronnie Sahlberg
6c16f9e322 Add tests for WRITE_ATOMIC_16
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-08 10:17:15 -07: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
a6f7c06119 Add support and tests for ExtendedCopy and ReceiveCopyResults
From sushma.gurram@sandisk.com
Add support to libiscsi and tests for these two opcodes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-08-02 12:57:21 -07:00
Ronnie Sahlberg
96c00b2178 New version 1.15.0
- Replace some u_int32_t with uint32_t
- Portability fixes to iscsi-perf
- Improved documentation for the tests in README
- Add/fix support for setting task/pdu timeouts and add unit tests for it.
- Add multipath helpers for the test suite and add a simple multipath test
- Skip sending TUR during reconnect, since it can cause the connection to
-   hang.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-06-21 08:50:50 -07:00
Peter Lieven
1ceb216394 pdu: timed out pdus might have no callback
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:14:11 +02:00
Peter Lieven
85fc823f59 pdu: do not leak timed out pdus
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:08:13 +02:00
Peter Lieven
7dd62aca61 pdu: add more debugging info for timed out commands
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:06:59 +02:00
Peter Lieven
0a3e157844 reconnect: copy scsi_timeout on reconnect
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 11:33:57 +02: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
Ronnie Sahlberg
cb4ad5f774 Connect: Don't use the TUR checks on re-connects
Only use TUR to eat any pending unit attentions on the initial connect
but not during reconnect.

From Peter Lieven <pl@kamp.de>

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-19 19:21:26 -07:00
Ronnie Sahlberg
45f667739c login.c: use uint32_t instead of u_int32_t
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-10 10:55:18 -07:00
Ronnie Sahlberg
dfeefd6539 New version 1.14.0
- Add support to use /dev/* nodes instead of just iscsi devices.
 - Create a dedicated test for the FUA/DPO flags
 - Allow reusing the context after disconnect
 - Fix non-randomness in rand_key()
 - Add iscsi-perf tool
 - Fix length bug when sending unsolicited data in iscsi_command
 - Reqrite the reconnect logic to begome fully async
 - Fix wrong checks for username in CHAP
 - Support Bidirectional CHAP
 - Improve handling of IMMEDIATE bit
 - Cmdsn, statsn fixes+
 - iscsi_which_events can return 0, which means that there are no events right
   now but try again in a second or so.
 - Ignore any ASYNC EVENTS we receive since we can not yet pass them back to
   the application.
 - Add initial make test support
 - Various minor fixes to libiscsi and the test suite

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-10 09:14:11 -07:00
Peter Lieven
6aa47691ce pdu: add known execptions to target serial processing
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-08 12:47:34 +02:00
Peter Lieven
a027931a2c init: simplify the case that the freelist is full in iscsi_sfree
if the freelist gets full we are likely in a low load situation so
we do not need to make all the work copying the pointers.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 14:14:26 +02:00
Peter Lieven
b4098c535e init: make LIBISCSI_CACHE_ALLOCATIONS a public environment variable
this variable was introduced for iscsi-test-cu only. This patch
makes it a generic environment variable that can be set per context.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 14:10:44 +02:00
Peter Lieven
724f44c31b socket: change the order of POLLIN and POLLOUT in iscsi_service
the original idea of writing to the socket before reading was to put data
on the wire as early as possible and avoid potential latency increase due
to long taking callbacks invoked in iscsi_read_from_socket.

Benchmarking with libiscsi userland tools have shown that changing the
order increases throughput by about 5%.
The reason is that during POLLIN we might receive an updated MaxCmdSN
which might us allow to send new data out during POLLOUT.

For Qemu the change doesn't matter since POLLIN and POLLOUT are processed
independently.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 13:57:10 +02:00
Peter Lieven
e9d67540e1 add LIBISCSI_IGNORE_NOP_OUT_ON_STUCK_WAITPDU_QUEUE environment variable
this variable is a helper to tell libiscsi to not reset the nops_in_flight
on receival of a NOP-Out if the oldest element in the waitpdu queue is
not changed since the last NOP-Out.

The idea is that we can detect a command that the target silently dropped
by this mechanism and run into a NOP timeout forcing a reconnect.

This environment variable is not suitable if a command is send that is taking more than
the allowed timeout for a NOP-Out as a reply to a initiator generated NOP-In
(or several NOP-Outs if more than 1 in flight is allowed).

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 13:54:22 +02:00