Commit Graph

91 Commits

Author SHA1 Message Date
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
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
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
52a6bdb774 Revert "lib: Make iscsi_realloc() update the freed pointer list"
iscsi_realloc MUST NOT be called with a pointer that is in the freelist
of small allocations. First they are free and secondly a realloc
will change the size of the small allocation to an unknown size.

This reverts commit d8de6531f8.
2015-04-23 14:12:57 +02:00
Bart Van Assche
cf4076dba9 test-tool: Make it possible to disable memory caching
Disable memory caching in libiscsi if the environment variable
LIBISCSI_CACHE_ALLOCATIONS has been set to zero. This makes
Valgrind reports more meaningful.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-04-20 07:01:17 -07:00
Bart Van Assche
d8de6531f8 lib: Make iscsi_realloc() update the freed pointer list
This patch improves the stability of libiscsi by avoiding that
stale pointers are passed to free().

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-04-20 06:57:31 -07:00
Peter Lieven
e4a448b115 init: don't close fd of iscsi->old_iscsi
its already closed at this point

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-16 11:58:39 +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
2955b2c616 init: apply settings to context in iscsi_parse_url
if iscsi_context is not NULL we apply the parsed settings
to the context.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 10:37:39 +01:00
Peter Lieven
a45094b7a7 init: fix segfaul in iscsi_parse_url
We allowed iscsi to be NULL in iscsi_parse_url. Especially
qemu does this and currently segfaults at start. Change the
usage guidelines for target username/password to be the same
as for chap username/password.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 10:07:52 +01:00
Peter Lieven
ea2bcfd308 init: fix segfault in iscsi_destroy_context
observed when iscsi_destroy_context is called while a iscsi NOP out is in flight.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-19 12:40:37 +01:00
Ronnie Sahlberg
b1d0ac45f1 Add support for bidirectional CHAP
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-03-14 10:43:03 -07:00
Peter Lieven
de7b38d9a0 use MIN and MAX macros at some places
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-02-23 08:03:27 +01: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
1828481ba2 Portability fixes. Declare variables at the start of a scope only. 2013-10-05 13:48:00 -07:00
Sitsofe Wheeler
7692027d6c Fix compilation issues under clang
clang defaults to c99 so remove inline statements
(http://clang.llvm.org/compatibility.html#inline ) on functions shared
across different translation units.
clang's linker doesn't like major numbers over 255 so change how SOREL
is generated in Makefile.am.
2013-09-09 18:04:06 +01: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
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