RFC3720 says that cmdsn comparison must be done using
serial32 arithmetic. This will definetly avoid a deadlock
if cmdsn wraps from 2^32-1 to 0.
Signed-off-by: Peter Lieven <pl@kamp.de>
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.
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.
Quoth gcc-4.6.3:
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/socket.lo -MD -MP -MF lib/.deps/socket.Tpo -c lib/socket.c -fPIC -DPIC -o lib/.libs/socket.o
lib/socket.c:445:1: warning: 'inline' is not at beginning of declaration [-Wold-style-declaration]
Fix this and make it a static function.
Also remove trailing whitespace from this file while at it.
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
Send a large number of DATA-OUT PDUs that do not have a matching SCSI-COMMAND
PDU and verify that the target responds correctly. Either by terminating the
session or by just ignoring the data.
Verify also that the target is not "surprised" and crashes.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
qemu-kvm/qemu-img starts in+out polls from the socket before the connection is
established. This leads to a hang if the connection cant be established
(i.e. the target is down when qemu-kvm is started).
before:
LIBISCSI_DEBUG=2 qemu-img convert -f iscsi -O raw iscsi://127.0.0.1/iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac/0 /dev/null
libiscsi: connecting to portal 127.0.0.1 [iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac]
libiscsi: read from socket failed, errno:111 [iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac]
libiscsi: connection to 127.0.0.1 established [iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac]
->success!!
after:
LIBISCSI_DEBUG=1 qemu-img convert -f iscsi -O raw iscsi://127.0.0.1/iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac/0 /dev/null
libiscsi: iscsi_service: socket error Connection refused(111) while connecting. [iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac]
libiscsi: Failed to connect to iSCSI socket. iscsi_service: socket error Connection refused(111) while connecting. [iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac]
qemu-img: iSCSI: Failed to connect to LUN : Failed to connect to iSCSI socket. iscsi_service: socket error Connection refused(111) while connecting.
qemu-img: Could not open 'iscsi://127.0.0.1/iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac/0': Invalid argument
qemu-img: Could not open 'iscsi://127.0.0.1/iqn.2004-04.com.qnap:ts-809u:iscsi.lieven20.c53dac/0'
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.
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.
For TCP_USER_TIMEOUT to work it seems to be necessary that SO_KEEPALIVE is
enabled. RFC5482 section 4.2 also says that the TCP_USER_TIMEOUT has to be
less than the keepalive timeout. This means less than 30000 ms in the
current libiscsi default settings for TCP keepalives.
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.
Set only the (socket) options which are defined on a given platform.
The function becomes a no-op if no option is known at complie time.
Remove autoconf test for HAVE_TCP_KEEPALIVE too.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
no data to read from the socket and there is no error.
For this case, if FIONREAD tells us that there are 0 bytes to read, check if
there is a socket error and return ok/error based on that.
Some eventsystems may cause this to burn some cpu if the socket is ok
but there are no bytes available to read by invoking POLLIN over and over, but it is better than failing the application.
It is not real zero-copy since the data is still copied in the kernel,
but it avoids copying the data inside libiscsi as well as in the callback.
For SCSI tasks that will return data from the target, the application can now
specify application buffers for libiscsi to read the data directly into.
This is done by calling scsi_task_add_data_in_buffer(task, ...
These buffers need not be linear, you can specify different areas to read into
by calling this function several times.
See examples/iscsiclient.c for an example.