Commit Graph

45 Commits

Author SHA1 Message Date
Sitsofe Wheeler
0b6b12ba53 TESTS: Fix COMPAREANDWRITE tests to send write data
Previously COMPAREANDWRITE was only sending verify instance data which
can cause targets to generate COMMAND ABORTED/NOT ENOUGH UNSOLICITED
DATA errors due to the buffer being obviously too small to contain
verify AND write instance data.

The buffer size check has been modified and compareandwrite tests
updated to pass a larger buffer with interesting write instance data.
2013-09-09 17:48:13 +01:00
Ronnie Sahlberg
daac72a8f9 TESTS more writesame1* test fixes 2013-08-25 16:39:38 -07:00
Ronnie Sahlberg
dc981c93ef Cleanup: rename to payload_* the PDU variables used to track writing to socket 2013-08-04 17:34:15 -07:00
Ronnie Sahlberg
804c5b0211 Dont reference *pdu after it has been freed 2013-07-21 13:29:43 -07:00
Ronnie Sahlberg
fd38ff4bfc Add MODESENSE6/10 and MODESELECT6/10 support 2013-07-20 14:05:20 -07:00
Ronnie Sahlberg
7895fb700c Add MODESELECT6 support
Add support for MODESELECT6 and add marshalling functions for the
mode pages we support so far.
2013-07-06 16:11:17 -07:00
Ronnie Sahlberg
92b987de52 Add helpers for the SANITIZE service actions 2013-05-26 10:51:19 -07:00
Ronnie Sahlberg
eebd04e613 Add initial support for SANITIZE and a simple test to generate this opcode. 2013-05-25 16:02:02 -07:00
Ronnie Sahlberg
ce4623b2fb READ SUPPORTED OPCODES. Update the signature to allow setting all of the
parameters to this command.
2013-05-18 12:34:03 -07:00
Ronnie Sahlberg
b7dd6b533b TEST: Add a test that is cmdsn is too low the target just ignores the pdu 2013-04-30 19:05:23 -07:00
Ronnie Sahlberg
4a8d967541 Add support for synchronous command timeout.
Default to 0 meaning no timeout.

Implement a test for iSCS to test what happens if we send a command
with CMDSN being higher than the target allows.
In this case we dont strictly know what will happen, just that what should
NOT happen is the target responding with success.
But we have to be prepared for any kind of failure, including a timeout,
scsi sense, or even iscsi reject or session failure.
2013-04-29 20:42:33 -07:00
Ronnie Sahlberg
402653b9f3 portability updates
add check if ipv6/sockaddr_in6 is availavble or not
add check for poll.h and only include when available
add includes for AROS
2013-04-18 19:43:36 -07:00
Ronnie Sahlberg
0f73f062d2 SCSI: remove LBDATA/PBDATA from the WriteSame10/16 signatures
Make LBA the third argument to the iscsi writesame functions
2013-01-21 21:15:37 -08:00
Ronnie Sahlberg
72598c0b46 UNMAP: Fix marshalling of DATA when more than one unmap descriptor is sent. 2013-01-21 20:06:11 -08:00
Ronnie Sahlberg
065319f996 SCSI Add support for STATUS_BUSY
Add support for BUSY status coide from the target and just pass this
back to the application as is (instead of converting it to _ERROR).

This allows the application to trap task->status==SCSI_STATUS_BUSY and
decide what/how to proceed.
2013-01-01 10:15:56 -08:00
Ronnie Sahlberg
2a74fc00bc Initial support for PERSISTENT_RESERVER_OUT and add a simple test to show the api 2012-12-17 21:25:46 -08:00
Ronnie Sahlberg
c60093eafe Add support for PERSISTENT_RESERVE_IN and add a simple test for READ_KEYS 2012-12-17 19:01:50 -08:00
Peter Lieven
446b1829c8 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>
2012-12-10 19:24:28 +01:00
Ronnie Sahlberg
22797e0f67 NOPs should not be requeued when reconnecting a session.
Just like DATA_OUT we should just discard NOPs instead of requeueing them
on session reconnect.
Add new flag that to indicate this behaviour on reconnect and set it for
both data out and nops
2012-12-04 19:07:49 -08:00
Peter Lieven
be998cdaed DATA-IN fix broken read without iov
The preallocation logic was messing with size and offset of pdu->indata.
This was broken when we removed iscsi_data->alloc_size. Removing
entirely since reading without iovectors is deprecated.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-12-03 17:08:07 +01:00
Ronnie Sahlberg
39f42dbd2f Update comments explaining how we send unsolicited data.
Add comments to explain how/why we send unsolicited data.
This is a somewhat hairy area and it is easy to make mistakes here, so
extra comments on the how/why is useful.
2012-12-02 13:09:12 -08:00
Ronnie Sahlberg
023c7f855a Simplify the logic for when we need to send unsolicited DATA-OUT 2012-12-02 12:58:52 -08:00
Ronnie Sahlberg
338a8e26f5 When sending unsolicited data out, beginning of buffer to send is pdu->out_len, not pdu->offset.
We might have already sent pdu->out_len amount of data as immediate data.
2012-12-02 10:05:32 -08:00
Ronnie Sahlberg
a3ce92c93c Fix sending of unsolicited data in the first burst
When deciding if to generate a data out queue for the first sequence
the test was wrong.
We should not check if INITIAL_R2T is NO and IMMEDIATE_DATA=NO.
Immediate data does not matter here.

What we should check is IF we have more data we need to send and IF
INITIAL_R2T allows us to send more data, then we generate a train of DATA-OUT.

If MaxRecvDataSegmentLength is less than FirstBurstLength we will often have
to send unsolicited data as both ImmediateData and also as unsolicited
DATA-OUT PDUs.

Example:
Assume Target has responded :
MaxRecvDataSegmentLength = 8k
FirstBurstLength = 64k
ImmediateData=YES
InitialR2T=NO

Then this should generate the following sequence :
I->T   ISCSI_COMMAND + 8K of immediate data. F-Bit is not set.
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K
I->T   DATA-OUT 8K. Final PDU in sequence   so F-bit is set.
T->I   R2T
...
2012-12-02 09:55:07 -08:00
Ronnie Sahlberg
564fc9963a Max immediate data we can send is MIN(maxrecvdatasegmentlength, firstburstlength)
Also, we can send unsolicited DATA-OUT if we need to regardless of whether we also sent immediate data.
2012-12-02 09:37:18 -08:00
Ronnie Sahlberg
9a570e0b37 Dont clear the F-flag when we we have more data to send later as solicited data.
If we do a write that spans more than first-burst-length amount of data
and we can use immediate data.

This will lead to a sequence
I->T  SCSI_COMMAND + furst_burst_length of immediate data
T->I  R2T
I->T  DATA-OUT with the remainder of the data.
T->I  SCSI_RESPONSE

In this situation we still have to set the F-bit in the flags for the ISCSI_COMMAND.

The F-bit indicates that the PDU is the final PDU in the current sequence
and is what will trigger the target to process what it has currently received
after which the target will either respond with a SCSI-RESULT or DATA-IN if this
was the final sequence of the command,
Or in the case this was not the last sequence, then the target will send a R2T
to request the next sequence for this command.

In this scenario above we have two sequences.
the first sequence is the SCSI_COMMAND with immediate data and since it has filled the full amount of immediate data and can not send any more data until an R2T, this means this pdu ends the sequence and thus has the F-bit set.

Once we receive the R2T the second sequence starts, which also will have the F-bit set in the PDU.
2012-12-01 08:28:47 -08:00
Peter Lieven
92114f5d7a ISCSI fix broken send logic in iscsi_scsi_async_command [v2]
This fixes the IMMEDIATE_DATA_YES case if the paylaod did
not fit into the first PDU and fixes no unsolicited data
sent out iff IMMEDIATE_DATA_NO and INITIAL_R2T_NO.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-30 21:06:39 +01:00
Peter Lieven
30df192634 DATA-OUT set pdu->cmdsn appropriately
set the cmdsn in the pdu struct so we can compare with
maxcmdsn when sending to socket even if data-out pdus
do not carry a cmdsn on the wire.

if we would not set pdu->cmdsn comparsion with
iscsi->maxcmdsn would cause a deadlock after
maxcmdsn increases to 2^31.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-30 18:18:17 +01:00
Ronnie Sahlberg
3ae7cec51d Revert "ISCSI fix broken send logic in iscsi_scsi_async_command"
This reverts commit 548bd22f51.

Revert for now. Will check it later today.
Causes 0130 and other tests to fail/hang when sending a solicited data-out
2012-11-30 06:49:53 -08:00
Peter Lieven
548bd22f51 ISCSI fix broken send logic in iscsi_scsi_async_command
The send logic was completely broken for any cases except
ISCSI_INITIAL_R2T_NO and ISCSI_IMMEDIATE_DATA_YES.
The final flag was set wrong or no data was sent.

It was also broken if the data did not fit into the cmd_pdu as
the consecutive pdus did not have the scsi_cbdata set which
lead to a segfault in iscsi_get_user_out_buffer().

Unfortunately we need to include scsi-lowlevel.h again in iscsi-private.h.
This should be fixed asap by introduction of an iscsi_task struct
to avoid to store iscsi relevant data in the scsi_task.

Signed-off-by: Peter Lieven <pl@kamp.de>

Conflicts:

	lib/iscsi-command.c

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-30 08:43:34 +01:00
Ronnie Sahlberg
7704215bcc SCSI: Revert some of the changes to introcuce iovectors and prepare to
obsolete the old api.

After discussions, It is probably not the right thing to do.
Lets leave the old api as is. Most simpler applications will
continue to pass a single linear buffer to the iscsi_<send-data-out-to-device>_task() for convenience  so it would be wrong to force them all to
migrate to amore complex iovector api.

Convert any linear buffers, if provided, to a one element data-out iovector
if a buffer was provided.
2012-11-29 19:08:57 -08:00
Ronnie Sahlberg
5ffb58c55f Merge branch 'zero_copy_write-3' into resolve-conflicts
Conflicts:
	lib/iscsi-command.c
	lib/pdu.c
	lib/socket.c
2012-11-29 18:46:51 -08:00
Ronnie Sahlberg
6eb523af64 Merge pull request #45 from plieven/nest-scsi_cbdata
ISCSI_PDU nest iscsi_scsi_cbdata
2012-11-29 06:36:06 -08:00
Peter Lieven
cd09c0f17d PDU use serial32 arithmetic for cmdsn, maxcmdsn and expcmdsn.
RFC3720 says that cmdsn comparison must be done using
serial32 arithmetic. This will definetly avoid a deadlock
if cmdsn wraps from 2^32-1 to 0.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 10:37:28 +01:00
Ronnie Sahlberg
20416529d6 Merge pull request #42 from plieven/fix-leaked-mem-report
ISCSI fix leaked memory report
2012-11-27 19:17:27 -08:00
Peter Lieven
d9f0464232 ISCSI_PDU nest iscsi_scsi_cbdata
We can simply next the iscsi_scsi_cbdata in the iscsi_pdu struct
since it is only used inside the iscsi_pdu.

This saves one malloc for each pdu.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-27 11:48:53 +01:00
Ronnie Sahlberg
9f741ad2e3 Remove the iscsi data alloc_size field.
Avoiding to realloc data over and over should rather be handled with something
similar to iovectors instead.
2012-11-25 19:22:37 -08:00
Ronnie Sahlberg
e86703b3aa Convert all scsi task functions to use iovectors. 2012-11-25 18:45:36 -08:00
Ronnie Sahlberg
3ac9fdcbff Change iscsi_scsi_command_async() to use iovectors for writes.
Change iscsi_scsi_command_async() to write data-out using iovectors
attached to the scsi task structure instead of copying the data into
the buffer holding the header.
Still allow passing the data via an argument to the funtcion so that the
ABI does not change but then just conver the data to an iovector.

Update the write_to_socket functions to know about the iovectors and write them
as part of the pdu.

Convert write10_task to use iovectors.

This will allow 'zero-copy' writes through libiscsi.
However, as 'zero-copy writes does mean that we do more send() calls into
the kernel this may degrade performance for very small i/o.

A scsi write will not take at least 2 send() calls.
One send call for the iscsi header structure and a second send call for the
payload data.
This will be more expensive than the old memcpy() of payload data plus one send() call since the send() will be a lot more expensive than memcpy() of a small amount of data.
2012-11-25 18:17:51 -08:00
Bernhard Kohl
6644389907 Use the (un)marshalling functions scsi_get/set_uint16/32() anywhere in the code
This has the nice side effect to remove the compiler warning
"dereferencing type-punned pointer will break strict-aliasing rules"
which occur since gcc-4.7.

There are 79 locations where the warning occurs. All of them are in
statements where the htonl/htons/ntohl/ntohs functions are used, e.g.:

in lib/pdu.c                itt = ntohl(*(uint32_t *)&in->hdr[16]);
in lib/scsi-lowlevel.c      *(uint32_t *)&task->cdb[2] = htonl(lba);

The warning is not related to the htonl/htons/ntohl/ntohs functions but
to the casting/dereferencing operation. If the dereferenced variable is
already a pointer, the warning does not not occur, e.g. this one:

in lib/pdu.c                itt = ntohl(*(uint32_t *)&in->data[16]);

The warning is caused by the -fstrict-aliasing option. The
-fstrict-aliasing option is enabled at optimization levels -O2, -O3, -Os.

Signed-off-by: Bernhard Kohl <bernhard.kohl@gmx.net>
2012-11-23 16:47:32 -08:00
Peter Lieven
f2f42547bd ISCSI fix leaked memory report
As long as we have no struct iscsi_task we cannot track the
free() of data.indata buffer. This leads to a leaked memory
report in iscsi_context_destroy().

We fix this by assuming it has been freed when we pass it
it to scsi_task.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-23 16:37:56 +01:00
Ronnie Sahlberg
3b3036b9da Add support for SCSI Sense formats 0x72/0x73 2012-11-19 18:25:12 -08:00
Peter Lieven
9e05aecadd MEMORY further remove memory reallocations
added a few tweaks to further remove the need to memory
allocation resizing by preallocating the right buffer size.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-18 14:01:52 -08:00
Ronnie Sahlberg
f9767e729a VERIFY10/12/16 If BYTCHK is false we dont need to transfer any blocks to the target
If BYTCHK is false the target will perform a medium check of the indicated
LBAs only and not compare with anything out of the DATA-OUT buffers.
As such we dont need to/should not transfer any DAT-OUT to the target.
2012-11-18 09:46:51 -08:00
Peter Lieven
b1374b42ed Rename scsi-command.c to iscsi-command.c 2012-11-12 16:12:29 +01:00