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.
are in flight at the moment.
Aside from commands, we also consider the "has not yet connected completely" as being an i/o.
When this command returns 0 it means we are connected ant the iscsi connection is idle, with no commands in flight.
KVM needs a function to detect idleness like this for its block layer io_flush
function.
Add a new pdu flag : DELETE_WHEN_SENT. When this pdu has been
sent to the wire, the pdu will be deleted and not put on the waitpdu list.
This will be useful for sequences such as
-> WRITE10 cdb
-> DATAOUT the data to write
-< RESPONSE
Where we want to match WRITE10 and RESPONSE but where the plain DATAOUT pdu
will not be soliciting its own response.
We dont need to wait for the response to DATAOUT pdus, we are already waitin
for the response form the initial PDU in the sequence.
When non-blocking connect completes the error code can be read using
getsockopt(SO_ERROR). Doing this is important for identifying failure
to connect, especially if POLLERR and POLLHUP were not employed by the
user.
The QEMU iscsi block driver does not use POLLERR/POLLHUP and depends on
SO_ERROR to detect connection failure.
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Non-blocking socket connect(2) involves waiting for the socket to become
writeable to detect that a connection has been made. POLLIN events
should not be requested until the socket is connected because they are
processed even if the iSCSI context is not yet connected.
For example, the QEMU iscsi block driver does something like this:
iscsi_full_connect_async(...)
/* Now wait until the socket becomes ready */
poll(POLLIN|POLLOUT) = POLLIN|POLLOUT
/* QEMU calls POLLIN and POLLOUT handlers individually and it happens to
* call the POLLIN handler *before* the POLLOUT handler.
*/
iscsi_service(POLLIN)
iscsi_service(POLLOUT)
POLLIN processing will read from the socket and consume the error code
if connect failed. As a result, the POLLOUT handler will write to a
disconnected socket and raise a SIGPIPE which kills the process.
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Input processing used to keep all data in one single input buffer, which
makes it hard to handle nested events as well as reading directly from the
socket into the application buffer without an extra copy.
Create a new iscsi_in_pdu structure where we store the header, and any data
for the recevied pdu and store them in a proper input queue.
Change the signature for all processing functions to tahe a iscsi_in_pdu
structure for the received pdu instead of just a pointer to a buffer.