Commit Graph

521 Commits

Author SHA1 Message Date
Ronnie Sahlberg
6822baee3f reconnect: we need to reset the in/out iovectors on reconnect
This is a bug that has been there a long time.
When we reconnect and requeue a PDU we must reset the iovectors
for the task. Otherwise, any partially sent/received data when the
command is reconnected would end up containing garbage.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-24 06:54:18 -08:00
Ronnie Sahlberg
76f8296dbb reconnect logic and pdu handling
Rework the reconnect logic so we just call iscsi_scsi_command_async()
for the scsi commands we are re-quining instead of poking into the
private fields of the structures themself.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:46:57 -08:00
Ronnie Sahlberg
aedced3b95 login.c: dont modify pdu->flags directly from iscsi_logout_async_internal
We no longer need to modify pdu->flags directly any more from
iscsi_logout_async_internal. We can just pass these as extra flags to
iscsi_allocate_pdu().

We also always set ISCSI_PDU_DROP_ON_RECONNECT unconditionally so there is
no need to pass this flag in from the callers in pdu.c .

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:39:37 -08:00
Ronnie Sahlberg
63c2e7583d task_mgmt.c: drop tmgmt pdus on reconnect
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:31:25 -08:00
Ronnie Sahlberg
0a9bd03b2d login.c: drop login PDUs on reconnect
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:31:25 -08:00
Ronnie Sahlberg
44c5089a21 discovery.c: drop discovery requests on reconnect instead or re-queuing them
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:31:25 -08:00
Ronnie Sahlberg
511c2fdbd1 pdu.c: remove iscsi_allocate_pdu_with_itt_flags()
Remove iscsi_allocate_pdu() which is just a wrapper.
Rename iscsi_allocate_pdu_with_itt_flags() to iscsi_allocate_pdu()
and update all callers.

This only removes a wrapper function and contains no logic changes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:26:22 -08:00
Peter Lieven
de7b38d9a0 use MIN and MAX macros at some places
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-02-23 08:03:27 +01:00
Peter Lieven
dd6831a50f iscsi-command: fix unsolicited data-out length
the recent implementation allows to send
iscsi->first_burst_length + iscsi->target_max_recv_data_segment_length
bytes if immediate and unsolicited data-out is send and
iscsi->target_max_recv_data_segment_length < iscsi->first_burst_length.

RFC3720 defines the length as:

Length=(min(FirstBurstLength, Expected Data
   Transfer Length) - Received Immediate Data Length).

so that immediate data and unsolicited data-out are together
FirstBurstLength at maximum.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-02-23 07:53:41 +01:00
Ronnie Sahlberg
2f5d21b09c iscsi-command.c: Use common function to write unsolicited data-out pdus.
We write unsolicited data-out PDUs from two places;
when we originally write the command in iscsi_scsi_command_async()
but also when we re-queue the PDUs during a session reconnect.

The re-queuing during the session re-connect was recently (almost) fixed
but was still buggy in that it did not correctly clamp the amount of written
data as per first burst length restriction.
This attempts to fix that.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-20 20:51:14 -08:00
Ronnie Sahlberg
831ecb3656 iscsi-command.c: use pdu->expxferlen instead of pdu->expxferlen
Both are the same value at this point but it is better to
do the computation only based on pdy-> fields.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-20 20:39:51 -08:00
Ronnie Sahlberg
b001d980ef reconnect: we must re-queue any missing data-outs during reconnect
If we have writes that do not have the Final bit set during reconnect
we must send out any missing data-out PDU.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-17 06:46:58 -08:00
Ronnie Sahlberg
8ae706630e iscsi-command.c: Better fix for the length bug for immediatedata
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-16 17:36:58 -08:00
Ronnie Sahlberg
db7924fc90 iscsi_command: fix length bug when sending unsolicited data.
If we have send unsolicited immediate data and are ALSO sending
unsilocoted data-out, then we have to exclude the length of data we have already sent.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-16 17:27:56 -08:00
Ronnie Sahlberg
7dc0ea200d socket.c: allow re-using a context after disconnect
From Adam Endrodi <adam.endrodi@nsn.com>
Fix a bug and clear is_corked during socket disconnect so that we
can re-use the context for a new connection.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-09 15:13:58 -08:00
Mike Cui
2284a8763c set_tcp_* functions should be static since they are not used anywhere else.
set_tcp_sockopt in particular conflicts with libnfs's function of the same
name and prevents a a program from statically linking against both libnfs and
libiscsi.

Similar fix should also go into libnfs.
2015-01-05 09:24:01 -08:00
Ronnie Sahlberg
7865a8a26e Merge branch 'sgio' 2014-12-21 15:07:40 -08:00
Ronnie Sahlberg
646c8b963d New version 1.13.0
- Fix UNMAP tests
 - Build updates
 - Check residuals also when status != GOOD
 - Add WSNZ bit to the tests
 - Various test updates
 - Fix bug in scsi_create_task so it sets cdb_len correctly
 - Add a getter function for scsi task status and sense
 - Fixes and workarounds for Dell Equallogic issues
 - Be more flexible when allowing for unit attentions during connect time

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-21 14:58:46 -08:00
Ronnie Sahlberg
8c4a579cda SCSI: scsi_task_get_status add getter function for task status and sense
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-19 08:33:21 -08:00
Ronnie Sahlberg
0c6e3bffb3 SCSI: scsi_create_task must set task->cdb_size
We forgot to set task->cdb_size which means all tasks we create with this
function becomes test unit ready :-(

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-18 09:20:17 -08:00
Ronnie Sahlberg
e07498e5c3 connect.c: improve the error message when iscsi_connect_async fails
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-07 10:08:38 -08:00
Peter Lieven
ac46262afa pdu: add workaround for DELL Equallogic FW bugs 71409 & 73732
Dell Equallogic storages may redirect connections from one member of a multi member storage
group to another. When the member that has the volume lead changes the storage issues
an async disconnect request message. The correct behaviour would be to either fail all I/O requests
with a check condition (waiting for logout) or fullfil requests until the time specified
in the disconnect request message has elapsed and then drop the connection. In firwamre 7.x
however the storage sometimes cancels requests with SENSE KEY:ILLEGAL_REQUEST(5)
ASCQ:LOGICAL_UNIT_NOT_SUPPORTED(0x2500). This leads to I/O errors propagated to the application.
This patch was reported in May 2014 to Dell and the initial bug 71409 has been fixed in 7.0.7.
However, the first fix did not entirely solve the problem and bug 73732 has been raised.

This patch adds an environment variable LIBISCSI_DROP_CONN_ON_ASYNC_EVENT1 which if set leads
to an immediate drop of the connection when such an async event is received. This is ugly, but
works around the I/O errors.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-10-28 09:20:05 +01:00
Ronnie Sahlberg
14461757c4 TESTS: Allow Hardware/Software write protect as valid ASCQ
Add 0x2701/0x2702 to the list of valid ASCQ values we accept for devices
that are write protected.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-10-08 06:23:43 -07:00
Ronnie Sahlberg
f3205bb095 scsi-lowlevel.c: check that task/datain are valid before we unmarshalling
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-27 09:49:52 -07:00
Ronnie Sahlberg
9e514fbf44 scsi-lowlevel.c: check that task/datain are valid before we unmarshalling
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-27 09:48:16 -07:00
Ronnie Sahlberg
5f9444b91a libiscsi.def: we do not need to specify scsi_cdb_compareandwrite twice
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-23 17:27:08 -07:00
Ronnie Sahlberg
ed238f1e69 Merge branch 'master' into sgio 2014-09-23 17:26:02 -07:00
Ronnie Sahlberg
f6d57ef3b0 connect.c: remove UA whitelist and just consume up to 10 UAs before failing
Lets not use a whitelist of UnitAttentions that we consume during the connect
phase. Instead we can just loop and fail after the 10th.
If there are more than 10 UAs then we have a problem, otherwise
just consume them all, forget them  and then pass control back to the caller.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-23 17:23:27 -07:00
Ronnie Sahlberg
398f03205d TESTS: update unmap to new api
Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
2014-09-18 14:07:22 -07:00
Ronnie Sahlberg
46eaa7dcc3 TESTS: convert compareandwrite to new api
Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
2014-09-18 14:07:22 -07:00
Ronnie Sahlberg
900ce145ad libiscsi.def: add missing scsi_cdb_compareandwrite and scs_malloc symbols
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-09-18 12:11:50 -07:00
Bart Van Assche
161547d5b6 lib/socket.c: Fix a use-after-free
This issue was introduced via patch "pdu: introduce ISCSI_PDU_CORK_WHEN_SENT"
on June 13, 2014 (commit 99585b6996).

Valgrind reported this use-after-free as follows:

Invalid read of size 4
   at 0x5267606: iscsi_write_to_socket (socket.c:721)
   by 0x5267A72: iscsi_service (socket.c:823)
   by 0x526827C: event_loop (sync.c:67)
   by 0x52698A4: iscsi_compareandwrite_sync (sync.c:823)
   by 0x408111: compareandwrite (iscsi-support.c:1752)
   by 0x4139E2: test_compareandwrite_simple (test_compareandwrite_simple.c:88)
   by 0x503D260: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D578: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D8B5: CU_run_all_tests (in /usr/lib64/libcunit.so.1.0.1)
   by 0x4046C6: main (iscsi-test-cu.c:1241)
 Address 0x639f258 is 8 bytes inside a block of size 256 free'd
   at 0x4C291E7: free (vg_replace_malloc.c:473)
   by 0x525321B: iscsi_free (init.c:68)
   by 0x52532F0: iscsi_sfree (init.c:110)
   by 0x5257AD9: iscsi_free_pdu (pdu.c:179)
   by 0x5267601: iscsi_write_to_socket (socket.c:719)
   by 0x5267A72: iscsi_service (socket.c:823)
   by 0x526827C: event_loop (sync.c:67)
   by 0x52698A4: iscsi_compareandwrite_sync (sync.c:823)
   by 0x408111: compareandwrite (iscsi-support.c:1752)
   by 0x4139E2: test_compareandwrite_simple (test_compareandwrite_simple.c:88)
   by 0x503D260: ??? (in /usr/lib64/libcunit.so.1.0.1)
   by 0x503D578: ??? (in /usr/lib64/libcunit.so.1.0.1)

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Peter Lieven <pl@kamp.de>
2014-09-18 11:57:05 -07:00
Bart Van Assche
ded75ae18a Fix WRITE SAME data buffer length handling
From the SPC-4 paragraph about WRITE SAME(10): "The WRITE SAME (10)
command requests that the device server transfer a single logical
block from the Data-Out Buffer [ ... ]". Hence always pass a data
buffer when sending a WRITE SAME(10) command.

Set the NDOB bit in the WRITE SAME(16) command if no data out buffer
is present.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2014-08-21 06:42:49 -07:00
Bart Van Assche
d77765548f libiscsi: Also parse residual if SCSI status != GOOD
This change is needed for the test_write*_residuals tests.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2014-08-04 16:03:49 -07:00
Ronnie Sahlberg
f0ebbdc203 Merge pull request #128 from plieven/revert_iovector
socket: rename max_read parameter to count in iscsi_iovector_readv_write...
2014-07-14 06:24:05 -07:00
Peter Lieven
53e38dff7d socket: rename max_read parameter to count in iscsi_iovector_readv_writev
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 15:05:19 +02:00
Ronnie Sahlberg
a0d09ca9de Merge pull request #127 from plieven/revert_iovector
Revert "Rewrite and simplify iscsi_iovector_readv_writev"
2014-07-14 05:56:12 -07:00
Peter Lieven
59e4a07129 Revert "Rewrite and simplify iscsi_iovector_readv_writev"
Since writing headers and payload in a single iov has never been
implementend and after thinking about it several times seems to
be very hairy I would like to revert this change since
the original implementation is in O(1) while the changed one
is in O(n). This results in a complexity of O(n^2) instead of
O(n) for the whole send operation.

This reverts commit 06eab264f6.
2014-07-14 08:05:32 +02:00
Peter Lieven
4b3f4b5822 iscsi_which_events: do not set POLLOUT if context is corked
if the socket is corked we otherwise set POLLOUT and then
do not sent. Depending on the event loop implementation this
can result in a busy wait.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 08:02:24 +02:00
Ronnie Sahlberg
ada1fc2008 Merge pull request #123 from plieven/asyncv3
add support for async messages
2014-07-13 16:46:27 -07:00
Paolo Bonzini
ce0723320c libiscsi: fix dangling pointer for outqueue_current
The outqueue_current PDU might also be in waitpdu if it does not have
ISCSI_PDU_DELETE_WHEN_SENT.  outqueue_current is freed after the
waitpdu list (for reconnect or defer_reconnect), or sometimes not
considered at all (for cancel), and this can cause a dangling pointer.

Keep outqueue_current up to date when a PDU is freed.  A bit hacky,
but it avoids touching code all over the place.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-17 14:59:50 +02:00
Peter Lieven
4e129d385c pdu: fix statsn and factor out sn comparision
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:58:38 +02:00
Peter Lieven
52c6b0d397 pdu: check callback on iscsi_process_reject
if the rejected packet is a NOP-Out it is legal
that it has no callback. In this case we end
up in a segfault.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:57:52 +02:00
Peter Lieven
e6894fd73a iscsi-command: do not fail commands while reconnect is pending
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:56:57 +02:00
Peter Lieven
f14f3ef6fe pdu: handle async events 2,3,4
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:56:43 +02:00
Peter Lieven
21e02c2078 pdu: catch rejected packets while target waits for logout
after a target has send the async target requests logout event it may
reject each request with a waiting for logout reason. Catch these
rejects if an outstanding request and the logout event overlap.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:54:05 +02:00
Peter Lieven
81921e3762 pdu: handle async target requests logout events
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:52:27 +02:00
Peter Lieven
98bbeab664 pdu: introduce ISCSI_PDU_URGENT_DELIVERY
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:50:41 +02:00
Peter Lieven
344b21d37d logout: allow additional PDU flags to be passed internally
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:43:54 +02:00
Peter Lieven
e940f95769 logout: cork socket after logout has been sent
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:21 +02:00