iscsi_create_context() calls srand() every time a new context is
generated. That practice is questionable, as the seed does not need to
change before each call to rand(). As a matter of fact, doing so defeats
the purpose of using rand() altogether. Furthermore, the current
implementation is not thread safe.
This improves ISID generation by using /dev/urandom (when available) as
a seed, and calling srand() only once. In case of errors, fallback to
using something similar to the previous implementation (albeit
thread-safe).
Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
The current random seed for determining a new context's ISID is
calculated by XOR'ing time(), getpid() and "iscsi". When invoked from
iscsi_reconnect(), all three inputs are likely to be identical,
resulting on identical ISIDs.
That happens because iscsi_reconnect() malloc()s a temporary "iscsi"
which is then free()d at the end of the call. Successive calls to
malloc() (from that function) are therefore likely to reuse the same
address for the context.
When multiple sessions are used for different LUNs of the same target,
and reconnects happen within the same second (the precision given by
time()), then multiple login attempts will happen with identical values,
violating the ISID RULE as described in Section 3.4.3 of RFC3270.
This fixes the issue by introducing a sequence number to the ISID seed
generation.
Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
Introduce a helper exported from lib/pdu.c which cancels all pdus for a
given context. This patch eliminates repeated code from various other
files which have the same purpose. The only functional difference is
that the cancellation done from iscsi-command.c was (incorrectly) not
checking for iscsi->is_loggedin before issuing callbacks.
Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
Using WIN32 depends on the build environment defining the variable.
_WIN32 is a predefined MSVC macro and is always available.
Signed-off-by: Tim Crawford <crawfxrd@gmail.com>
The primary issue is that in MSVC 14.00 (VS2015) Microsoft added
snprintf as a function to the standard library and prevents users from
defining it to something else (typically, this was _snprintf). So, only
define it when using _MSC_VER < 1900.
Other changes are:
- Fix macro definition of dup2
- Add macro for getpid
- Add function definition for win32_dup
- Add missing EXTERNs
Signed-off-by: Tim Crawford <crawfxrd@gmail.com>
Let user specify iSER support by the protocol part of the URL.
I.e. support both
iser://127.0.0.1/iqn.ronnie.test/1
iscsi://127.0.0.1/iqn.ronnie.test/1?iser
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This splits a transport into static driver specific functions for the common
iscsi commands. Optionally, a driver specific opaque memory is introduced
which is currently only used by iSER transport.
Last a lot of functions changed to static.
Signed-off-by: Peter Lieven <pl@kamp.de>
This commit includes all iSER implementation in libscsi
library and utilities.
Also, adding iser option in url.
Change-Id: I55ca8a9d4db802e72eb991061260dbb0bd0ef9ba
Signed-off-by: Roy Shterman <roysh@mellanox.com>
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>
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>
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>
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>
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.
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>
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>
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>
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>
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.
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>
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
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.
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>
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>
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>
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>