Commit Graph

129 Commits

Author SHA1 Message Date
Peter Lieven
812d55d343 socket: do not show misleading disconnect message if we are not actually logged in
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-16 11:58:28 +02:00
Peter Lieven
913b2ab708 reconnect: avoid deadlock if socker error is received during reconnect
If we are reconnecting and the connection is already established we
end up looping forever if there is a socket error before we finish
the login process. Fix this by invoking the reconnect callback if
there is an error and no new reconnect is scheduled.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 12:11:03 +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
a3e5c4d3c5 socket: allow iscsi_which_events to return 0
this is meant as a hint that there can be no event at the moment
and in this special case iscsi_service will return immediately.
We use this at the moment in the case of a wait for a reconnect
in which case we would enter a busy loop waiting for that
reconnect. The 0 means do not poll for the client application.
Do not poll, just wait a little (a few hundred ms) and call iscsi_which_events
again. The wait should be timer driven or at least non busy looping,
of course.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-02 08:34:52 +02:00
Peter Lieven
b7cb8fbf5a iscsi_service: dont return if a reconnect is pending but not yet reconnecting
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-02 08:31:53 +02:00
Peter Lieven
b152d26eb9 connect: make the reconnect async
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-31 16:21:00 +02:00
Peter Lieven
153e6ba07c pdu: set pdu->cmdsn when the pdu structure is updated
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-30 12:32:03 +02:00
Peter Lieven
37f908bb8a socket: set expstatsn when we put the PDU on the wire
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-30 08:44:50 +02:00
Peter Lieven
47e2b8918e socket: Data-Out PDUs may carry a CmdSN < ExpCmdSN
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-27 22:21:51 +01:00
Peter Lieven
cb6667a5dc drop ISCSI_PDU_URGENT_DELIVERY
its not needed anymore

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 17:00:20 +01:00
Peter Lieven
2a57cea180 socket: queue immediate PDUs at front of outqueue
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 16:51:18 +01:00
Peter Lieven
b76c8a703e socket: honour ISCSI_PDU_IMMEDIATE in iscsi_which_events
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 16:45:03 +01:00
Peter Lieven
33c301335b socket: check if expcmdsn is not greater than pdus cmdsn
this is just another sanity check.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 12:27:48 +01:00
Peter Lieven
21cb9a9014 debug: add NOP Out and stalled outqueue debug messages
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 12:18:29 +01:00
Peter Lieven
4ce740f737 socket: fix bounds check in iscsi_iovector_readv_writev
if we received too little iovectors niov++ may also
make iov2 point to uninitialized memory.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 11:42:53 +01:00
Ronnie Sahlberg
2f94f16d02 iovectors: don't reset nalloc when resetting an iovector
Don't reset nalloc when resetting an iovector during reconnect.
Resetting offset/consumed should be sufficient.

Also, don't reset the iovectors when we detect an error condition in
iscsi_iovector_readv_writev. If there is a bug feeding an invalid
pos into this function, where pos suddently points before the amount
of data we have already read/written, then singlan this as an error
and return -EINVAL.

Previosly we did not reset the iovectors correctly when we re-queued
PDUs after a reconnect and thus relied on the iovectors being automatically
reset if/when we detected this type of error in readv_writev.
Now we do reset the iovectors properly so we do nt need to atuo reset them
here anymore and we can change this check to test for and abort the transfer
if an error is detected.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-03-22 08:20:29 -07:00
Ronnie Sahlberg
7dc0ea200d socket.c: allow re-using a context after disconnect
From Adam Endrodi <adam.endrodi@nsn.com>
Fix a bug and clear is_corked during socket disconnect so that we
can re-use the context for a new connection.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-09 15:13:58 -08:00
Mike Cui
2284a8763c set_tcp_* functions should be static since they are not used anywhere else.
set_tcp_sockopt in particular conflicts with libnfs's function of the same
name and prevents a a program from statically linking against both libnfs and
libiscsi.

Similar fix should also go into libnfs.
2015-01-05 09:24:01 -08:00
Bart Van Assche
161547d5b6 lib/socket.c: Fix a use-after-free
This issue was introduced via patch "pdu: introduce ISCSI_PDU_CORK_WHEN_SENT"
on June 13, 2014 (commit 99585b6996).

Valgrind reported this use-after-free as follows:

Invalid read of size 4
   at 0x5267606: iscsi_write_to_socket (socket.c:721)
   by 0x5267A72: iscsi_service (socket.c:823)
   by 0x526827C: event_loop (sync.c:67)
   by 0x52698A4: iscsi_compareandwrite_sync (sync.c:823)
   by 0x408111: compareandwrite (iscsi-support.c:1752)
   by 0x4139E2: test_compareandwrite_simple (test_compareandwrite_simple.c:88)
   by 0x503D260: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D578: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D8B5: CU_run_all_tests (in /usr/lib64/libcunit.so.1.0.1)
   by 0x4046C6: main (iscsi-test-cu.c:1241)
 Address 0x639f258 is 8 bytes inside a block of size 256 free'd
   at 0x4C291E7: free (vg_replace_malloc.c:473)
   by 0x525321B: iscsi_free (init.c:68)
   by 0x52532F0: iscsi_sfree (init.c:110)
   by 0x5257AD9: iscsi_free_pdu (pdu.c:179)
   by 0x5267601: iscsi_write_to_socket (socket.c:719)
   by 0x5267A72: iscsi_service (socket.c:823)
   by 0x526827C: event_loop (sync.c:67)
   by 0x52698A4: iscsi_compareandwrite_sync (sync.c:823)
   by 0x408111: compareandwrite (iscsi-support.c:1752)
   by 0x4139E2: test_compareandwrite_simple (test_compareandwrite_simple.c:88)
   by 0x503D260: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D578: ??? (in /usr/lib64/libcunit.so.1.0.1)

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Peter Lieven <pl@kamp.de>
2014-09-18 11:57:05 -07:00
Ronnie Sahlberg
f0ebbdc203 Merge pull request #128 from plieven/revert_iovector
socket: rename max_read parameter to count in iscsi_iovector_readv_write...
2014-07-14 06:24:05 -07:00
Peter Lieven
53e38dff7d socket: rename max_read parameter to count in iscsi_iovector_readv_writev
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 15:05:19 +02:00
Ronnie Sahlberg
a0d09ca9de Merge pull request #127 from plieven/revert_iovector
Revert "Rewrite and simplify iscsi_iovector_readv_writev"
2014-07-14 05:56:12 -07:00
Peter Lieven
59e4a07129 Revert "Rewrite and simplify iscsi_iovector_readv_writev"
Since writing headers and payload in a single iov has never been
implementend and after thinking about it several times seems to
be very hairy I would like to revert this change since
the original implementation is in O(1) while the changed one
is in O(n). This results in a complexity of O(n^2) instead of
O(n) for the whole send operation.

This reverts commit 06eab264f6.
2014-07-14 08:05:32 +02:00
Peter Lieven
4b3f4b5822 iscsi_which_events: do not set POLLOUT if context is corked
if the socket is corked we otherwise set POLLOUT and then
do not sent. Depending on the event loop implementation this
can result in a busy wait.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 08:02:24 +02:00
Peter Lieven
81921e3762 pdu: handle async target requests logout events
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:52:27 +02:00
Peter Lieven
98bbeab664 pdu: introduce ISCSI_PDU_URGENT_DELIVERY
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:50:41 +02:00
Peter Lieven
99585b6996 pdu: introduce ISCSI_PDU_CORK_WHEN_SENT
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:08 +02:00
Peter Lieven
5d55d32adb socket: do not stop sending for immediate PDUs
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:00 +02:00
Ronnie Sahlberg
717b95cb8a slist.h: rename SLIST_ to ISCSI_LIST_ to avoid clash on *BSD
Rename the macros for managing the linked lists from SLIST_* to ISCSI_LIST_*
to avoid a clash on *BSD which already have other macros SLIST_*

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-05-07 06:44:19 -07:00
Michael Tokarev
120b308741 Spelling fixes: Dont => Don't
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2013-12-16 18:19:24 -08:00
Ronnie Sahlberg
78e49f1427 Coding style update 2013-11-05 17:59:55 -08:00
Paolo Bonzini
bb0e59055a handle bad iscsi->fd in iscsi_service
Just do nothing if the file descriptor is invalid.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:31:16 +01:00
Edward Tomasz Napierala
dd1ca33094 Freebsd build fixes. 2013-10-13 15:35:00 +02:00
Ronnie Sahlberg
d7b7c7727a Fix win32 so it works again 2013-10-05 15:34:56 -07:00
Sitsofe Wheeler
2fda87160c Fix compilation on OS X
OS X doesn't implement SOL_TCP so workaround this the same way as on
FreeBSD/Solaris.
2013-09-09 19:38:00 +01:00
Paolo Bonzini
73b0d4777f Ignore padding when an iovector is supplied
The iSCSI protocol adds padding to a data packet if the data size is not
a multiple of four.  The iovector provided by QEMU does not include such
padding, and libiscsi then complains that there was a protocol error.
This patch fixes this by reading the padding in a separate "recv"
system call.  These packets anyway do not happen in the data path,
where the packet size is a multiple of 512.

This fixes QEMU's scsi-generic backend, which triggered the problem when
the target sent a 66-byte INQUIRY response.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-08-26 23:53:31 +02:00
Ronnie Sahlberg
dc981c93ef Cleanup: rename to payload_* the PDU variables used to track writing to socket 2013-08-04 17:34:15 -07:00
Ronnie Sahlberg
6cb88eb0ce Cleanup: rename pdu->written -> pdu->outdata_written 2013-08-04 17:27:29 -07:00
Ronnie Sahlberg
c5bd95aac9 Remove the use of TCP_CORK 2013-08-04 16:15:22 -07:00
Ronnie Sahlberg
06eab264f6 Rewrite and simplify iscsi_iovector_readv_writev 2013-08-04 14:34:57 -07:00
Ronnie Sahlberg
912b5dc495 Merge pull request #67 from plieven/small_allocations
MEMORY introduce a small allocation pool
2013-08-02 06:45:35 -07:00
Paolo Bonzini
73ce7f40c8 avoid casting struct sockaddr
On ARM, this produces a warning.  Use a union instead.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-08-02 15:06:16 +02:00
Peter Lieven
d429276907 MEMORY introduce a small allocation pool
This patch finally introduces a small allocation pool
which recycles all the small portions of memory that
are used for headers and pdu structures. This was
the initial idea behind wrapping all memory functions
in libiscsi.

The results of booting are test system up to the login
prompt are quite impressive:

BEFORE:
libiscsi:5 memory is clean at iscsi_destroy_context() after 10712 mallocs, 18 realloc(s) and 10712 free(s)

AFTER:
libiscsi:5 memory is clean at iscsi_destroy_context() after 41 mallocs, 18 realloc(s), 41 free(s) and 10584 reused small allocations

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-07-18 11:15:56 +02:00
Ronnie Sahlberg
cc02faabb0 Add TCP_CORK support when available 2013-07-10 14:14:36 -07:00
Ronnie Sahlberg
8140c5b726 Flag another argument as _U_ 2013-06-29 11:20:23 -07:00
Ronnie Sahlberg
bc7b1dc600 Add _U_ to some variables that might be unused 2013-06-29 11:14:46 -07:00
Ronnie Sahlberg
b555bbebdd Add a cast to ssize_t 2013-06-29 11:12:41 -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
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
Peter Lieven
8bc0046f51 changed iscsi_data.size from int to size_t
iscsi_data.size is used as parameter to memory
operation functions (such as malloc) which except
size_t rather than int.

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-01-28 09:36:00 +01:00