Commit Graph

670 Commits

Author SHA1 Message Date
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
Ronnie Sahlberg
4f32723b4c Merge pull request #46 from plieven/fix_outqueue
Fix outqueue deadlock
2012-11-28 06:25:24 -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
c09ee1dab8 Fix test 1040 to really trigger cmdsn deadlock
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 11:37:23 +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
efc556e2e9 TESTS: Create a test that tries to overflow the maxcmdsn counter
so that i/o from the initiator stops flowing and are just queued locally
until teh cmdsn window opens up again.

Send a lot of writes that block until we have processed the R2T
back from the target and verify we can still make process when we
have saturated the cmdsn window and are also blocked waiting for R2Ts.
2012-11-27 19:51:22 -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
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
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
Ronnie Sahlberg
032594f099 Merge pull request #41 from plieven/iovec
SCSI add support for iovectors
2012-11-23 11:54:31 -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
e691f9cc2b ISCSI-DD: Remove some compiler warnings 2012-11-20 06:49:19 -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
Bernhard Kohl
219533dc7b Returned buffers from poptGetArgs() are free()ed in poptFreeContext()
Calling "free(url);" causes a core dump in glibc-2.15.

Signed-off-by: Bernhard Kohl <bernhard.kohl@gmx.net>
2012-11-18 14:12:30 -08: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
Arne Redlich
fa158865d2 scsi-lowlevel: remove scsi_modesense6_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:47:14 +01:00
Arne Redlich
5f414317dc scsi-lowlevel: remove scsi_inquiry_params and refactor INQUIRY data-in unmarshalling
Split the INQUIRY data-in unmarshalling into smaller chunks, fixing some
potential memory leaks along the way.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:46:04 +01:00
Arne Redlich
b5a9ba6159 scsi-lowlevel: remove scsi_readcapacity10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:04:57 +01:00
Arne Redlich
188505a72d scsi-lowlevel: remove scsi_verify16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:59:42 +01:00
Arne Redlich
de67d86e64 scsi-lowlevel: remove scsi_verify12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:58:30 +01:00
Arne Redlich
10fd2f560b scsi-lowlevel: remove scsi_verify10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:57:00 +01:00
Arne Redlich
1dbdd04795 scsi-lowlevel: remove scsi_writeverify16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:55:01 +01:00
Arne Redlich
a262d07c4b scsi-lowlevel: remove scsi_writeverify12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:53:44 +01:00
Arne Redlich
fff2527cda scsi-lowlevel: remove scsi_writeverify10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:52:34 +01:00
Arne Redlich
8169c3e280 scsi-lowlevel: remove scsi_compareandwrite_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:51:10 +01:00