Commit Graph

326 Commits

Author SHA1 Message Date
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
58e5ef5cbc SCSI_IOVECTOR remove size field
Remove the size field as it is not used. If we would keep it
we would have to calculate it in scsi_task_set_iov_in/out which
would add unneccassry wals to the iovec array.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-30 08:44:33 +01: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
b1da7311c4 change u_int to uint 2012-11-29 19:14:26 -08: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
14bee1007f RECONNECT do not increase CmdSN for immediate PDUs
Immediate PDUs such as queued NOP-Outs will cause
a protocol error on reconnect.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-29 15:17:30 +01:00
Peter Lieven
5da6ea7275 NOP make the message optional
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 18:44:22 +01:00
Ronnie Sahlberg
bd86570b4f minor style changes 2012-11-28 07:40:10 -08:00
Peter Lieven
1f4a66abc8 PDU queue out PDUs in order of itt.
This patch fixes a deadlock case where all available
cmdsns have been used for command PDUs which need
additional Data-OUT PDUs to succeed (e.g. a write16
which is larger than first_burst_len).
In this case the target will never increase the maxcmdsn
leading to a deadlock in iscsi_write_to_socket().
If we receive the R2T for such a write request we will
queue the Data-OUT PDUs but at the end of queue. As
a result they will never be sent as the outqueue is already
stuck.

We fix this by sorting the outqueue by ascending itt.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 14:04:14 +01:00
Peter Lieven
722eb013c8 TESTS really fix T1040
This finally makes T1040 trigger the cmdsn overflow deadlock.
Its a bad idea to mangle on negotiated parameters as this leads
to protocol errors.
We also need to avoid overlapping writes as this leads also
to protocol errors.
Additionally we test with and with (if available) immediate data.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 13:55:55 +01:00
Peter Lieven
562dd46833 PDU avoid incrementing itt to 0xffffffff
This patch avoid incrementing itt to 0xffffffff which is
a reserved value for immediate pdus. Avoid incrementing
it to 0xfffffff to avoid unexpected behaviour.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 10:58:33 +01: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
700d363a88 Create a wrapper function for when we add pdus to the out queue
so that we can add them so that they are send in increasing itt order.
2012-11-27 20:26:13 -08:00
Ronnie Sahlberg
22a8d221bf Merge pull request #43 from plieven/connection_info
SOCKET add debug info about local ip and port
2012-11-27 19:19:13 -08: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
Peter Lieven
00e267620c SOCKET add debug info about local ip and port
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-26 10:15:29 +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
bb755104e5 Remove iscsi_allocate_pdu_with_itt_flags_size()
We dont need this anymore.
2012-11-25 19:11:51 -08:00
Ronnie Sahlberg
7b1c0a19bb Remove iscsi_allocate_pdu_size. This is not use any more. 2012-11-25 19:02:34 -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
Ronnie Sahlberg
ccf81c74a7 make scsi_iovector_add() static 2012-11-25 14:11:59 -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
Bernhard Kohl
7e4b33dd31 scsi-lowlevel: make scsi_get_uint16/32() global and add scsi_set_uint16/32()
This is a preparation to use the (un)marshalling functions anywhere
in the library.

Signed-off-by: Bernhard Kohl <bernhard.kohl@gmx.net>
2012-11-23 16:46:03 -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
Peter Lieven
e7cc6dc1ca SCSI add support for POSIX compatible iovectos
This patch defines an scsi_iovec struct which is guaranteed
to be POSIX compatible. It furthermore adds support for
in+out iovectors for bi-directional operations
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-23 15:43:00 +01:00
Peter Lieven
55f76cfb0c SCSI add support for iovectors
If an application passes buffers to libiscsi for reading they are
currently added to a linked list one by one. This leads to a malloc
for each buffer object plus O(n) walks trough the list to add
the buffer to then end of the list. Additionally the buffer read
routine takes up to O(n) iterations to find the right buffer
for a request.

This patch introduces an scsi_iovector struct to pass buffers to
an scsi task. Adding a new buffer is in O(1) and finding the
right buffer to also. Malloc requirements are in O(log(n)).

Additionally the scsi_iovector struct is itended to be binary
compatible to an QEMUIOVector allowing to pass this structure
directly to the library.

Initial tests have been made booting an Ubuntu LTS 12.04.1
Desktop server up to the login prompt. The following observations
have been made with regards to scsi_malloc calls:

original implementation:	~11.500 mallocs
using iovector instead of list:	~ 7.500 mallocs
passing the iovector directly:        0 mallocs

To enable this feature in qemu for testing the following patch might
be used:

diff --git a/block/iscsi.c b/block/iscsi.c
index a6a819d..2809c15 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -390,11 +390,16 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
         return NULL;
     }

+#if defined(LIBISCSI_FEATURE_IOVECTOR)
+    assert(sizeof(struct QEMUIOVector) == sizeof(struct scsi_iovector));
+    scsi_iovector_assign(acb->task, (struct scsi_iovector*) acb->qiov);
+#else
     for (i = 0; i < acb->qiov->niov; i++) {
         scsi_task_add_data_in_buffer(acb->task,
                 acb->qiov->iov[i].iov_len,
                 acb->qiov->iov[i].iov_base);
     }
+#endif

     iscsi_set_events(iscsilun);

---
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-21 17:02:59 +01:00
Ronnie Sahlberg
4a973e9a4e SCSI: Pass the expected opcode to scsi_cdb_unmarshall()
Pass the opcode we expect to the unmarshalling function so it can do a basic
check that we are trying to unmarshalling the right kind of cdb.
2012-11-20 19:16:42 -08:00
Ronnie Sahlberg
890471c8cc Add support to unmarshall a CDB into a structure and update iscsi-dd
Add two new helper functions scsi_get_uint32() and scsi_get_uint16()
2012-11-20 19:00:55 -08:00
Ronnie Sahlberg
3b3036b9da Add support for SCSI Sense formats 0x72/0x73 2012-11-19 18:25:12 -08:00
Ronnie Sahlberg
b4746678f9 Merge pull request #38 from aredlich/master
Remove scsi_task->params
2012-11-19 18:19:28 -08:00
Arne Redlich
5194d13e73 scsi-lowlevel: remove scsi_maintenancein_params and finally scsi_task->params too
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 23:28:32 +01:00
Arne Redlich
8baa843d73 scsi-lowlevel: remove scsi_readtoc_params and fix READ TOC format field
Set the format field in the READ TOC CDB (lower nibble of byte 2).

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 23:16:45 +01:00
Peter Lieven
a75727d989 RECONNECT avoid deadlock on reconnect retry timeout
If there is a clock jump e.g. due to daylight saving time
the wait can be almost infinite
2012-11-18 14:03:13 -08:00
Peter Lieven
328755fb68 CONNECT add further debug output regardint login and reconnect 2012-11-18 14:02:29 -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
Peter Lieven
30804507f9 SYNC set status to -1 on error in event_loop
If there is an error in iscsi_service or on poll we
exit the event_loop. But in this case scsi_sync_cb is
never reached and the status is 0. This will make
the caller think that the sync task has been completed
successfully.
2012-11-18 14:00:31 -08:00
Peter Lieven
577d37c5ed RECONNECT exit from sync event_loop in case of an error
If there is an error during reconnect we should not loop in event_loop
as this will cause a deadlock in case there is actually an error like
connection drop etc. If this reconnect fails the reconnect routine
will retry itself.
2012-11-18 13:59:53 -08:00
Arne Redlich
551298adfb scsi-lowlevel: remove scsi_serviceactionin_params and plug potential memleaks
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:57:59 +01:00
Peter Lieven
f9dc2da672 Revert "CONNECT only read/write from sockets when connection is established"
Fixed the login process in qemu-kvm. This makes this fix obsolete.

This reverts commit a9257d52a7.
2012-11-18 13:57:57 -08:00
Peter Lieven
00baa9bd6c CONNECT fixed memleak in case iscsi_connect_async fails directly 2012-11-18 13:57:02 -08:00
Ronnie Sahlberg
bdfa2833e5 tiny style change 2012-11-18 13:55:15 -08:00
Peter Lieven
6f3a575238 INIT check iscsi==NULL in iscsi_get_error()
qemu-kvm calls iscsi_get_error(NULL) if we specify an invalid URL
2012-11-18 13:54:07 -08:00
Peter Lieven
6f7b02989a LOGGING log target_name and not initator_name 2012-11-18 13:52:55 -08:00
Peter Lieven
bd1d5ec70f LOGGING add target name to log output 2012-11-18 13:52:48 -08:00