Commit Graph

507 Commits

Author SHA1 Message Date
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
Peter Lieven
99585b6996 pdu: introduce ISCSI_PDU_CORK_WHEN_SENT
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:08 +02:00
Peter Lieven
5d55d32adb socket: do not stop sending for immediate PDUs
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:00 +02:00
Paolo Bonzini
267343dca5 bump ABI version again
1.10 and 1.11 both introduced incompatible changes to the
libiscsi ABI.  Please do not do that, and feel free to Cc
me on any patch that touches include/.  In the meanwhile,
bump the soname of the library.  I suggest releasing 1.11.1
with this change for distros.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-10 13:38:46 +02:00
Michael Tokarev
d7ab603ba0 format string cast ptrdiff on 32bit arch (#747262)
Cast ptrdiff (diff between two pointers) to long to fix printfs.
This fixes FTBFS on 32bit architectures.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-05-07 06:49:02 -07:00
Ronnie Sahlberg
717b95cb8a slist.h: rename SLIST_ to ISCSI_LIST_ to avoid clash on *BSD
Rename the macros for managing the linked lists from SLIST_* to ISCSI_LIST_*
to avoid a clash on *BSD which already have other macros SLIST_*

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-05-07 06:44:19 -07:00
Ronnie Sahlberg
fe669580ee New version 1.11.0
This version contains changes for:
 - Fix memory leaks in persistent reserve out.
 - Fix various leaks in the testsuite.
 - Add additional READ16 tests
 - Better logging when reconnect fails.
 - Discovery and Login fixes.
 - Various fixes found by coverity.
 - WRITESAME test updates.
 - Add XML oputput support for the testsuite.
and various other things.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-04-19 12:06:45 -07:00
Ronnie Sahlberg
24601a36ee MAKEFILE.AM cleanups 2014-03-22 18:21:27 -07:00
Ronnie Sahlberg
65d3597c1b AUTOTOOLS: Create Makefile.am for lib 2014-03-22 13:10:15 -07:00
Ronnie Sahlberg
354f00fd4f Discovery: Create a list of portals for each discovered target.
Some targets return multiple TargetAddress for individual targets.
Create a linked list of addresses for each target instead of
failing the discovery process when this happens.
2014-01-15 19:37:40 -08:00
Michael Tokarev
120b308741 Spelling fixes: Dont => Don't
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2013-12-16 18:19:24 -08:00
Paolo Bonzini
34b93c4cfd fix CHAP authentication
Empty discovery and login packets are legal, and have the same behavior
as packets with a single NUL in them.  Introduced by commit 94d73fc
(Merge pull request #83 from bonzini/coverity, 2013-11-05).

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-12-12 17:06:06 +01:00
Ronnie Sahlberg
78e49f1427 Coding style update 2013-11-05 17:59:55 -08:00
Ronnie Sahlberg
e59c336450 Use <ptr> == NULL instead of !<ptr> 2013-11-05 17:53:10 -08:00
Paolo Bonzini
87ee645621 check for a target being there before processing TargetAddress
Otherwise we access a NULL pointer.  RFC3270 appendix D confirms
that TargetName must always come before TargetAddress.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 15:38:38 +01:00