Commit Graph

50 Commits

Author SHA1 Message Date
Ronnie Sahlberg
07ad0572f2 Add support for READ6 2011-04-16 08:06:16 +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
ef846b0f30 Target initiated NOP:
Initial support to try to respond to target initiated NOPs.
2011-04-10 15:33:42 +10:00
Ronnie Sahlberg
cfe19486ee Add RESERVATION CONFLICT
From Richard Sharpe,  add support to handle when a target responds with
RESERVATION CONFLICT to a scsi i/o
2011-04-09 12:00:10 +10:00
Ronnie Sahlberg
5225b5fa66 Add definitions for ASCQ LBA-OUT-OF-RANGE 2011-04-04 17:40:13 +10:00
Ronnie Sahlberg
4979b7346f From Richard Sharpe
Add a mechanism where residual overflow/underflow can be reportad back to
the application

We probably need somethinf for bidir residuals at some stage too
2011-03-27 19:27:10 +11:00
Ronnie Sahlberg
343d86dca7 get rid of the _async() scsi functions.
We dotn need two interfaces that only diuffer in whether they return a pointer or NULL vs an semiidentical interface that returns 0 or <0

All uses of _async() for scsi tasks should be replaced with the equivalent _task() function instead
2011-03-27 18:17:12 +11:00
Ronnie Sahlberg
f4f6ef5033 change dont automatically free the scsi_task once the callback completes.
Freeing the scsi_task structure is the responsibility of the application
to either do so during the callback, or later.
2011-03-27 17:53:05 +11:00
Ronnie Sahlberg
4e6e39ee23 Support for REJECT PDUs. 2011-02-27 13:49:49 +11:00
Ronnie Sahlberg
3561dbbd61 Document the async _task() functions 2011-02-27 10:32:23 +11:00
Ronnie Sahlberg
76208e1eff Rename the _send() functions to _task()
These functions are also async functions for SCSI commands but they return
a task structure or NULL.

This task structure can be used in task management functions to abort the task or a whole task set.
2011-02-27 10:29:51 +11:00
Ronnie Sahlberg
356a6571bb Login: remember what the TargetAddress returned during login is so we can
handle redirect 'errors'.
2011-02-25 15:35:49 +11:00
Ronnie Sahlberg
e9749ee68c Add ifdefs to protect the header files from being included
multiple times

From Richard Sharpe
2011-02-25 14:25:45 +11:00
Ronnie Sahlberg
c07dee474c TaskManagement: Add LunReset, TargetWarmReset, TargetColdReset 2011-02-19 18:23:03 +11:00
Ronnie Sahlberg
6a2a8b5187 TaskManagement: Add a function for abort task set 2011-02-19 18:18:56 +11:00
Ronnie Sahlberg
b81d21ce8c TaskManagement: Add a function to abort a scsi_task 2011-02-19 18:04:55 +11:00
Ronnie Sahlberg
4315ee9225 Create _send() functions for all scsi commands that return a 'handle'
we can use to abort the task later.
2011-02-19 17:30:03 +11:00
Ronnie Sahlberg
09446737aa TaskMgmt: add a enum for the task management functions 2011-02-15 22:03:41 +11:00
Ronnie Sahlberg
3dfdebcba7 TaskMgmt : Add an initial function to create a iscsi tm PDU 2011-02-15 21:53:47 +11:00
Ronnie Sahlberg
332ea04e8d TaskMgmt: Add a functionto set the Reference cmdsn for tm pdus 2011-02-15 21:44:16 +11:00
Ronnie Sahlberg
95db35e592 TaskMgmt: add a function to set the ritt for tm pdus 2011-02-15 21:42:23 +11:00
Ronnie Sahlberg
2c093d86a6 whitespace changes to the list of pdu types 2011-02-15 21:26:26 +11:00
Ronnie Sahlberg
704288169f Add task management pdu request and response constants to the list of pdu types 2011-02-15 21:24:24 +11:00
Ronnie Sahlberg
f73e42ec26 TaskManagement: Store the ITT and CMDSN in the scsi_task structure
These are required for some of the task management functions
2011-02-15 20:57:03 +11:00
Ronnie Sahlberg
eba0a2de81 SYNC READ10 : add a sync version for read10 2011-02-05 20:41:02 +11: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
ec08fe7a45 Read10/Write10 parameters
LBA is uint32_t for read/write10

Also store the lba/numblocks arguments in the task structure for read10/write10
This makes it much easier to implement a fully async "read lots/write lots"
applications.
2011-01-23 18:34:16 +11:00
Ronnie Sahlberg
7b5ff1095c Improve help/usage strings for iscsi-ls and iscsi-inq
For help output, also print the syntax for the iscsi url required.
2011-01-09 10:36:53 +11:00
Ronnie Sahlberg
e312aa2ae0 ISID: Add helper functions to set any type of ISID value for the iscsi context.
Let default be to create a 'random' ISID during context creation.
2011-01-09 09:26:03 +11:00
Ronnie Sahlberg
b5d5370b8c TYPO, fix typo in iscsi.h 2011-01-09 09:04:13 +11:00
Ronnie Sahlberg
7253a667ae Add a helper function to parse a Portal URL.
A Portal URL is of the form
   iscsi://[<username>[%<password>]@]<host>[:<port>]
and is used by command such as iscsi-ls during the discovery login phase.

During discovery we do not yet know the target iqn name, nor the lun of
any devices.
2011-01-03 15:22:01 +11:00
Ronnie Sahlberg
74fadc9337 Add support for R2T PDUs.
Update the "send scsi command" fucntion to honour
"FirstBurstLength" so that we only send this many bytes as unsolicited data.

The wait for a train of R2T from the target to clock out additional
busrts of data until the full task data has been sent to the Target.

We should now honour, and handle the case of
ImmediateData=No
InitialR2T=No
correctly for targets that are limited on receiveing data too fast.
2011-01-02 19:27:32 +11:00
Ronnie Sahlberg
d240e8b5aa Use an initiator specific and one target specific value for MaxRecvDataSegmentLength 2011-01-02 19:27:16 +11:00
Ronnie Sahlberg
5e5d6c05c0 Add a function to send DATAOUT PDUs.
Update the send pdu command to trap when we need to send data to the target
but we are not allowed to send using immediate data.
For this case, send the data as a separate DATAOUT pdu instead.

Twiddle the flags and other fields to now manage that we send the data
as two separate PDUs.
2011-01-02 18:01:21 +11:00
Ronnie Sahlberg
9a8fca8bea Add two new helpers iscsi_pdu_set_[datasn|bufferoffset]()
These two helpers can be used to set the corresponding fields in a
DATAOUT PDU
2011-01-02 18:01:08 +11:00
Ronnie Sahlberg
9cd03ca559 Add a new helper function iscsi_allocate_pdu_with_itt_flags()
This function can allocate a new pdu using a specific itt value
and specific flags instead of using the defaults of, next iff, no flags set.

This can be used when we need to allocate additional PDUs in a chain,
for commands that span across multiple PDUs and where all need to keep
the same itt value.

For example
   ->WRITE10 cdb
   ->DATAOUT
   -<RESPONSE

Here the DATAOUT PDU belongs to the same task that was started by write10
so it need to use the same itt value.
2011-01-02 18:01:00 +11:00
Ronnie Sahlberg
1569624fd2 Add a new helper function _set_itt() that can be used to set the itt of
a pdu, instead of having to twiddle the bits and bytes manually.
2011-01-02 18:00:46 +11:00
Ronnie Sahlberg
72f9d8fa82 Add a new pdu flag : NO_CALLBACK
This flag is used when we dont want the CANCEL callback to be invoked if the
context is destroyed.

Thsi will be used for the sequence where we send multiple PDUs
to the target for one single scsi task, such as
    -> WRITE10 cdb
    -> DATAOUT
    -< RESPONSE

Since if the context is destroyed when the command is in flight, we
already get the CANCEL callback for the WRITE10 PDU, so we dont need to invoke
it again for when we destroy the DATAOUT pdu, since they both refer to the same
task.
2011-01-02 18:00:37 +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
1f1e5111d4 Negotiate ImmediateData during login and store the result in iscsi->
We will use this later to decide when we should send unsolicited imemdiate
data to the target. Currently we always send unsolicited immediate data
but targets configured to not allow immediate data may refuce this and
turn an error.
2011-01-02 12:59:41 +11:00
Ronnie Sahlberg
32228a4509 Negotiate InitialR2T during login. Default to offer No, but update
and accept what Target responds.

Store the result of the negotiated setting in the iscsi context
so we can use it later to determine how to send solicited/unsolicited
data.
2011-01-02 12:50:00 +11:00
Ronnie Sahlberg
a3328a85ef Negotiation of MaxBurstLength, FirstBurstLength, MaxRecvDataSegmentLength
Add these settings to the iscsi context structure and initialize them to
sane valued.
When sending login commands to the target, use these values instead
of hardcoded values.
Parse when the target sends a login reply back to us and update these variables
if the target asks us to.

This allows us to detect when our defaults are too big for the target
and adjust the settings we use so we match the target.

Some targets have a very small accepted default for some settings.
During login, we will initially send these keys with our dafult values.
These targets will then respond back by refusing to transition to the next
login phase, and by telling us back what the maximum of these values should be.
In this case we have to try the login again but use the smaller values we got
from the target.
Othervise, if we try again, ignoring the value from the target, and just repeat
using our defaults the target will abort the login with a "initiator error".
2011-01-01 09:51:16 +11:00
Ronnie Sahlberg
a0acddb627 Update to the public header to better document the api 2010-12-31 12:26:46 +11:00
Ronnie Sahlberg
40abe849b0 CHAP
Add unidirectional chap support so we can authenticate to the target.

Make the login phase more "intelligent" so we can iterate over login
pdus until we have reached full feature phase

Add a new helper functions to parse a iscsi url and break it down
into elements in a structure

Update iscsi-inq to allow CHAP authentication
2010-12-22 22:23:55 +11:00
Ronnie Sahlberg
633a08bc22 MD5
Add a public domain implementation of MD5 so we can compute CHAP
The md5 implementation is copied from TGTD
2010-12-22 21:57:58 +11:00
Ronnie Sahlberg
cf0ddbd0d9 URL PARSER
Add a function to parse a common iscsi://... URL so we dont have to re
implement the same code in every application
2010-12-22 18:40:46 +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
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