Commit Graph

65 Commits

Author SHA1 Message Date
Ronnie Sahlberg
f6d57ef3b0 connect.c: remove UA whitelist and just consume up to 10 UAs before failing
Lets not use a whitelist of UnitAttentions that we consume during the connect
phase. Instead we can just loop and fail after the 10th.
If there are more than 10 UAs then we have a problem, otherwise
just consume them all, forget them  and then pass control back to the caller.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-23 17:23:27 -07: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
e59c336450 Use <ptr> == NULL instead of !<ptr> 2013-11-05 17:53:10 -08:00
Paolo Bonzini
1acce4a948 log failures (typically malloc) of iscsi_create_context during reconnect
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Paolo Bonzini
c3e8d0c945 reconnect: do not initialize iscsi to old_iscsi, use old_iscsi if appropriate
Makes it clearer that logging has to be done on the existing context,
since the "iscsi" pointer will not survive iscsi_reconnect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Ronnie Sahlberg
eec84c2805 Add PowerOnOccured as a sense code we allow and ignore during connect 2013-10-05 17:06:21 -07:00
Ronnie Sahlberg
720e426c92 Always declare variables at the start of a new scope. 2013-10-05 13:43:10 -07:00
Bart Van Assche
4653cd8df4 iscsi_reconnect: Fix a use-after-free
This patch fixes the following Valgrind complaint:

Invalid read of size 4
   at 0x524A858: iscsi_reconnect (connect.c:378)
   by 0x5258794: iscsi_service (socket.c:707)
   by 0x52599C4: event_loop (sync.c:67)
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
   by 0x403171: main (iscsi-test-cu.c:1258)
 Address 0x6443958 is 3,032 bytes inside a block of size 4,120 free'd
   at 0x4C2B83A: free (vg_replace_malloc.c:468)
   by 0x524A846: iscsi_reconnect (connect.c:374)
   by 0x5258794: iscsi_service (socket.c:707)
   by 0x52599C4: event_loop (sync.c:67)
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
   by 0x403171: main (iscsi-test-cu.c:1258)

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2013-10-01 06:24:07 -07:00
Ronnie Sahlberg
766d92221c Reconnect: recalculate the header digest when we re-queue after a reconnect 2013-09-26 18:26:29 -07: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
49698e0322 Dont fail the login just because a sanitize is in progress 2013-07-21 14:04:41 -07:00
Bart Van Assche
49d1145a10 Next to BUS RESET, also accept NEXUS LOSS unit attention after login
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2013-06-08 07:44:43 -07:00
Ronnie Sahlberg
d5c5fb83af We should still be able to login even if the device is reserved.
TESTUNITREADY returning reservation conflict is no reason to fail the login
2013-03-21 19:26:55 -07:00
Peter Lieven
5a94d5d73a fix leak of iscsi_context in iscsi_reconnect
in case the maximum number of reconnects is limited with
iscsi_set_reconnect_max_retries() the an iscsi_context
is leaked if the limit is exhausted.

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-03-11 08:51:18 +01:00
Peter Lieven
327b51ed5b do not reconnect if reconnect is already defered
If the amount of reconnects is limited with iscsi_set_reconnect_max_retries()
it might happen that iscsi_reconnect is called while there is already a deferred
reconnect.

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-03-11 08:44:11 +01:00
Peter Lieven
7e46a5a337 RECONNECT fix lost allocation on reconnect.
Signed-off-by: Peter Lieven <pl@kamp.de>
2013-01-28 09:31:13 +01:00
Peter Lieven
154760a00e RECONNECT remove redundant requeue code
We first merge waitpdu and outqueue queues and then requeue
the elements. iscsi_add_to_outqueue() will sort them accordingly
so this is no problem.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-12-06 10:42:23 +01:00
Peter Lieven
5f18c72706 RECONNCT fix broken reconnect for iov out vectors
We where modifying out_offset and out_len in iscsi_write_to_socket().
If the packet that was being sent before reconnect was a write command
the was a significant change that out_offset and out_len where already
touched. When requeing the packet after reconnect we where
sending garbage!

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-12-06 10:42:16 +01:00
Ronnie Sahlberg
d1344a666b Merge pull request #53 from plieven/reconnect_on_login_error
RECONNECT add option to limit the number of reconnect retries
2012-12-04 19:16:44 -08:00
Ronnie Sahlberg
22797e0f67 NOPs should not be requeued when reconnecting a session.
Just like DATA_OUT we should just discard NOPs instead of requeueing them
on session reconnect.
Add new flag that to indicate this behaviour on reconnect and set it for
both data out and nops
2012-12-04 19:07:49 -08:00
Peter Lieven
ee83c7ce75 RECONNECT add option to limit the number of reconnect retries
In specific situation it might be useful to give up if a reconnect
is not successful or after a given number reconnect retries.
This patch adds the ability to change that. The default remains
the same: retry forever.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-12-04 13:38:50 +01:00
Peter Lieven
14bee1007f RECONNECT do not increase CmdSN for immediate PDUs
Immediate PDUs such as queued NOP-Outs will cause
a protocol error on reconnect.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-29 15:17:30 +01:00
Peter Lieven
562dd46833 PDU avoid incrementing itt to 0xffffffff
This patch avoid incrementing itt to 0xffffffff which is
a reserved value for immediate pdus. Avoid incrementing
it to 0xfffffff to avoid unexpected behaviour.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 10:58:33 +01:00
Ronnie Sahlberg
700d363a88 Create a wrapper function for when we add pdus to the out queue
so that we can add them so that they are send in increasing itt order.
2012-11-27 20:26:13 -08:00
Peter Lieven
a75727d989 RECONNECT avoid deadlock on reconnect retry timeout
If there is a clock jump e.g. due to daylight saving time
the wait can be almost infinite
2012-11-18 14:03:13 -08:00
Peter Lieven
328755fb68 CONNECT add further debug output regardint login and reconnect 2012-11-18 14:02:29 -08:00
Peter Lieven
00baa9bd6c CONNECT fixed memleak in case iscsi_connect_async fails directly 2012-11-18 13:57:02 -08:00
Peter Lieven
8cb369b87f Merge remote-tracking branch 'upstream-git/master'
Conflicts:
	include/iscsi-private.h
	include/iscsi.h
	lib/connect.c
	lib/init.c
	lib/scsi-lowlevel.c
2012-11-12 16:02:57 +01:00
Peter Lieven
144026a7bd RECONNECT allow a consecutive reconnect only every 5 seconds
In case there is an error condition e.g. out of memory. We are heavily
disconnecting and reconnecting without any limit. This patch
adds a 5 seconds period that has to go by between 2 reconnects.
2012-11-08 16:56:44 +01:00
Ronnie Sahlberg
50e7c682bb Add a logging subsystem and change all DPRINTF to ISCSI_LOG
Add a mechanism where we can set a logging subsystem that libiscsi can use.
Create an example 'log to stderr' that utilities can use for convenience.
2012-11-07 06:34:38 -08:00
Peter Lieven
3e57a612db SOCKET add more skill to interface binding
If a process opens more than once connection the interfaces are assigned
round-robin from the available ones. However, different processes will
uses a random interface of as starting point. This patch will also
make the redirect case handled correctly.
2012-11-06 15:47:30 +01:00
Peter Lieven
a6caad107c INIT zero out sensitive data before its freed
The iscsi_url and iscsi_context might contain clear text
login credentials for an iscsi target. As Linux zeroes
on allocate this data might remain in memory for a long
time.
2012-11-03 02:12:46 +01:00
Peter Lieven
871c56ce7a MEMORY add compatibility for qemu-kvm
qemu-kvm iscsi block driver calls iscsi_parse_full_url without
a valid iscsi_context. The driver also creates its own scsi_task
objects.
2012-11-03 02:05:16 +01:00
Peter Lieven
d327ab09c6 MEMORY add wrappers around all mallocs and frees and trace them
This patch adds a wrapper around all memory allocations and frees.
The idea is to get warned immediately if the application leaks memory.
Additionally the wrapper functions make it easy to add different
memory allocators or memory pools in the future.
2012-11-03 01:05:57 +01:00
Peter Lieven
2e30d7aafb CONNECT correctly free ct in case first testunitready fails 2012-10-29 21:37:39 +01:00
Peter Lieven
923b9a4fb2 ISCSI-CONTEXT change dynamic string allocations to statics 2012-10-27 17:23:40 +02:00
Peter Lieven
0906109d8a CONNECT fix mem leak of connection_task object 2012-10-27 16:31:56 +02:00
Peter Lieven
4785dd9933 CONNECT do not reseed RNG in iscsi_reconnect 2012-10-26 20:47:35 +02:00
Peter Lieven
0b4424cca0 CONNECT Fix memory leak in iscsi_reconnect 2012-10-26 20:47:15 +02:00
Ronnie Sahlberg
97dcf94d72 iSCSI: when reconnecting we should not automatically requeue any DATA-OUT PDUs
Dont requeue data-out pdus, or other pdus with the DELETE_WHEN_SENT flag, such
as nops.
These, like the DATA-OUT pdu will instead be automatically re-sent when the original write command is sent again.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2012-10-24 19:32:00 -07:00
Peter Lieven
6e82c48185 RECONNECT fix read from freed iscsi context 2012-10-23 10:55:04 +02: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
Peter Lieven
78a31ad4a1 Add iscsi_set_tcp_syncnt function
This patch adds support for setting TCP_SYNCNT to overwrite
the system default values. This allows indirect support
for a configurable connect timeout.

Linux uses a exponential backoff for SYN retries starting
with 1 second.

This means for a value n for TCP_SYNCNT, the connect will
effectively timeout after 2^(n+1)-1 seconds.
2012-10-20 18:43:48 +02:00
Peter Lieven
236aaa011f Fix compiler warnings
These patch fixes 3 compiler warnings introduce by my recent patches.
2012-10-19 23:48:04 +02:00
Peter Lieven
ad9cd56b2d Add setters for TCP keepalive values
This patch adds 3 functions to set the 3 keepalive values TCP_KEEPIDLE, TCP_KEEPCNT
and TCP_KEEPINTVL. The values have to be set after iscsi context creation and are
then configured on the socket on each new connection.
2012-10-19 23:40:12 +02:00
Ronnie Sahlberg
abd20f3587 Use the literal ISCSI_STATUS_REDIRECT instead of the numeric value 2012-10-18 20:03:58 -07:00
Peter Lieven
326b2ea49d Add backoff mechanism to iscsi_reconnect
This patch adds a linear backoff mechanishm + jitter in case
a reconnect fails. If there is a longer outage this is to
avoid a large amount of simultaneous connects to the storage.
2012-10-18 12:18:40 +02:00
Peter Lieven
f973608578 Add iscsi_tcp_set_user_timeout function
This patch adds a user configurable option to set the TCP_USER_TIMEOUT
socket option. With this timeout set a broken TCP session is shutdown
after a given timeout even there are unacked packets. SO_KEEPALIVE
seems not to work in this case.
2012-10-18 11:55:15 +02:00