Commit Graph

18 Commits

Author SHA1 Message Date
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