Commit Graph

33 Commits

Author SHA1 Message Date
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
Yuri Pankov
2a0ad3bd2d FreeBSD and illumos do not define SOL_TCP 2012-06-20 02:54:34 +04:00
Ronnie Sahlberg
6be4a82407 Remove some unused variables 2012-05-30 18:23:15 +10:00
Ronnie Sahlberg
824a33c834 win32 set the socket to nonblocking moe for win32 2012-05-15 22:08:10 +10:00
Ronnie Sahlberg
ec0d9682a7 Dont use FIONREAD just rely on the fact the socket is nonblocking and look for EAGAIN when we reach the end of available data.
From Paolo Bonzini <pbonzini@redhat.com>
2012-05-15 20:32:37 +10:00
Ronnie Sahlberg
ed4b8ec72e W32: Remove our poor emulation of poll() from the w32 build. 2012-05-13 16:46:38 +10:00
Michael Tokarev
aee0e3bf72 always export iscsi_set_tcp_keepalive()
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>
2012-05-12 08:41:34 +10:00
Ronnie Sahlberg
c91de1e35a We might be called by some eventsystems with POLLIN eventhough there is
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.
2012-05-10 20:04:22 +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
Ronnie Sahlberg
6ecf536e86 Rename a varialbe to get rid of compiler warning 2011-12-31 10:31:23 +11:00
Ronnie Sahlberg
114c81390f Remove unused variable 2011-12-31 10:29:41 +11:00
Ronnie Sahlberg
49017fda58 OpenSolaris: Add support for opensolaris 2011-09-01 18:04:29 +10:00
Ronnie Sahlberg
c3d3123981 Windows: Add support to build as a DLL under windows 2011-08-31 13:12:30 +10:00
Ronnie Sahlberg
3a39201543 Add 'zero-copy' in libiscsi for reads.
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.
2011-04-20 05:46:17 +10:00
Ronnie Sahlberg
b6782dd7c8 TCP KEEPALIVE support
Add tcp keeplaive support on platforms that support these socket options.
Set default to fail the socket after 120 seconds
2011-04-13 21:37:28 +10:00
Ronnie Sahlberg
376f60fc06 Use ioctl(FIONREAD) to determine how many bytes are readable in the socket
and make sure we dont try to read mor than that.
2011-04-03 07:22:05 +10:00
Ronnie Sahlberg
c29b9a2aae Add a new "iscsi_queue_length()" which will tell us how many commands
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.
2011-02-03 19:08:16 +11:00
Ronnie Sahlberg
b9ad4beb41 Replace rindex() with strrchr() 2011-01-09 09:47:39 +11:00
Ronnie Sahlberg
5e11bb17b1 Replace index() with strchr() 2011-01-09 09:46:42 +11:00
Ronnie Sahlberg
aa916b7802 IPv6 Support. Add ipv6 support to the socket management.
IPv6 addresses are specified in [...] format.

iscsi://10.1.1.27/...
iscsi://10.1.1.27:3260/...
iscsi://[fec0::1]/...
iscsi://[fec0::1]:3260/...
2011-01-08 16:09:14 +11:00
Ronnie Sahlberg
9ddce8dc24 Replace bzero() with memset() 2011-01-03 15:35:36 +11:00
Ronnie Sahlberg
87072d5622 Dont use gethostbyname2() at all since it is non-portable,
use gethostbyname() instead.
2011-01-03 14:48:43 +11:00
Ronnie Sahlberg
adfb7326e3 Solaris needs -lsocket and -lnsl and does not support gethostbyname2()
With these changes we build and work on solaris
2011-01-03 10:57:35 +11:00
Ronnie Sahlberg
490a01053a Add a flags field to the pdu structure
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.
2011-01-02 18:00:19 +11:00
Ronnie Sahlberg
2b30e3a7fe When getting a socket POLLERR event, use getsockopt(SO_ERROR)
to create a better error message about the reason for the socket failing.
2010-12-31 06:01:41 +11:00
Stefan Hajnoczi
6981b79516 Check SO_ERROR when async connect completes
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>
2010-12-29 08:57:48 +00:00
Stefan Hajnoczi
faec3c0dfd Only await POLLOUT events until connected
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>
2010-12-29 08:57:48 +00:00
Ronnie Sahlberg
647ebd222e Try to resolve hostnames into ip addresses
Dont assume everyone just uses dotted-decimal always on their networks.
Try resolve hostnames specified in the iscsi URLs into addresses
2010-12-28 13:51:54 +11:00
Ronnie Sahlberg
1c024d6bc4 Input processing:
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.
2010-12-11 15:15:51 +11:00
Ronnie Sahlberg
8a6665a092 Licence
Change to LGPL 2.1+ to be compatible with kvm/qemu
2010-12-11 11:47:28 +11:00
Ronnie Sahlberg
3d3da6c6e3 include config.h from lib/socket.c and use this to conditionaly
compile code to set sin_len on platforms that require this field
in the sockaddr structures.
2010-12-05 13:53:41 +11:00
Ronnie Sahlberg
709d85c4da Add a COPYING file and updat ehte LGPL boilerplate 2010-12-05 11:11:37 +11:00
Ronnie Sahlberg
098bc5a9a7 Initial import of libiscsi 2010-12-05 08:24:57 +11:00