Commit Graph

72 Commits

Author SHA1 Message Date
Ronnie Sahlberg
e061cba1b9 URL encoded Targetnames
Assume target names are URL encoded with '%' as the special character.

Any sequence of '%' followed by two bytes in the target name will be replaced
with the byte that the second two bytes represent in hexadecimal.

Example
iqn.ronnie.test%3A1234
will be translated to iqn.ronnie.test:1234
2013-06-16 11:35:14 -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
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
dbe9a1e73a SOCKET queue cmd PDUs directly in waitpdu queue
A storage might sent an R2T response for a WRITE command while
we still sending out the WRITE command PDU. This is especially
the case when the command PDU carries immediata data.

Without this patch the R2T response will get lost as
the cmdpdu for the R2T cannot be found in iscsi_process_pdu()
leading to a deadlock.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-12-03 11:05:21 +01:00
Ronnie Sahlberg
56707bcdf9 Fix how we negotiate IMMEDIATE_DATA. It defaults to YES and is negotiated
unless one side said NO
2012-12-01 11:21:24 -08:00
Ronnie Sahlberg
edb0df07d6 INITIAL_R2T defaults to YES 2012-12-01 09:43:49 -08:00
Ronnie Sahlberg
276f600181 Add functions to control how IMMEDIATE_DATA and INITIAL_R2T is negotiated 2012-12-01 09:19:50 -08:00
Ronnie Sahlberg
b1da7311c4 change u_int to uint 2012-11-29 19:14:26 -08:00
Peter Lieven
e7cc6dc1ca SCSI add support for POSIX compatible iovectos
This patch defines an scsi_iovec struct which is guaranteed
to be POSIX compatible. It furthermore adds support for
in+out iovectors for bi-directional operations
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-23 15:43:00 +01:00
Peter Lieven
55f76cfb0c SCSI add support for iovectors
If an application passes buffers to libiscsi for reading they are
currently added to a linked list one by one. This leads to a malloc
for each buffer object plus O(n) walks trough the list to add
the buffer to then end of the list. Additionally the buffer read
routine takes up to O(n) iterations to find the right buffer
for a request.

This patch introduces an scsi_iovector struct to pass buffers to
an scsi task. Adding a new buffer is in O(1) and finding the
right buffer to also. Malloc requirements are in O(log(n)).

Additionally the scsi_iovector struct is itended to be binary
compatible to an QEMUIOVector allowing to pass this structure
directly to the library.

Initial tests have been made booting an Ubuntu LTS 12.04.1
Desktop server up to the login prompt. The following observations
have been made with regards to scsi_malloc calls:

original implementation:	~11.500 mallocs
using iovector instead of list:	~ 7.500 mallocs
passing the iovector directly:        0 mallocs

To enable this feature in qemu for testing the following patch might
be used:

diff --git a/block/iscsi.c b/block/iscsi.c
index a6a819d..2809c15 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -390,11 +390,16 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
         return NULL;
     }

+#if defined(LIBISCSI_FEATURE_IOVECTOR)
+    assert(sizeof(struct QEMUIOVector) == sizeof(struct scsi_iovector));
+    scsi_iovector_assign(acb->task, (struct scsi_iovector*) acb->qiov);
+#else
     for (i = 0; i < acb->qiov->niov; i++) {
         scsi_task_add_data_in_buffer(acb->task,
                 acb->qiov->iov[i].iov_len,
                 acb->qiov->iov[i].iov_base);
     }
+#endif

     iscsi_set_events(iscsilun);

---
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-21 17:02:59 +01:00
Ronnie Sahlberg
bdfa2833e5 tiny style change 2012-11-18 13:55:15 -08:00
Peter Lieven
6f3a575238 INIT check iscsi==NULL in iscsi_get_error()
qemu-kvm calls iscsi_get_error(NULL) if we specify an invalid URL
2012-11-18 13:54:07 -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
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
a97b51bbe5 Revert "DEBUG add function to set debug fd"
We will have a completely different debugging framework soon.

This reverts commit ec46d6fa43.
2012-11-07 06:45:54 +01:00
Peter Lieven
ec46d6fa43 DEBUG add function to set debug fd
DPRINTF was blindly sending all debug output to fd 2 (stderr).
The new function iscsi_set_debug_fd() will set the debug fd.
In general debugging is completely disabled by default.
2012-11-06 16:07:43 +01:00
Ronnie Sahlberg
d81bcd7b38 Dont print to stderr from _set_error if iscsi is NULL
If iscsi is NULL then just do nothing and dont log to stderr.
Our caller might have closed stderr or worse, re-used fd 2 for something else.
2012-11-06 06:20:11 -08:00
Peter Lieven
bde85a4b57 INIT allow iscsi_context = NULL in iscsi_set_error()
qemu-kvm calls iscsi_parse_url_full() with iscsi = NULL.
In case there is an invalid URL specified qemu-kvm segfaults when
it tries to set iscsi->error_string.

I tried to patch this in qemu-kvm, but the initiator_name is dirived
from the target name so this seemed to be the easier approach.
2012-11-06 06:13:17 -08:00
Peter Lieven
f00cd04810 INIT call srand() once at iscsi_create_context()
currently the rng is not seeded at all which makes the isid not really random
at all.
2012-11-06 15:01:34 +01:00
Peter Lieven
6cad82532a SOCKET add option to bind to connection to interface(s) 2012-11-06 14:53:55 +01:00
Peter Lieven
0d8819e68f INIT allow iscsi_context = NULL in iscsi_set_error()
qemu-kvm calls iscsi_parse_url_full() with iscsi = NULL.
In case there is an invalid URL specified qemu-kvm segfaults when
it tries to set iscsi->error_string.

I tried to patch this in qemu-kvm, but the initiator_name is dirived
from the target name so this seemed to be the easier approach.
2012-11-06 08:53:38 +01:00
Peter Lieven
e6553c2ef8 MEMORY account reallocs 2012-11-05 15:20:15 +01:00
Peter Lieven
36527c5122 Merge remote-tracking branch 'aredlich/master'
Conflicts:
	lib/init.c
	lib/socket.c
2012-11-03 10:39:23 +01:00
Peter Lieven
3268ae4c88 INIT fix iscsi_destroy_url 2012-11-03 02:26: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
Arne Redlich
b910efa7c5 iscsi_parse_url: fix spurious compiler warnings
gcc-4.6.3 reports these:
  libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I./include "-D_U_=__attribute__((unused))" -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -g -O2 -MT lib/init.lo -MD -MP -MF lib/.deps/init.Tpo -c lib/init.c  -fPIC -DPIC -o lib/.libs/init.o
  lib/init.c: In function 'iscsi_parse_url':
  lib/init.c:410:18: warning: 'l' may be used uninitialized in this function [-Wuninitialized]
  lib/init.c:409:10: warning: 'target' may be used uninitialized in this function [-Wuninitialized]

Both warnings appear to be spurious though, as both "target" and "l" are only used if
"full" is set, which implies that these are initialized before.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-10-31 14:34:30 +01:00
Peter Lieven
1d348de71f INIT fix typo in iscsi_parse_url() 2012-10-30 21:00:46 +01:00
Peter Lieven
a0fb2d179d ERROR fix error string creation
At some points in the code the error string includes itself. This
generates self-repeating error messages.
2012-10-30 16:38:09 +01:00
Peter Lieven
ef3b6fe911 INIT fix url parsing error message 2012-10-30 12:02:09 +01:00
Peter Lieven
ca6f28437a INIT remove redundant url parsing code 2012-10-30 11:56:12 +01:00
Peter Lieven
9f82d0bf83 INIT allow a trailing / in iscsi_parse_portal_url() 2012-10-30 11:47:12 +01:00
Peter Lieven
774ede1f46 ISCSI_URL change strings from dynamic to static 2012-10-30 11:41:51 +01:00
Peter Lieven
923b9a4fb2 ISCSI-CONTEXT change dynamic string allocations to statics 2012-10-27 17:23:40 +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
d1110b7515 Add various environment variables
This patch allows the following parameters inside libiscsi to be adjusted without code modification:
LIBISCSI_DEBUG
LIBISCSI_TCP_USER_TIMEOUT
LIBISCSI_TCP_KEEPIDLE
LIBISCSI_TCP_KEEPCNT
LIBISCSI_TCP_KEEPINTVL

You can now enable debugging of libiscsi inside e.g. qemu-kvm with
LIBISCSI_DEBUG=3 qemu-kvm -hda iscsi://...
2012-10-20 18:11:35 +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
Peter Lieven
4cb845477d Add debugging framework
This patch adds a user configurable debug level. For testing
it includes connection info and reporting errors.
2012-10-18 10:36:26 +02:00
Ronnie Sahlberg
06cc2d2ece CONNECT: connect data is not always malloc()ed so we can demand it is free()able
After a sync connection, make sure to clear connect_data since it will otherwise
point to a structure on the stack.
2012-08-09 08:27:48 +10:00
Ronnie Sahlberg
439f68e555 CONNECTION: Track the connection state and callback via the context structure
Dont free the connection state when login is finished, instead track it via the
iscsi context structure and free it once the context is destroyed
2012-08-02 08:51:25 +10:00
Ronnie Sahlberg
9e5535adfd Reconnect: If we are logged in and we experience a session failure, then
try to re-connect and redrive all I/O

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2012-05-01 18:46:30 +10:00
Paolo Bonzini
a1975e90f6 fix warning from -Wuninitialized 2011-09-21 12:00:20 +02:00
Ronnie Sahlberg
c3d3123981 Windows: Add support to build as a DLL under windows 2011-08-31 13:12:30 +10:00
Ronnie Sahlberg
356a6571bb Login: remember what the TargetAddress returned during login is so we can
handle redirect 'errors'.
2011-02-25 15:35:49 +11:00
Ronnie Sahlberg
d1fdaef5c6 Username/password separator: Allow ':' to separate the chap username/password in addition to '%' 2011-02-20 10:44:53 +11:00
Ronnie Sahlberg
d22a2aee3c When initializing a new session, default to set the
"random" ISID randomly.

Dont assume that users will never create multiple contexts
concurrently, in which case the previous getpid()^time(NULL)
would create duplicates.
2011-01-27 11:02:16 +11:00
Ronnie Sahlberg
7b5ff1095c Improve help/usage strings for iscsi-ls and iscsi-inq
For help output, also print the syntax for the iscsi url required.
2011-01-09 10:36:53 +11:00