NOP count in flight of client generated NOP-Outs

This patch adds the abilitiy to libiscsi to count the number
of consecutive outstanding NOPs.

With this ability its fairly easy to implement a keepalive
check with NOPs in your application.

Periodically (e.g. every 5 secs) create a NOP-Out with:

iscsi_nop_out_async(iscsi, NULL, NULL, 0, NULL);

At that time check the number of consecutive missing NOP-Ins
with

iscsi_get_nops_in_flight(iscsi) > N.

Where N is the number of missing NOP-Ins you will allow.
Please note that it is legitime for the Target to ignore
a NOP if the load is very high as those packet are mark
as IMMEDIATE.

Signed-off-by: Peter Lieven <pl@kamp.de>
RECONNCT fix broken reconnect for iov out vectors

We where modifying out_offset and out_len in iscsi_write_to_socket().
If the packet that was being sent before reconnect was a write command
the was a significant change that out_offset and out_len where already
touched. When requeing the packet after reconnect we where
sending garbage!

Signed-off-by: Peter Lieven <pl@kamp.de>
RECONNECT remove redundant requeue code

We first merge waitpdu and outqueue queues and then requeue
the elements. iscsi_add_to_outqueue() will sort them accordingly
so this is no problem.

Signed-off-by: Peter Lieven <pl@kamp.de>
SOCKET remove useless code

At this point in iscsi_write_to_socket() pdu->written can only be
equal to total.

Signed-off-by: Peter Lieven <pl@kamp.de>
Merge pull request #54 from plieven/nop+queue-fixes

Nop+queue fixes
SOCKET set TCP_NODELAY on iscsi->fd

This will set TCP_NODELAY on the socket connection
to the target. This is the first step to improve latency.
For systems supporting TCP_CORK we plan to add a cork
around certain PDUs e.g. DATA-Out, but this needs further
testing.

Signed-off-by: Peter Lieven <pl@kamp.de>
SOCKET use readv/writev to write directly into iovectors

This patch adds support for read/writev to directly read and write
from/to iovectors. Before this patch on read and write from/to socket
the operation was limited by the iovec boundaries. If there is enough
data in the buffer or enough buffer space available its now possible
to transfer the whole data in one atomic operaion.

Signed-off-by: Peter Lieven <pl@kamp.de>
Merge pull request #55 from plieven/tcp_nodelay

SOCKET set TCP_NODELAY on iscsi->fd
PDU log header of rejected PDUs

Signed-off-by: Peter Lieven <pl@kamp.de>
SOCKET do not queue PDUs with itt==0xffffffff head of queue

Queing packets with itt = 0xffffffff (e.g. NOP-Out replies) ahead
of queue because they might have a higher CmdSN than following
packets. This again could lead to a deadlock AND its a protocol
violotion:

RFC3720 Section 3.2.2.1 second last paragraph on Page 21:
"On any connection, the iSCSI initiator MUST send the commands in
increasing order of CmdSN, except for commands that are retransmitted
due to digest error recovery and connection recovery."

Signed-off-by: Peter Lieven <pl@kamp.de>
SOCKET order packets in outqueue by CmdSN

Ordering by itt adds the special case of handling
itt == 0xffffffff. Order by CmdSN instead as described
by RFC3720.

Signed-off-by: Peter Lieven <pl@kamp.de>
Merge pull request #57 from plieven/outqueue-itt-fix

Nice catch.
Add support for PERSISTENT_RESERVE_IN and add a simple test for READ_KEYS
Add unmarshalling of PERSISTENT_RESERVE_IN/READ_KEYS DATA-IN blob
Add test for the range of service actions for PERSISTENT_RESERVE_IN
Initial support for PERSISTENT_RESERVER_OUT and add a simple test to show the api
TEST: Change the last test to be a more simple REGISTER/UNREGISTER test for persisntet registrations.
Add unmarshalling og READ_RESERVATION data
Add unmarshalling ot REPORT_CAPABILITIES
Added no-strict-aliasing to compile flags.
Would not compile on my openSUSE 12.2 system without this fix.